//get list of possible moves public override List<Square> getPossibleMoves(Board board, Square s) { var possibleMoves = new List<Square>(); int[,] offsets = { { -1, 1 }, { 1, 1 }, { 1, -1 }, { -1, -1 } }; int tempFile, tempRank; for (int i = 0; i < offsets.GetLength(0); i++) { tempFile = s.file; tempRank = s.rank; for (int j = 0; j < 8; j++) { tempFile += offsets[i, 0]; tempRank += offsets[i, 1]; if (!inBounds(tempFile, tempRank)) break; if (!board.Square[tempFile, tempRank].isEmpty()) { if (board.Square[tempFile, tempRank].Piece.getPlayer() != player) possibleMoves.Add(new Square(tempFile, tempRank)); break; } else possibleMoves.Add(new Square(tempFile, tempRank)); } } return possibleMoves; }
//determine if a move is legal public bool isLegalMove(Board board, int file, int rank, Square s) { var possibleMoves = getPossibleMoves(board, s); foreach (Square i in possibleMoves) if (file == i.file && rank == i.rank) return true; return false; }
public FENSpecifier(SerializationModes mode, Board b) { InitializeComponent(); this.saveDiag.Filter = Main.FILETYPE_FEN; this.openDiag.Filter = Main.FILETYPE_FEN; this.setMode(mode); if (b != null) this.Result = new FENSerializer().Serialize(b); }
//get list of possible moves public override List<Square> getPossibleMoves(Board board, Square s) { var possibleMoves = new List<Square>(); int[,] offsets = { { -1, 1 }, { 1, 1 }, { 0, 1 }, { 0, 2 } }; int tempFile, tempRank; for (int i = 0; i < offsets.GetLength(0); i++) { if (offsets[i, 1] == 2 && moved > 0) continue; tempFile = s.file; tempRank = s.rank; if (player == WHITE){ tempFile += offsets[i, 0]; tempRank += offsets[i, 1]; }else{ tempFile -= offsets[i, 0]; tempRank -= offsets[i, 1]; } if (!inBounds(tempFile, tempRank)) continue; if (tempFile == s.file) { if (board.Square[tempFile, tempRank].isEmpty()) possibleMoves.Add(new Square(tempFile, tempRank)); else break; } else if(tempFile != s.file && !board.Square[tempFile,tempRank].isEmpty()) { if(board.Square[tempFile,tempRank].Piece.getPlayer() != player) possibleMoves.Add(new Square(tempFile, tempRank)); else continue; } } return possibleMoves; }
public Game() { board = new Board(); }
//return a list of all possible moves for a piece public abstract List<Square> getPossibleMoves(Board board, Square s);
//get list of possible moves public override List<Square> getPossibleMoves(Board board, Square s) { var possibleMoves = new List<Square>(); int[,] offsets = { { -1, 1 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, { 1, 0 }, { -1, -1 }, { 0, -1 }, { 1, -1 } }; int tempFile, tempRank; if (moved == 0) { //queenside castle if (!board.Square[0, s.rank].isEmpty()) { if (board.Square[0, s.rank].Piece.moved == 0) { for (int i = 4; i > 0; --i) { if (!board.Square[i, s.rank].isEmpty()) break; if (i == 1) possibleMoves.Add(new Square(2, s.rank)); } } } //kingside castle if (!board.Square[7, s.rank].isEmpty()) { if (board.Square[7, s.rank].Piece.moved == 0) { for (int i = 4; i < 7; ++i) { if (!board.Square[i, s.rank].isEmpty()) break; if (i == 6) possibleMoves.Add(new Square(6, s.rank)); } } } } //normal moves for (int i = 0; i < offsets.GetLength(0); i++) { tempFile = s.file; tempRank = s.rank; tempFile += offsets[i, 0]; tempRank += offsets[i, 1]; if (!inBounds(tempFile, tempRank)) continue; if (!board.Square[tempFile, tempRank].isEmpty()) { if (board.Square[tempFile, tempRank].Piece.getPlayer() != player) possibleMoves.Add(new Square(tempFile, tempRank)); else continue; } else possibleMoves.Add(new Square(tempFile, tempRank)); } return possibleMoves; }