CLeaner way to fix PGN
[vchess.git] / public / javascripts / variants / Antiking.js
CommitLineData
7d6b0773
BA
1class AntikingRules
2{
3 // Path to pieces
4 static getPpath(b)
5 {
6 return b[1]=='a' ? "Antiking/"+b : b;
7 }
8
9 static get ANTIKING() { return 'a'; }
46302e64
BA
10
11 initVariables(fen)
12 {
13 super.initVariables(fen);
14 // TODO: initialize this.antikingPos[...]
15 }
7d6b0773 16
818ede16 17 canTake(color1, color2, [x,y])
7d6b0773 18 {
818ede16
BA
19 const piece = this.getPiece(x,y);
20 return (piece != "a" && color1 != color2) || (piece == "a" && color1 == color2);
7d6b0773
BA
21 }
22
23 getPotentialMovesFrom([x,y])
24 {
25 let c = this.getColor(x,y);
26 switch (this.getPiece(x,y))
27 {
28 case VariantRules.ANTIKING:
29 return this.getPotentialAntikingMoves(x,y,c);
30 default:
31 return super.getPotentielMovesFrom([x,y]);
32 }
33 }
34
46302e64 35 getPotentialAntikingMoves([x,y])
7d6b0773
BA
36 {
37 // TODO
38 }
39
46302e64 40 isAttacked(sq, colors)
7d6b0773 41 {
46302e64 42 return (super.isAttacked(sq, colors) || this.isAttackedByAntiking(sq, colors));
7d6b0773
BA
43 }
44
45 isAttackedByAntiking(sq, color)
46 {
47 // TODO
48 }
49
46302e64 50 underCheck(move)
7d6b0773 51 {
46302e64 52 const c = this.turn;
7d6b0773
BA
53 this.play(move);
54 let res = this.isAttacked(this.kingPos[c], this.getOppCol(c));
55 // TODO: also check that antiking is still in check
56 this.undo(move);
57 return res;
58 }
59
46302e64 60 getCheckSquares(move)
7d6b0773
BA
61 {
62 this.play(move);
46302e64 63 const c = this.turn;
7d6b0773
BA
64 // TODO
65 let res = this.isAttacked(this.kingPos[c], this.getOppCol(c))
46302e64 66 ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ]
7d6b0773
BA
67 : [ ];
68 this.undo(move);
69 return res;
70 }
71
7d6b0773
BA
72 // TODO: need antikingPos as well
73 updateVariables(move)
74 {
75 // ...
76 }
77
78 unupdateVariables(move)
79 {
80 // TODO
81 }
82
83 checkGameEnd(color)
84 {
85 // TODO
86 if (!this.isAttacked(this.kingPos[color], this.getOppCol(color)))
87 return "1/2";
88 return color == "w" ? "0-1" : "1-0";
89 }
90
46302e64 91 // Pieces values (TODO: use Object.assign() + ChessRules.VALUES ?)
7d6b0773
BA
92 static get VALUES() {
93 return {
94 'p': 1,
95 'r': 5,
96 'n': 3,
97 'b': 3,
98 'q': 9,
99 'k': 1000,
100 'a': 1000
101 };
102 }
103
104 static GenRandInitFen()
105 {
46302e64
BA
106 let randFen = ChessRules.GenRandInitFen();
107 // TODO: just add an antiking at random on 3rd ranks
108 return randFen;
7d6b0773
BA
109 }
110}