Example #1
0
 public void CoordinateToIdOn4x4Board(int x, int y, int n)
 {
     // |_|1|_|2|
     // |3|_|4|_|
     // |_|5|_|6|
     // |7|_|8|_|
     SquareId.FromPosition(x, y, 4).Should().Be(new SquareId(n));
 }
Example #2
0
        public void NonPlayableCoordinatesShouldThrow()
        {
            // |_|.|_|.|
            // |.|x|.|_|
            // |_|.|_|.|
            // |.|_|.|_|
            Action fromPosition = () => SquareId.FromPosition(1, 1, 4);

            fromPosition.Should().Throw <ManualValidationException>();
        }
Example #3
0
        public void DoMove(UserId currentUserId, GameId gameId, SquareId from, SquareId to)
        {
            _unitOfWork.WithGameTransaction(tran => {
                var(game, gameState) = FindGameAndState(gameId);
                _playGameDomainService.DoMove(game, gameState, currentUserId, from, to);

                _gameRepository.Save(game);
                _gameStateRepository.Save(gameState);

                tran.Commit();
            });
        }
Example #4
0
        public void DoMove(Game game, GameState gameState, UserId currentUserId, SquareId from, SquareId to)
        {
            game.ValidateCanDoMove(currentUserId);

            var moveResult = gameState.AddMove(from, to, game.Turn !.Player.Color, game.Settings);

            switch (moveResult)
            {
            case GameState.MoveResult.NextTurn:
                game.NextTurn(currentUserId, _clock.UtcNow());
                break;

            case GameState.MoveResult.MoreCapturesAvailable:
                break;     // No need to do anything, the user will do the next move.

            case GameState.MoveResult.GameOver:
                game.WinGame(currentUserId, _clock.UtcNow());
                break;

            default:
                throw new InvalidOperationException("Unknown MoveResult");
            }
        }
Example #5
0
 public void CoordinateToIdOn8x8Board(int x, int y, int n)
 {
     SquareId.FromPosition(x, y, 8).Should().Be(new SquareId(n));
 }
Example #6
0
 private SquareId Pos(int x, int y) => SquareId.FromPosition(x, y, 4);