Add Koth (experimental)
[vchess.git] / client / src / variants / Koth.js
1 import { ChessRules } from "@/base_rules";
2
3 export class KothRules extends ChessRules {
4 filterValid(moves) {
5 if (moves.length == 0) return [];
6 const color = this.turn;
7 const oppCol = V.GetOppCol(color);
8 return moves.filter(m => {
9 this.play(m);
10 // Giving check is forbidden as well:
11 const res = !this.underCheck(color) && !this.underCheck(oppCol);
12 this.undo(m);
13 return res;
14 });
15 }
16
17 getCurrentScore() {
18 // Turn has changed:
19 const color = V.GetOppCol(this.turn);
20 if (
21 [3,4].includes(this.kingPos[color][0]) &&
22 [3,4].includes(this.kingPos[color][1])
23 ) {
24 // The middle is reached!
25 return color == "w" ? "1-0" : "0-1";
26 }
27 if (this.atLeastOneMove()) return "*";
28 // Stalemate (will probably never happen)
29 return "1/2";
30 }
31
32 evalPosition() {
33 // Count material:
34 let evaluation = super.evalPosition();
35 // Ponder with king position:
36 return (
37 evaluation/5 +
38 (
39 Math.abs(this.kingPos["w"][0] - 3.5) +
40 Math.abs(this.kingPos["w"][1] - 3.5)
41 ) / 2 -
42 (
43 Math.abs(this.kingPos["b"][0] - 3.5) +
44 Math.abs(this.kingPos["b"][1] - 3.5)
45 ) / 2
46 );
47 }
48 };