+ 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
+ }
+