1 import { ChessRules
} from "@/base_rules";
3 export class FootballRules
extends ChessRules
{
4 static get HasFlags() {
8 static get PawnSpecs() {
12 { promotions: ChessRules
.PawnSpecs
.promotions
.concat([V
.KING
]) }
31 static IsGoodPosition(position
) {
32 if (position
.length
== 0) return false;
33 const rows
= position
.split("/");
34 if (rows
.length
!= V
.size
.x
) return false;
35 // Just check that at least one piece of each color is there:
36 let pieces
= { "w": 0, "b": 0 };
37 for (let row
of rows
) {
39 for (let i
= 0; i
< row
.length
; i
++) {
40 const lowerRi
= row
[i
].toLowerCase();
41 if (V
.PIECES
.includes(lowerRi
)) {
42 pieces
[row
[i
] == lowerRi
? "b" : "w"]++;
45 const num
= parseInt(row
[i
]);
46 if (isNaN(num
)) return false;
50 if (sumElts
!= V
.size
.y
) return false;
52 if (Object
.values(pieces
).some(v
=> v
== 0)) return false;
66 // No variables update because no royal king + no castling
73 const oppCol
= V
.GetOppCol(this.turn
);
74 const goal
= (oppCol
== 'w' ? 0 : 7);
75 if (this.board
[goal
].slice(3, 5).some(b
=> b
[0] == oppCol
))
76 return oppCol
== 'w' ? "1-0" : "0-1";
77 if (this.atLeastOneMove()) return "*";
81 static GenRandInitFen(randomness
) {
83 return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 -";
85 let pieces
= { w: new Array(8), b: new Array(8) };
86 for (let c
of ["w", "b"]) {
87 if (c
== 'b' && randomness
== 1) {
88 pieces
['b'] = pieces
['w'];
92 // Get random squares for every piece, totally freely
93 let positions
= shuffle(ArrayFun
.range(8));
94 const composition
= ['b', 'b', 'r', 'r', 'n', 'n', 'k', 'q'];
95 const rem2
= positions
[0] % 2;
96 if (rem2
== positions
[1] % 2) {
97 // Fix bishops (on different colors)
98 for (let i
=2; i
<8; i
++) {
99 if (positions
[i
] % 2 != rem2
)
100 [positions
[1], positions
[i
]] = [positions
[i
], positions
[1]];
103 for (let i
= 0; i
< 8; i
++) pieces
[c
][positions
[i
]] = composition
[i
];
106 pieces
["b"].join("") +
107 "/pppppppp/8/8/8/8/PPPPPPPP/" +
108 pieces
["w"].join("").toUpperCase() +
109 // En-passant allowed, but no flags