X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDynamo.js;h=7a794ea21b254e95589c0eb6fb3c254b8d141fb2;hb=b866a62ab3d1d427688954383ed7035111b0e132;hp=4d443eb5d87432cf0e967b60181e5f5a937a2558;hpb=e75718fc502801bb4d97eb9efddb1ae34727f3ed;p=vchess.git diff --git a/client/src/variants/Dynamo.js b/client/src/variants/Dynamo.js index 4d443eb5..7a794ea2 100644 --- a/client/src/variants/Dynamo.js +++ b/client/src/variants/Dynamo.js @@ -1,4 +1,10 @@ -import { ChessRules } from "@/base_rules"; +import { ChessRules, Move, PiPo } from "@/base_rules"; + +// TODO: need FEN lastmove pour interdire défaire dernière poussée +// --> check appear et vanish totally reversed. + +// TODO: pawn promotions by push (en + des promotions standard) +// --> similar to Zen promotions. export class DynamoRules extends ChessRules { canIplay(side, [x, y]) { @@ -6,29 +12,6 @@ export class DynamoRules extends ChessRules { return true; } - // NOTE: to push a piece out of the board, make it slide until our piece - // (doing the action, moving or not) - getPotentialMovesFrom([x, y]) { - const color = this.turn; - let moves = []; - if (this.getColor(x, y) != color) { - // Push or pull something: freely only if subTurn == 1 - if (this.subTurn == 2) { - // I know that someone is pushing/pulling: find out who, - // and deduce my possible squares (or exit). - // TODO - } else { - // Look in every direction for a friendly pusher/puller. - // This means that the action is done without moving. - // TODO - } - } else { - // My piece: fill first with normal moves (if any), - // and add pushes/pulls (if any). - // TODO - } - } - getPPpath(m) { let imgName = ""; if (m.vanish.length == 1) imgName = "empty"; @@ -40,8 +23,8 @@ export class DynamoRules extends ChessRules { else { const deltaX = Math.abs(m.appear[1].x - m.vanish[1].x); const deltaY = Math.abs(m.appear[1].y - m.vanish[1].y); - if (deltaX == 0) imgName = "shift" + deltaY; - else if (deltaY == 0) imgName = "shift" + deltaX; + if (deltaX == 0) imgName = "shift_" + deltaY; + else if (deltaY == 0) imgName = "shift_" + deltaX; else // Special knight push/pull: just print "P" imgName = "pstep"; @@ -50,6 +33,86 @@ export class DynamoRules extends ChessRules { return "Dynamo/" + imgName; } + getPactions(sq, by, color) { + const [x, y] = sq; + let moves = []; + let squares = {}; +// const lineAdd = (allowedPieces) = { +// // attacking piece must be of the allowed types +// }; + if (!by) { + // Look in all directions for a "color" piece + for (let step of V.steps[V.KNIGHT]) { + const xx = x + step[0], + yy = y + step[1]; + if ( + V.OnBoard(xx, yy) && + this.getPiece(xx, yy) == V.KNIGHT && + this.getColor(xx, yy) == color + ) { + const px = x - step[0], + py = y - step[1]; + if (V.OnBoard(px, py) && this.board[px][py] == V.EMPTY) { + const hash = "s" + px + py; + if (!squares[hash]) { + squares[hash] = true; + moves.push(this.getBasicMove([x, y], [px, py])); + } + } else { + const hash = "s" + xx + yy; + if (!squares[hash]) { + squares[hash] = true; + moves.push( + new Move({ + start: { x: x, y: y }, + end: { x: xx, y: yy }, + appear: [], + vanish: [ + new PiPo({ + x: x, + y: y, + p: this.getPiece(x, y), + c: oppCol + }) + ] + }) + ); + } + } + } + } + for (let step in V.steps[V.ROOK]) { + // color is enemy, so no pawn pushes: king, rook and queen + } + for (let step in V.steps[V.BISHOP]) { + // King, bishop, queen, and possibly pawns attacks + } + } +// else { +// // TODO: probably in a different function for now. +// } + return moves; + } + + // NOTE: to push a piece out of the board, make it slide until our piece + // (doing the action, moving or not) + getPotentialMovesFrom([x, y]) { + const color = this.turn; + const oppCol = V.GetOppCol(color); + if (this.getColor(x, y) != color) { + // Look in every direction for a friendly pusher/puller. + // This means that the action is done without moving. + return this.getPactions([x, y], null, color); + } else { + // Playing my pieces: do they attack an enemy? + // If yes ... TODO + //this.getPattacks(sq, [x, y]); + // Temporary: + return super.getPotentialMovesFrom([x, y]); + } + return []; //never reached + } + isAttackedBySlideNJump([x, y], color, piece, steps, oneStep) { for (let step of steps) { let rx = x + step[0],