Commit | Line | Data |
---|---|---|
5bfb0956 BA |
1 | class AliceRules extends ChessRUles |
2 | { | |
0cd8f2bd BA |
3 | // TODO: more general double correspondance normal <--> alice |
4 | static get ALICE_PIECES() | |
5bfb0956 | 5 | { |
0cd8f2bd | 6 | return ['s','t','u','c','o','l']; //king is 'l' |
5bfb0956 | 7 | } |
a3eb4cc5 | 8 | |
0cd8f2bd BA |
9 | static getPpath(b) |
10 | { | |
11 | return (this.ALICE_PIECES.includes(b[1]) ? "Alice/" : "") + b; | |
12 | } | |
13 | ||
14 | getPotentialMovesFrom([x,y]) | |
15 | { | |
16 | // Build board1+board2 from complete board | |
17 | let board1 = doubleArray(sizeX, sizeY, ""); | |
18 | let board2 = doubleArray(sizeX, sizeY, ""); | |
19 | const [sizeX,sizeY] = variantRules.size; | |
20 | for (let i=0; i<sizeX; i++) | |
21 | { | |
22 | for (let j=0; j<sizeY; j++) | |
23 | { | |
24 | const piece = this.getPiece(i,j); | |
25 | if (this.ALICE_PIECES.includes(piece)) | |
26 | board2[i][j] = this.board[i][j]; | |
27 | else | |
28 | board1[i][j] = this.board[i][j]; | |
29 | } | |
30 | } | |
31 | let saveBoard = JSON.parse(JSON.stringify(this.board)); | |
32 | ||
33 | // Search valid moves on both boards | |
34 | let moves = []; | |
35 | this.board = board1; | |
36 | ||
37 | ||
38 | this.board = board2; | |
39 | ||
40 | this.board = saveBoard; | |
41 | ||
42 | // Finally filter impossible moves | |
43 | ||
44 | return moves; | |
45 | } | |
46 | ||
47 | underCheck(move) | |
48 | { | |
49 | // 1 where is king ? if board1 then build it, if board2 then build it. then check. | |
50 | const color = this.turn; | |
51 | this.play(move); | |
52 | let res = this.isAttacked(this.kingPos[color], this.getOppCol(color)); | |
53 | this.undo(move); | |
54 | return res; | |
55 | } | |
56 | ||
57 | // TODO also: | |
58 | //getCheckSquares(move) | |
59 | ||
60 | // TODO: pieces change side! | |
61 | static PlayOnBoard(board, move) | |
62 | { | |
63 | for (let psq of move.vanish) | |
64 | board[psq.x][psq.y] = VariantRules.EMPTY; | |
65 | for (let psq of move.appear) | |
66 | board[psq.x][psq.y] = psq.c + psq.p; | |
67 | } | |
68 | static UndoOnBoard(board, move) | |
69 | { | |
70 | for (let psq of move.appear) | |
71 | board[psq.x][psq.y] = VariantRules.EMPTY; | |
72 | for (let psq of move.vanish) | |
73 | board[psq.x][psq.y] = psq.c + psq.p; | |
74 | } | |
75 | ||
76 | checkGameEnd() | |
77 | { | |
78 | const color = this.turn; | |
79 | // No valid move: stalemate or checkmate? | |
80 | // TODO: here also, need to build the board with king on it | |
81 | if (!this.isAttacked(this.kingPos[color], this.getOppCol(color))) | |
82 | return "1/2"; | |
83 | // OK, checkmate | |
84 | return color == "w" ? "0-1" : "1-0"; | |
85 | } | |
5bfb0956 | 86 | } |