public static bool IsCaptureMovePossiblePerSide(ePlayerSide i_Side, Board i_Board, int i_Direction, Piece i_Piece) { bool isCaptureMovePossible = false; ePlayerSide opponentSide = GetOtherSide(i_Side); if (IsInBorders(i_Board, i_Piece.Location.X + i_Direction, i_Piece.Location.Y - i_Direction) && i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y - i_Direction].CurrentPiece != null) { if (i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y - i_Direction].CurrentPiece.Side == opponentSide) { if (IsInBorders(i_Board, i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y - (2 * i_Direction))) { if (i_Board.GameBoard[i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y - (2 * i_Direction)].CurrentPiece == null) { isCaptureMovePossible = true; } } } } if (IsInBorders(i_Board, i_Piece.Location.X + i_Direction, i_Piece.Location.Y + i_Direction) && i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y + i_Direction].CurrentPiece != null) { if (i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y + i_Direction].CurrentPiece.Side == opponentSide) { if (IsInBorders(i_Board, i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y + (2 * i_Direction))) { if (i_Board.GameBoard[i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y + (2 * i_Direction)].CurrentPiece == null) { isCaptureMovePossible = true; } } } } return(isCaptureMovePossible); }
public static bool IsMovingInValidDirection(Player i_CurrentPlayer, Move i_Move, Piece i_Piece) { bool isDirectionValid = false; if (i_Piece.IsKing) { isDirectionValid = true; } else { // bottom player tries to move up if (i_CurrentPlayer.Side == ePlayerSide.Down && i_Move.FromRow > i_Move.ToRow) { isDirectionValid = true; } // top player tries to move down else if (i_CurrentPlayer.Side == ePlayerSide.Up && i_Move.FromRow < i_Move.ToRow) { isDirectionValid = true; } } return(isDirectionValid); }