From a401074d8f035dc1c47d59d8d24dcd629ca51906 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Thu, 12 Sep 2013 04:24:06 +0000
Subject: [PATCH] Add resignation support.

---
 xtrn/chess/board.js | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/xtrn/chess/board.js b/xtrn/chess/board.js
index 24694da7a3..58539d04ef 100644
--- a/xtrn/chess/board.js
+++ b/xtrn/chess/board.js
@@ -62,6 +62,7 @@ function Board(moves)
 	}
 }
 Board.prototype.drawn=false;
+Board.prototype.resigned=false;
 Board.prototype.handleMove=function(move)
 {
 	m=move.match(/^([a-h][1-8])([a-h][1-8])(.*)$/);
@@ -86,15 +87,22 @@ Board.prototype.handleMove=function(move)
 		if(!piece.moveTo(parsePos(m[2])))
 			return false;
 	}
-	if(move.search(/'D$/) != -1) {
-		if(this.draw_offer && this.draw_offer != this.turn())
-			this.drawn=true;
-		else if(m==null)
-			return false;
-		this.draw_offer = this.turn();
+	if(move=='R')
+		this.resigned=true;
+	else {
+		if(move.search(/'D$/) != -1) {
+			if(this.draw_offer && 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);
 	return true;
 }
@@ -128,7 +136,10 @@ Board.prototype.newTurn=function()
 {
 	var t=this.turn();
 	var s,smaterial,i,count,piece,material_array,x,y,c,c2;
-	
+
+	if(this.resigned)
+		return 'RESIGNED';
+
 	if(this.drawn)
 		return 'DRAW';
 
-- 
GitLab