#!/usr/bin/env node "use strict"; var app=require("express")(), http=require("http").Server(app), io=require("socket.io")(http), fs=require("fs"), spawn=require("child_process").spawn, mkdirp=require("mkdirp"), C=require("./common.js"); var HTTPPORT=8090; var uniqid=(function(){ var id=0; return function(){return id++;}; })(); app.get("/",function(req,res){ res.sendFile(__dirname+"/index.html"); }); ["index.html","common.js","dong.ogg","dong.mp3"].forEach(function(fname){ app.get("/"+fname,function(req,res){ res.sendFile(__dirname+"/"+fname); }); }); function Game(_np){ if(!(this instanceof Game))return new Game(_np); this.bd=C.emptyboard(); this.np=_np; this.onturn=0; } Game.prototype.applymove=function(player,pos){ if(this.onturn!=player)return false; var x=pos%C.W,y=~~(pos/C.W); if(x<0||y<0||x>=C.W||y>=C.H){ console.log("applymove asked to apply on pos ("+x+","+y+")"); return false; } if(this.bd[y][x].n&&this.bd[y][x].c!=player)return false; this.bd[y][x].c=player; this.bd[y][x].n++; this.bd=C.stabilise(this.bd); this.onturn=(this.onturn+1)%this.np; if(C.countballs(this.bd)>=this.np){ while(C.countballs(this.bd,this.onturn)==0){ this.onturn=(this.onturn+1)%this.np; } } return true; }; Game.prototype.checkwin=function(){ if(C.countballs(this.bd): {ids:[id's], game:Game}} function findid(id){ var lo=0,mid,hi=connlist.length-1; if(connlist[lo].id==id)return lo; if(connlist[hi].id==id)return hi; while(lo