diff --git a/xtrn/chess/board.js b/xtrn/chess/board.js index 0dc463ba7d117d99a8cb97e5d039f257ddb6c2ca..7394a01424267472bb28378198ad22ad68b82e2f 100644 --- a/xtrn/chess/board.js +++ b/xtrn/chess/board.js @@ -54,19 +54,23 @@ function Board(moves) this.moves=[]; if(moves) { for(move in moves) { - // TODO: Promotions - m=moves[move].match(/^([a-h][1-8])([a-h][1-8])(.*)$/); - if(m==null) - throw("Corrupt game (invalid move)!"); - if(m!=null) { - piece=this.getPiece(parsePos(m[1])); - if(!piece.moveTo(m[2])) - throw("Corrupt game (illegal move)!"); - } - this.moves.push(moves[move]); + this.handleMove(moves[move]); } } } +Board.prototype.handleMove +{ + // TODO: Promotions + m=moves[move].match(/^([a-h][1-8])([a-h][1-8])(.*)$/); + if(m==null) + throw("Corrupt game (invalid move)!"); + if(m!=null) { + piece=this.getPiece(parsePos(m[1])); + if(!piece.moveTo(m[2])) + throw("Corrupt game (illegal move)!"); + } + this.moves.push(moves[move]); +} Board.prototype.movenum={value: 0}; Board.prototype.pieces=null; Board.prototype._domove=function(from, to)