public ViewBoardResponse Execute(ViewBoardRequest request)
        {
            Board board = _boardReader.Fetch();

            return(new ViewBoardResponse
            {
                Board = board,
                Status = board.IsComplete() ? (IBoardStatus) new Complete() : new Incomplete()
            });
        }
Ejemplo n.º 2
0
        public void Execute(int x, int y)
        {
            var board = _boardReader.Fetch();

            if (board.PieceAt(x, y) != null)
            {
                return;
            }

            int pieceType = board.GetCurrentPieceType();

            _boardWriter.Write(board.NewBoardWithPieceAt(pieceType, x, y));
        }
Ejemplo n.º 3
0
        public SeeBoardResponse Execute()
        {
            var board = _boardReader.Fetch();

            var winner0 = IsHorizontalWinner(board.Pieces, 0) ||
                          IsVerticalWinner(board.Pieces, 0) ||
                          IsDiagonalWinner(board.Pieces, 0);
            var winner1 = IsHorizontalWinner(board.Pieces, 1) ||
                          IsVerticalWinner(board.Pieces, 1) ||
                          IsDiagonalWinner(board.Pieces, 1);
            var presentableWinner = ToPresentableWinner(winner0, winner1);

            var response = new SeeBoardResponse
            {
                Board        = board.Pieces,
                Winner       = presentableWinner,
                HasGameEnded = board.Pieces.Cast <int?>().ToArray().Count(x => x != null) == 9 ||
                               presentableWinner != null
            };

            return(response);
        }