protected virtual void SetGameStatus(GameModel game) { var gameStatus = GameStatusType.Ongoing; game.SwitchPlayerPerspective(() => { if (PiecesManagerService.IsKingCaptured(game)) { gameStatus = GameStatusType.Win; } else if (PiecesManagerService.IsPlayerUnableToMove(game)) { gameStatus = GameStatusType.Draw; } }); if (gameStatus != GameStatusType.Ongoing) { game.GameStatusModel = new GameStatusModel(gameStatus); if (gameStatus is GameStatusType.Win) { game.GameStatusModel.Winner = game.MovingPlayer; } } }
public MoveCommand MakeMove(GameModel game, Move move, string promotionType = null) { if (game.GameStatusModel != null) { return(null); } var validatedMoveCommand = GameValidationService.ValidateMove(game, move); if (validatedMoveCommand == null) { return(null); } if (validatedMoveCommand is PawnPromotionCommand) { if (promotionType == null) { // we return without updating anything because we wait // the client to tell us which piece it wants to promote to return(validatedMoveCommand); } ((PawnPromotionCommand)validatedMoveCommand).PromotionType = promotionType; } var validatedMoveCommandClientCopy = validatedMoveCommand.Clone(); PiecesManagerService.UpdatePieces(game, validatedMoveCommand); SetGameStatus(game); UpdateGameMovesHistory(game, validatedMoveCommand); game.SwitchTurns(); return(validatedMoveCommandClientCopy); }