Fix typo
[vchess.git] / client / src / variants / Titan.js
CommitLineData
b0d55a05
BA
1import { ChessRules } from "@/base_rules";
2
3export 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
31c53595
BA
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
b0d55a05
BA
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() {
31c53595
BA
37 return [
38 'a',
39 'c',
40 'j',
41 'l',
42 'm',
43 'o',
44 's',
45 't',
46 'u',
47 'v'
48 ];
b0d55a05 49 }
31c53595
BA
50
51 // Decode above notation into additional piece
b0d55a05 52 getExtraPiece(symbol) {
31c53595
BA
53 if (['a','j','m','s','u'].includes(symbol))
54 return 'n';
55 return 'b';
b0d55a05
BA
56 }
57
31c53595
BA
58 // If piece not in usual list, bishop or knight appears.
59 getPotentialMovesFrom([x, y]) {
b0d55a05
BA
60 let moves = super.getPotentialMovesFrom(sq);
61 const color = this.turn;
31c53595
BA
62
63// treat castle case here (both pieces appear!)
b0d55a05 64 if (
31c53595
BA
65 V.AUGMENTED_PIECES.includes(this.board[x][y][1]) &&
66 ((color == 'w' && x == 7) || (color == "b" && x == 0))
b0d55a05 67 ) {
31c53595 68 const newPiece = this.getExtraPiece(this.board[x][y][1]);
b0d55a05
BA
69 moves.forEach(m => {
70 m.appear.push(
71 new PiPo({
72 p: newPiece,
73 c: color,
31c53595
BA
74 x: x,
75 y: y
b0d55a05
BA
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};