1 import ChessRules
from "/base_rules.js";
2 import Move
from "/utils/Move.js";
3 import PiPo
from "/utils/PiPo.js";
4 import {ArrayFun
} from "/utils/array.js";
6 export default class AtarigoRules
extends ChessRules
{
32 const flipped
= (this.playerColor
== 'b');
35 viewBox="0 0 ${10*(this.size.y)} ${10*(this.size.x)}"
36 class="chessboard_SVG">`;
37 for (let i
=0; i
< this.size
.x
; i
++) {
38 for (let j
=0; j
< this.size
.y
; j
++) {
39 const ii
= (flipped
? this.size
.x
- 1 - i : i
);
40 const jj
= (flipped
? this.size
.y
- 1 - j : j
);
43 id="${this.coordsToId({x: ii, y: jj})}"
52 // Add lines to delimitate "squares"
53 for (let i
= 0; i
< this.size
.x
; i
++) {
54 const y
= i
* 10 + 5, maxX
= this.size
.y
* 10 - 5;
56 <line x1="5" y1="${y}" x2="${maxX}" y2="${y}"
57 stroke="black" stroke-width="0.2"/>`;
59 for (let i
= 0; i
< this.size
.x
; i
++) {
60 const x
= i
* 10 + 5, maxY
= this.size
.x
* 10 - 5;
62 <line x1="${x}" y1="5" x2="${x}" y2="${maxY}"
63 stroke="black" stroke-width="0.2"/>`;
71 x: this.options
["bsize"],
72 y: this.options
["bsize"],
76 genRandInitBaseFen() {
77 const fenLine
= C
.FenEmptySquares(this.size
.y
);
79 fen: (fenLine
+ '/').repeat(this.size
.x
- 1) + fenLine
+ " w 0",
94 const [x
, y
] = [coords
.x
, coords
.y
];
95 if (this.board
[x
][y
] != "")
97 const color
= this.turn
;
98 const oppCol
= C
.GetOppCol(color
);
100 appear: [ new PiPo({ x: x
, y: y
, c: color
, p: 's' }) ],
104 this.playOnBoard(move); //put the stone
105 let noSuicide
= false;
107 for (let s
of [[0, 1], [1, 0], [0, -1], [-1, 0]]) {
108 const [i
, j
] = [x
+ s
[0], y
+ s
[1]];
109 if (this.onBoard(i
, j
)) {
110 if (this.board
[i
][j
] == "")
111 noSuicide
= true; //clearly
112 else if (this.getColor(i
, j
) == color
) {
113 // Free space for us = not a suicide
115 let explored
= ArrayFun
.init(this.size
.x
, this.size
.y
, false);
116 noSuicide
= this.searchForEmptySpace([i
, j
], color
, explored
);
120 // Free space for opponent = not a capture
121 let explored
= ArrayFun
.init(this.size
.x
, this.size
.y
, false);
122 const captureSomething
=
123 !this.searchForEmptySpace([i
, j
], oppCol
, explored
);
124 if (captureSomething
) {
125 for (let ii
= 0; ii
< this.size
.x
; ii
++) {
126 for (let jj
= 0; jj
< this.size
.y
; jj
++) {
127 if (explored
[ii
][jj
])
128 captures
.push(new PiPo({ x: ii
, y: jj
, c: oppCol
, p: 's' }));
135 this.undoOnBoard(move); //remove the stone
136 if (!noSuicide
&& captures
.length
== 0)
138 Array
.prototype.push
.apply(move.vanish
, captures
);
142 searchForEmptySpace([x
, y
], color
, explored
) {
144 return false; //didn't find empty space
145 explored
[x
][y
] = true;
147 for (let s
of [[1, 0], [0, 1], [-1, 0], [0, -1]]) {
148 const [i
, j
] = [x
+ s
[0], y
+ s
[1]];
149 if (this.onBoard(i
, j
)) {
150 if (this.board
[i
][j
] == "")
152 else if (this.getColor(i
, j
) == color
)
153 res
= this.searchForEmptySpace([i
, j
], color
, explored
) || res
;
160 // Suicide check not here, because side-computation of captures
164 getCurrentScore(move_s
) {
165 if (move_s
[0].vanish
.length
> 0)
166 return (this.turn
== 'w' ? "0-1" : "1-0");