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

Add a check checking method

parent 0bc5a337
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,9 @@ function Board()
new Rook('b', 'h8', this),
],
];
this.king = {}
this.king[COLOUR.white] = this.pieces[0][4];
this.king[COLOUR.black] = this.pieces[7][4];
}
Board.prototype.movenum={value: 0};
Board.prototype.pieces=null;
......@@ -64,3 +67,19 @@ Board.prototype.getPiece=function(pos)
{
return this.pieces[pos.y-1][pos.x-1];
}
Board.prototype.check=function(colour)
{
var x,y,piece,kp;
kp=this.king[colour].position;
for(y=0;y<this.pieces.length;y++) {
for(x=0;x<this.pieces[y].length;x++) {
piece=this.getPiece({x:x, y:y});
if(piece != null) {
if(piece.moveTo(kp, false))
return true;
}
}
}
return false;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment