public Game DoMove(Guid gameId, Move move) { var game = GameMechanics.Persistence.LoadGame(gameId); if (!GameMechanics.Rules.IsValidMove(game.GetCurrentState(), move)) { throw new GameRulesBrokenException("That is not a valid move at this point!"); } var newState = GameMechanics.Rules.GetNewStateAfterMove(game.GetCurrentState(), move); game.States.Add(newState); GameMechanics.Persistence.SaveGame(game); return game; }
// This is wrong! Any move is considered valid! public bool IsValidMove(GameState gameState, Move move) { return true; }
// This is correct! But none of the ApplyMove calls are... :-( public GameState GetNewStateAfterMove(GameState currentState, Move move) { return move.ApplyMove(currentState); }