// Private Methods private void addSimpleMovesUpside(List <Move> i_MovesList, Board i_Board) { if (MoveValidator.IsInBorders(i_Board, this.Location.X + 1, this.Location.Y + 1) && i_Board.GameBoard[this.Location.X + 1, this.Location.Y + 1].CurrentPiece == null) { i_MovesList.Add(new Move(this.Location.Y, this.Location.X, this.Location.Y + 1, this.Location.X + 1)); } if (MoveValidator.IsInBorders(i_Board, this.Location.X + 1, this.Location.Y - 1) && i_Board.GameBoard[this.Location.X + 1, this.Location.Y - 1].CurrentPiece == null) { i_MovesList.Add(new Move(this.Location.Y, this.Location.X, this.Location.Y - 1, this.Location.X + 1)); } // Capture moves if (MoveValidator.IsInBorders(i_Board, this.Location.X + 2, this.Location.Y + 2) && i_Board.GameBoard[this.Location.X + 2, this.Location.Y + 2].CurrentPiece == null) { if (i_Board.GameBoard[this.Location.X + 1, this.Location.Y + 1].CurrentPiece != null && i_Board.GameBoard[this.Location.X + 1, this.Location.Y + 1].CurrentPiece.Side == ePlayerSide.Down) { i_MovesList.Add(new Move(this.Location.Y, this.Location.X, this.Location.Y + 2, this.Location.X + 2)); } } if (MoveValidator.IsInBorders(i_Board, this.Location.X + 2, this.Location.Y - 2) && i_Board.GameBoard[this.Location.X + 2, this.Location.Y - 2].CurrentPiece == null) { if (i_Board.GameBoard[this.Location.X + 1, this.Location.Y - 1].CurrentPiece != null && i_Board.GameBoard[this.Location.X + 1, this.Location.Y - 1].CurrentPiece.Side == ePlayerSide.Down) { i_MovesList.Add(new Move(this.Location.Y, this.Location.X, this.Location.Y - 2, this.Location.X + 2)); } } }
private bool checkKingCapture(Board i_Board, int i_Direction, Move i_Move) { bool captureMove = false; if (MoveValidator.IsInBorders(i_Board, i_Move.ToRow, i_Move.ToCol)) { if (i_Board.GameBoard[i_Move.ToRow, i_Move.ToCol].CurrentPiece == null) { if (i_Board.GameBoard[i_Move.FromRow + 1, i_Move.FromCol + i_Direction].CurrentPiece != null) { if (i_Board.GameBoard[i_Move.FromRow + 1, i_Move.FromCol + i_Direction].CurrentPiece.Side == MoveValidator.GetOtherSide(this.Side)) { captureMove = true; } } } } return(captureMove); }
// Returns true if the given move is a capture move private bool checkCapture(Board i_Board, int i_Direction, Move i_Move) { // check if destinations is in board's borders if (MoveValidator.IsInBorders(i_Board, i_Move.ToRow, i_Move.ToCol)) { Piece pieceToBeCaptured = i_Board.GameBoard[(i_Move.FromRow + i_Move.ToRow) / 2, (i_Move.FromCol + i_Move.ToCol) / 2].CurrentPiece; // check destination is empty if (i_Board.GameBoard[i_Move.ToRow, i_Move.ToCol].CurrentPiece == null) { if (pieceToBeCaptured != null) { if (pieceToBeCaptured.r_Side == MoveValidator.GetOtherSide(this.Side)) { return(true); } } } } return(false); }