1 import ChessRules
from "/base_rules.js";
2 import {ArrayFun
} from "/utils/array.js";
3 import {Random
} from "/utils/alea.js";
5 export default class AlapoRules
extends ChessRules
{
9 select: C
.Options
.select
,
10 styles: C
.Options
.styles
.filter(s
=> s
!= "teleport")
22 let board
= super.getSvgChessboard().slice(0, -6);
23 // Add lines to delimitate goals
25 <line x1="0" y1="10" x2="60" y2="10" stroke="black" stroke-width="0.1"/>
26 <line x1="0" y1="50" x2="60" y2="50" stroke="black" stroke-width="0.1"/>
31 genRandInitFen(seed
) {
32 if (this.options
["randomness"] == 0)
33 return "rbqqbr/tcssct/6/6/TCSSCT/RBQQBR w 0";
43 let pieces
= { w: new Array(6), b: new Array(6) };
44 // Shuffle pieces on first (and last rank if randomness == 2)
45 for (let c
of ["w", "b"]) {
46 if (c
== 'b' && this.options
["randomness"] == 1) {
47 pieces
['b'] = pieces
['w'];
51 let positions
= ArrayFun
.range(6);
53 // Get random squares for bishops
54 let randIndex
= 2 * Random
.randInt(3);
55 const bishop1Pos
= positions
[randIndex
];
56 let randIndex_tmp
= 2 * Random
.randInt(3) + 1;
57 const bishop2Pos
= positions
[randIndex_tmp
];
58 positions
.splice(Math
.max(randIndex
, randIndex_tmp
), 1);
59 positions
.splice(Math
.min(randIndex
, randIndex_tmp
), 1);
61 // Get random square for queens
62 randIndex
= Random
.randInt(4);
63 const queen1Pos
= positions
[randIndex
];
64 positions
.splice(randIndex
, 1);
65 randIndex
= Random
.randInt(3);
66 const queen2Pos
= positions
[randIndex
];
67 positions
.splice(randIndex
, 1);
69 // Rooks positions are now fixed,
70 const rook1Pos
= positions
[0];
71 const rook2Pos
= positions
[1];
73 pieces
[c
][rook1Pos
] = "r";
74 pieces
[c
][bishop1Pos
] = "b";
75 pieces
[c
][queen1Pos
] = "q";
76 pieces
[c
][queen2Pos
] = "q";
77 pieces
[c
][bishop2Pos
] = "b";
78 pieces
[c
][rook2Pos
] = "r";
82 pieces
["b"].join("") + "/" +
83 pieces
["b"].map(p
=> piece2pawn
[p
]).join("") +
85 pieces
["w"].map(p
=> piece2pawn
[p
].toUpperCase()).join("") + "/" +
86 pieces
["w"].join("").toUpperCase() +
91 // Triangles are rotated from opponent viewpoint (=> suffix "_inv")
93 const allSpecs
= super.pieces(color
, x
, y
);
97 'b': Object
.assign({}, allSpecs
['b'],
98 {"class": "bishop" + (this.playerColor
!= color
? "_inv" : "")}),
103 steps: [[0, 1], [0, -1], [1, 0], [-1, 0]],
109 "class": "babyqueen",
113 [0, 1], [0, -1], [1, 0], [-1, 0],
114 [1, 1], [1, -1], [-1, 1], [-1, -1]
121 "class": "babybishop" + (this.playerColor
!= color
? "_inv" : ""),
124 steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]],
144 // Try both colors (to detect potential suicides)
146 for (let c
of ['w', 'b']) {
147 const oppCol
= C
.GetOppCol(c
);
148 const goal
= (c
== 'w' ? 0 : 5);
149 won
[c
] = this.board
[goal
].some((b
,j
) => {
151 this.getColor(goal
, j
) == c
&&
152 !this.findCapturesOn(
157 segments: this.options
["cylinder"]
163 if (won
['w'] && won
['b'])
164 return "?"; //no idea who won, not relevant anyway :)
165 return (won
['w'] ? "1-0" : (won
['b'] ? "0-1" : "*"));