public static List<Tuple<uint, uint>> getPossibleMoves(Board board, Piece piece) { List<Tuple<uint, uint>> moves = new List<Tuple<uint, uint>>(); int px = (int) piece.getX(); int py = (int) piece.getY(); // Loops over jump locations foreach (Tuple<int, int> item in jmpList) { int jmpX = item.Item1 + px; int jmpY = item.Item2 + py; if (board.withinBoard(jmpX, jmpY)) { Piece P = board.getPieceAt((uint) jmpX, (uint) jmpY); if (P != null) { if (!piece.isSameColour(P)) { moves.Add(new Tuple<uint, uint>((uint)jmpX, (uint)jmpY)); } } else { moves.Add(new Tuple<uint, uint>((uint)jmpX, (uint)jmpY)); } } } // Filter for check situations CommonRules.checkFilter(ref moves, board, piece); return moves; }
// Returns a list of all possible moves public static List<Tuple<uint, uint>> getPossibleMoves(Board board, Piece piece) { List<Tuple<uint, uint>> tmpList = new List<Tuple<uint, uint>>(); short yMod; short passantRow; if (piece.getColour() == "white") { yMod = 1; passantRow = 4; } else { yMod = -1; passantRow = 3; } // Take left if (board.withinBoard((int) piece.getX() - 1, (int) piece.getY() + yMod)) { Piece P = board.getPieceAt((uint)(piece.getX() - 1), (uint)(piece.getY() + yMod)); if (P != null) { if (!piece.isSameColour(P)) { tmpList.Add(new Tuple<uint, uint>((uint)(piece.getX() - 1), (uint)(piece.getY() + yMod))); } } } //Take right if (board.withinBoard((int)piece.getX() + 1, (int)piece.getY() + yMod)) { Piece P = board.getPieceAt((uint)(piece.getX() + 1), (uint)(piece.getY() + yMod)); if (P != null) { if (!piece.isSameColour(P)) { tmpList.Add(new Tuple<uint, uint>((uint)(piece.getX() + 1), (uint)(piece.getY() + yMod))); } } } //Move 1 if (board.withinBoard((int)piece.getX(), (int)piece.getY() + yMod)) { Piece P = board.getPieceAt(piece.getX(), (uint)(piece.getY() + yMod)); if (P == null) { tmpList.Add(new Tuple<uint, uint>(piece.getX(), (uint)(piece.getY() + yMod))); } } //Move 2 (Only first move) if (!piece.movedFromInit()) { if (board.withinBoard((int)piece.getX(), (int)piece.getY() + 2 * yMod)) { Piece P = board.getPieceAt(piece.getX(), (uint)(piece.getY() + 2 * yMod)); Piece P2 = board.getPieceAt(piece.getX(), (uint)(piece.getY() + yMod)); if (P == null && P2 == null) { tmpList.Add(new Tuple<uint, uint>(piece.getX(), (uint)(piece.getY() + 2 * yMod))); //((Pawn)piece).setDoubleStepTurn(board.getTurn()); } } } //En Passant if (piece.getY() == passantRow) { if ((piece.getX() + 1) < Board.BOARD_SIZE_X) { Piece P1 = board.getPieceAt(piece.getX() + 1, piece.getY()); if (P1 != null) { if (P1 is Pawn) if (((Pawn)P1).getDoubleStepTurn() == board.getTurn() - 1) tmpList.Add(new Tuple<uint, uint>(piece.getX() + 1, (uint)(piece.getY() + yMod))); } } if ((int)piece.getX() - 1 >= 0) { Piece P2 = board.getPieceAt(piece.getX() - 1, piece.getY()); if (P2 != null) { if (P2 is Pawn) if (((Pawn)P2).getDoubleStepTurn() == board.getTurn() - 1) tmpList.Add(new Tuple<uint, uint>(piece.getX() - 1, (uint)(piece.getY() + yMod))); } } } // Filter for check situations CommonRules.checkFilter(ref tmpList, board, piece); return tmpList; }