Commit | Line | Data |
---|---|---|
39867b70 BA |
1 | import { Refusal1Rules } from "@/variants/Refusal1"; |
2 | ||
3 | export class Refusal2Rules extends Refusal1Rules { | |
4 | ||
5 | // NOTE: do not take refusal move into account here (two own moves) | |
6 | atLeastTwoMoves() { | |
7 | let movesCounter = 0; | |
8 | const color = this.turn; | |
9 | for (let i = 0; i < V.size.x; i++) { | |
10 | for (let j = 0; j < V.size.y; j++) { | |
11 | if (this.board[i][j] != V.EMPTY && this.getColor(i, j) == color) { | |
12 | const moves = this.getPotentialMovesFrom([i, j]); | |
13 | for (let m of moves) { | |
14 | if (m.vanish[0].c == color && this.filterValid([m]).length > 0) { | |
15 | movesCounter++; | |
16 | if (movesCounter >= 2) return true; | |
17 | } | |
18 | } | |
19 | } | |
20 | } | |
21 | } | |
22 | return false; | |
23 | } | |
24 | ||
25 | prePlay(move) { | |
26 | const L = this.lastMove.length; | |
27 | const lm = this.lastMove[L-1]; | |
28 | if ( | |
29 | // My previous move was already refused? | |
30 | (!!lm && this.getColor(lm.end.x, lm.end.y) == this.turn) || | |
31 | // I've only one move available? | |
32 | !this.atLeastTwoMoves() | |
33 | ) { | |
34 | move.noRef = true; | |
35 | } | |
36 | // NOTE: refusal could be recomputed, but, it's easier like this | |
37 | if (move.vanish[0].c != this.turn) move.refusal = true; | |
38 | } | |
39 | ||
40 | }; |