Ejemplo n.º 1
0
        /// <inheritdoc />
        public GameMoveDetails GetMove(string gameId, int moveNumber)
        {
            if (string.IsNullOrWhiteSpace(gameId))
            {
                throw new ArgumentException(nameof(gameId));
            }

            if (moveNumber < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(moveNumber));
            }

            var game = GetById(gameId);

            if (game == null)
            {
                return(null);
            }

            LoadGameBoard(game);

            var move = game.GameBoard.Moves.ElementAtOrDefault(moveNumber);

            if (move == null)
            {
                return(null);
            }

            return(GameMoveDetails.FromEntity(game, move));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public IEnumerable <GameMoveDetails> GetMoves(string gameId)
        {
            if (string.IsNullOrWhiteSpace(gameId))
            {
                throw new ArgumentException(nameof(gameId));
            }

            var game = GetById(gameId);

            if (game == null)
            {
                return(null);
            }

            LoadGameBoard(game);

            return(game.GameBoard.Moves.Select(move => GameMoveDetails.FromEntity(game, move)));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public IEnumerable <GameMoveDetails> GetMoves(string gameId, int start, int until)
        {
            if (string.IsNullOrWhiteSpace(gameId))
            {
                throw new ArgumentException(nameof(gameId));
            }

            if (start < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }

            if (until < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(until));
            }

            if (until < start)
            {
                throw new ArgumentException("until cannot be less than start");
            }

            var game = GetById(gameId);

            if (game == null)
            {
                return(null);
            }

            LoadGameBoard(game);

            // TODO: This could be more efficient by only returning the desired rows from the database
            // instead of loading them all into memory, then converting to array, then segmenting it
            var moves = new ArraySegment <GameMove>(game.GameBoard.Moves.ToArray(), start, until - start + 1);

            return(moves.Select(move => GameMoveDetails.FromEntity(game, move)));
        }