Add Discoduel, draft Dobutsu, some code cleaning
[xogo.git] / variants / Dobutsu / class.js
1 import ChessRules from "/base_rules.js";
2
3 export default class DobutsuRules extends ChessRules {
4
5 static get Options() {
6 return {};
7 }
8
9 get hasFlags() {
10 return false;
11 }
12
13 get hasEnpassant() {
14 return false;
15 }
16
17 pieces(color, x, y) {
18 const pawnShift = this.getPawnShift(color || 'w');
19 // NOTE: classs change according to playerColor (orientation)
20 const mySide = (this.playerColor == color);
21 return {
22 'c': {
23 "class": (mySide ? "" : "rev-") + "chick",
24 both: [{steps: [[pawnShift, 0]], range: 1}]
25 },
26 'h': {
27 "class": (mySide ? "" : "rev-") + "hen",
28 both: [
29 {
30 steps: [
31 [pawnShift, 1], [pawnShift, -1],
32 [0, 1], [0, -1], [1, 0], [-1, 0]
33 ],
34 range: 1
35 }
36 ]
37 },
38 'e': {
39 "class": (mySide ? "" : "rev-") + "elephant",
40 both: [{steps: [[-1, 1], [-1, -1], [1, 1], [1, -1]], range: 1}]
41 },
42 'g': {
43 "class": (mySide ? "" : "rev-") + "giraffe",
44 both: [{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], range: 1}]
45 },
46 'l': {
47 "class": (mySide ? "" : "rev-") + "lion",
48 both: [{
49 steps: [[-1, 1], [-1, -1], [1, 1], [1, -1],
50 [0, 1], [0, -1], [1, 0], [-1, 0]],
51 range: 1
52 }]
53 }
54 };
55 }
56
57 isKing(x, y, p) {
58 if (!p)
59 p = this.getPiece(x, y);
60 return (p == 'l');
61 }
62
63 static get ReserveArray() {
64 return ['p', 'h', 'e', 'g'];
65 }
66
67 constructor(o) {
68 o.options = {crazyhouse: true, taking: true};
69 super(o);
70 }
71
72 get pawnPromotions() {
73 return ['h'];
74 }
75
76 genRandInitBaseFen() {
77 return {
78 fen: "gle/1c1/1C1/ELG",
79 o: {}
80 };
81 }
82
83 get size() {
84 return {x: 4, y: 4};
85 }
86
87 getCurrentScore(move_s) {
88 const res = super.getCurrentScore(move_s);
89 if (res != '*')
90 return res;
91 const oppCol = C.GetOppTurn(this.turn);
92 const oppLastRank = (oppCol == 'b' ? 3 : 0);
93 for (let j=0; j < this.size.y; j++) {
94 if (this.board[oppLastRank][j] == oppCol + 'l')
95 return (oppCol == 'w' ? "1-0" : "0-1");
96 }
97 return "*";
98 }
99
100 };