Fix typo
[vchess.git] / client / src / variants / Titan.js
1 import { ChessRules } from "@/base_rules";
2
3 export class TitanRules extends ChessRules {
4 // Idea: yellow = bishop, orange = knight (for white)
5 // and, red = bishop + purple = knight (black side)
6 // (avoid using a bigger board, or complicated drawings)
7
8 // Decode if normal piece, or + bishop or knight
9 getPiece(i, j) {
10 const piece = this.board[i][j].charAt(1);
11 if (ChessRules.PIECES.includes(piece)) return piece;
12 // Augmented piece:
13 switch (piece) {
14 case 'a':
15 case 'c':
16 return 'b';
17 case 'j':
18 case 'l':
19 return 'k';
20 case 'm':
21 case 'o':
22 return 'n';
23 case 's':
24 case 't':
25 return 'q';
26 case 'u':
27 case 'v':
28 return 'r';
29 }
30 }
31
32 // TODO: subtelty, castle forbidden if
33
34 // Code: a/c = bishop + knight/bishop j/l for king,
35 // m/o for knight, s/t for queen, u/v for rook
36 static get AUGMENTED_PIECES() {
37 return [
38 'a',
39 'c',
40 'j',
41 'l',
42 'm',
43 'o',
44 's',
45 't',
46 'u',
47 'v'
48 ];
49 }
50
51 // Decode above notation into additional piece
52 getExtraPiece(symbol) {
53 if (['a','j','m','s','u'].includes(symbol))
54 return 'n';
55 return 'b';
56 }
57
58 // If piece not in usual list, bishop or knight appears.
59 getPotentialMovesFrom([x, y]) {
60 let moves = super.getPotentialMovesFrom(sq);
61 const color = this.turn;
62
63 // treat castle case here (both pieces appear!)
64 if (
65 V.AUGMENTED_PIECES.includes(this.board[x][y][1]) &&
66 ((color == 'w' && x == 7) || (color == "b" && x == 0))
67 ) {
68 const newPiece = this.getExtraPiece(this.board[x][y][1]);
69 moves.forEach(m => {
70 m.appear.push(
71 new PiPo({
72 p: newPiece,
73 c: color,
74 x: x,
75 y: y
76 })
77 );
78 });
79 }
80 return moves;
81 }
82
83 // TODO: special case of move 1 = choose squares, knight first, then bishop
84 // (just click ?)
85 };