Skip to content
Snippets Groups Projects
Commit a401074d authored by deuce's avatar deuce
Browse files

Add resignation support.

parent 2d13ffde
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,7 @@ function Board(moves) ...@@ -62,6 +62,7 @@ function Board(moves)
} }
} }
Board.prototype.drawn=false; Board.prototype.drawn=false;
Board.prototype.resigned=false;
Board.prototype.handleMove=function(move) Board.prototype.handleMove=function(move)
{ {
m=move.match(/^([a-h][1-8])([a-h][1-8])(.*)$/); m=move.match(/^([a-h][1-8])([a-h][1-8])(.*)$/);
...@@ -86,15 +87,22 @@ Board.prototype.handleMove=function(move) ...@@ -86,15 +87,22 @@ Board.prototype.handleMove=function(move)
if(!piece.moveTo(parsePos(m[2]))) if(!piece.moveTo(parsePos(m[2])))
return false; return false;
} }
if(move.search(/'D$/) != -1) { if(move=='R')
if(this.draw_offer && this.draw_offer != this.turn()) this.resigned=true;
this.drawn=true; else {
else if(m==null) if(move.search(/'D$/) != -1) {
return false; if(this.draw_offer && this.draw_offer != this.turn())
this.draw_offer = this.turn(); this.drawn=true;
else if(m==null)
return false;
this.draw_offer = this.turn();
}
else {
if(m==null)
return false;
delete this.draw_offer;
}
} }
else
delete this.draw_offer;
this.moves.push(move); this.moves.push(move);
return true; return true;
} }
...@@ -128,7 +136,10 @@ Board.prototype.newTurn=function() ...@@ -128,7 +136,10 @@ Board.prototype.newTurn=function()
{ {
var t=this.turn(); var t=this.turn();
var s,smaterial,i,count,piece,material_array,x,y,c,c2; var s,smaterial,i,count,piece,material_array,x,y,c,c2;
if(this.resigned)
return 'RESIGNED';
if(this.drawn) if(this.drawn)
return 'DRAW'; return 'DRAW';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment