| 1 | import ChessRules from "/base_rules.js"; |
| 2 | |
| 3 | export default class CopycatRules extends ChessRules { |
| 4 | |
| 5 | static get Options() { |
| 6 | return { |
| 7 | select: C.Options.select, |
| 8 | input: C.Options.input, |
| 9 | styles: C.Options.styles.filter(s => !["madrasi", "zen"].includes(s)) |
| 10 | }; |
| 11 | } |
| 12 | |
| 13 | getStepSpec(color, x, y) { |
| 14 | let res = super.getStepSpec(color, x, y); |
| 15 | const piece = this.getPiece(x,y); |
| 16 | if (['p', 'k'].includes(piece)) |
| 17 | return res; |
| 18 | // Now check if the piece at x, y attack some friendly one (enhancement) |
| 19 | let movements = {}; |
| 20 | const steps = this.pieces()[piece].both[0].steps; |
| 21 | steps.forEach(s => { |
| 22 | let [i, j] = [x + s[0], y + s[1]]; |
| 23 | while ( |
| 24 | this.onBoard(i, j) && |
| 25 | this.board[i][j] == "" && |
| 26 | piece != 'n' |
| 27 | ) { |
| 28 | i += s[0]; |
| 29 | j += s[1]; |
| 30 | } |
| 31 | if (this.onBoard(i, j) && this.getColor(i, j) == color) { |
| 32 | const attacked = this.getPiece(i, j); |
| 33 | if (['r', 'b', 'n'].includes(attacked)) { |
| 34 | if (!movements[attacked]) |
| 35 | movements[attacked] = true; |
| 36 | } |
| 37 | else if (attacked == 'q') { |
| 38 | if (!movements['r']) |
| 39 | movements['r'] = true; |
| 40 | if (!movements['b']) |
| 41 | movements['b'] = true; |
| 42 | } |
| 43 | } |
| 44 | }); |
| 45 | Object.keys(movements).forEach(type => { |
| 46 | if ((piece != 'q' && type != piece) || (piece == 'q' && type == 'n')) |
| 47 | res.both.push(this.pieces()[type].both[0]); |
| 48 | }); |
| 49 | return res; |
| 50 | } |
| 51 | |
| 52 | }; |