public bool ValidateAndMove(ChessMove chessMove, ChessColor playerColor) { if (promotionDetector.IsPromotionRequired()) { return(ValidateAndPromote(chessMove)); } var piece = chessBoard.Pieces .FirstOrDefault(p => p.Position == chessMove.StartingPosition); if (piece == null) { return(false); } if (piece.Color != playerColor) { return(false); } var movements = legalMovement.GetAvailableLegalMoves(piece); if (!movements.Contains(chessMove)) { return(false); } chessBoard.Move(chessMove); return(true); }
public ChessPlayResult Play(ChessMove chessMove, ChessColor player) { if (IsGameFinished()) { return(checkResult); } if (player != CurrentPlayer) { return(ChessPlayResult.WrongPlayer); } if (!moveValidator.ValidateAndMove(chessMove, player)) { return(ChessPlayResult.InvalidMove); } if (promotionDetector.IsPromotionRequired()) { return(ChessPlayResult.PromotionRequired); } CurrentPlayer = CurrentPlayer.Opposite(); checkResult = gameFinishedDetector.IsGameFinished(CurrentPlayer); return(checkResult); }