Commit | Line | Data |
---|---|---|
f55a0a67 | 1 | import ChessRules from "/base_rules.js"; |
f3e90e30 BA |
2 | import {ArrayFun} from "/utils/array.js"; |
3 | import {Random} from "/utils/alea.js"; | |
7c038235 | 4 | import {FenUtil} from "/utils/setupPieces.js"; |
f55a0a67 BA |
5 | |
6 | export default class AlapoRules extends ChessRules { | |
7 | ||
6b9320bb BA |
8 | static get Options() { |
9 | return { | |
10 | select: C.Options.select, | |
11 | styles: C.Options.styles.filter(s => s != "teleport") | |
12 | }; | |
13 | } | |
14 | ||
f55a0a67 BA |
15 | get hasFlags() { |
16 | return false; | |
17 | } | |
18 | get hasEnpassant() { | |
19 | return false; | |
20 | } | |
21 | ||
22 | getSvgChessboard() { | |
23 | let board = super.getSvgChessboard().slice(0, -6); | |
24 | // Add lines to delimitate goals | |
25 | board += ` | |
26 | <line x1="0" y1="10" x2="60" y2="10" stroke="black" stroke-width="0.1"/> | |
27 | <line x1="0" y1="50" x2="60" y2="50" stroke="black" stroke-width="0.1"/> | |
28 | </svg>`; | |
29 | return board; | |
30 | } | |
31 | ||
f31de5e4 | 32 | genRandInitBaseFen() { |
10c9010b BA |
33 | const s = FenUtil.setupPieces( |
34 | ['r', 'b', 'q', 'q', 'b', 'r'], | |
35 | { | |
36 | randomness: this.options["randomness"], | |
37 | diffCol: ['b'] | |
38 | } | |
39 | ); | |
7c038235 BA |
40 | const piece2pawn = { |
41 | r: 't', | |
42 | q: 's', | |
43 | b: 'c' | |
44 | }; | |
45 | const fen = ( | |
46 | s.b.join("") + "/" + | |
47 | s.b.map(p => piece2pawn[p]).join("") + | |
48 | "/6/6/" + | |
49 | s.w.map(p => piece2pawn[p].toUpperCase()).join("") + "/" + | |
50 | s.w.join("").toUpperCase() | |
51 | ); | |
f31de5e4 | 52 | return { fen: fen, o: {} }; |
f55a0a67 BA |
53 | } |
54 | ||
65cf1690 | 55 | // Triangles are rotated from opponent viewpoint (=> suffix "_inv") |
f55a0a67 | 56 | pieces(color, x, y) { |
65cf1690 | 57 | const allSpecs = super.pieces(color, x, y); |
f55a0a67 | 58 | return { |
65cf1690 BA |
59 | 'r': allSpecs['r'], |
60 | 'q': allSpecs['q'], | |
61 | 'b': Object.assign({}, allSpecs['b'], | |
62 | {"class": "bishop" + (this.playerColor != color ? "_inv" : "")}), | |
f55a0a67 BA |
63 | 's': { //"square" |
64 | "class": "babyrook", | |
33b42748 | 65 | both: [ |
f55a0a67 BA |
66 | { |
67 | steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], | |
68 | range: 1 | |
69 | } | |
70 | ] | |
71 | }, | |
72 | 'c': { //"circle" | |
73 | "class": "babyqueen", | |
33b42748 | 74 | both: [ |
f55a0a67 BA |
75 | { |
76 | steps: [ | |
77 | [0, 1], [0, -1], [1, 0], [-1, 0], | |
78 | [1, 1], [1, -1], [-1, 1], [-1, -1] | |
79 | ], | |
80 | range: 1 | |
81 | } | |
82 | ] | |
83 | }, | |
84 | 't': { //"triangle" | |
85 | "class": "babybishop" + (this.playerColor != color ? "_inv" : ""), | |
33b42748 | 86 | both: [ |
f55a0a67 BA |
87 | { |
88 | steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]], | |
89 | range: 1 | |
90 | } | |
91 | ] | |
92 | } | |
93 | }; | |
94 | } | |
95 | ||
96 | get size() { | |
97 | return { | |
98 | x: 6, | |
99 | y: 6 | |
100 | }; | |
101 | } | |
102 | ||
103 | filterValid(moves) { | |
104 | return moves; | |
105 | } | |
106 | ||
107 | getCurrentScore() { | |
108 | // Try both colors (to detect potential suicides) | |
109 | let won = {}; | |
110 | for (let c of ['w', 'b']) { | |
616a8d7a | 111 | const oppCol = C.GetOppTurn(c); |
f55a0a67 BA |
112 | const goal = (c == 'w' ? 0 : 5); |
113 | won[c] = this.board[goal].some((b,j) => { | |
114 | return ( | |
115 | this.getColor(goal, j) == c && | |
6b9320bb BA |
116 | !this.findCapturesOn( |
117 | [goal, j], | |
118 | { | |
119 | one: true, | |
120 | oppCol: oppCol, | |
121 | segments: this.options["cylinder"] | |
122 | } | |
123 | ) | |
f55a0a67 BA |
124 | ); |
125 | }); | |
126 | } | |
127 | if (won['w'] && won['b']) | |
128 | return "?"; //no idea who won, not relevant anyway :) | |
129 | return (won['w'] ? "1-0" : (won['b'] ? "0-1" : "*")); | |
130 | } | |
131 | ||
132 | }; |