public void ShouldReturnFalseIfFewerThan4DiscsOnBoard()
        {
            var board = new Board
                {
                    BoundaryX = 20,
                    BoundaryY = 20,
                    DiscsOnBoard = new List<DiscPosition>
                        {
                            new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 10 },
                            new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 11 },
                            new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 12 },
                            new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 13 },
                            new DiscPosition { PlayerInitialLetter = 'U', X = 15, Y = 10 },
                        }
                };

            var checker = new Mock<IWinnerChecker>();
            var winningCombo = new List<DiscPosition>();
            checker.Setup(c => c.IsWinner(new List<DiscPosition>(), out winningCombo)).Returns(true);

            var checkers = new List<IWinnerChecker>() { checker.Object };

            var result = _gameManager.IsWinner(board.DiscsOnBoard, 'T', checkers, out winningCombo);

            Assert.IsFalse(result);
        }
Beispiel #2
0
        public void AddDisc(DiscPosition discPosition, Board board, out bool isLegalPlay)
        {
            isLegalPlay = true;

            //Outside the board
            if (discPosition.X > board.BoundaryX
                || discPosition.Y > board.BoundaryY
                || discPosition.X < 1
                || discPosition.Y < 1)
            {
                isLegalPlay = false;
            }

            if(board.DiscsOnBoard == null)
                board.DiscsOnBoard = new List<DiscPosition>();

            //On occupied position
            if (board.DiscsOnBoard.Exists(p =>
                p.X.Equals(discPosition.X) && p.Y.Equals(discPosition.Y)
                ))
            {
                isLegalPlay = false;
            }

            board.DiscsOnBoard.Add(discPosition);
        }
        public Board GetBoard()
        {
            var board = new Board
                {
                    BoundaryX = 20,
                    BoundaryY = 20,
                    DiscsOnBoard = new List<DiscPosition>()
                };

            return board;
        }
        public DiscPosition Play(Board board)
        {
            var possiblePosition = GetPossibleDiscPosition(board.DiscsOnBoard, board.BoundaryX, board.BoundaryY);

            var myMove = new DiscPosition
                {
                    X = possiblePosition.X,
                    Y = possiblePosition.Y
                };

            return myMove;
        }
        public void ShouldNotThrowExceptionIfDiscsOnBoardIsNull()
        {
            var disc = new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 10 };
            var board = new Board
            {
                BoundaryX = 20,
                BoundaryY = 20
            };

            bool isLegalPlay = true;

            Assert.DoesNotThrow(() => _gameManager.AddDisc(disc, board, out isLegalPlay));
        }
        public void ShouldStateIllegalPlayIfOutsideBoard()
        {
            var disc = new DiscPosition { PlayerInitialLetter = 'T', X = 0, Y = 0 };
            var board = new Board { BoundaryX = 20, BoundaryY = 20 };
            bool isLegalPlay = true;

            _gameManager.AddDisc(disc, board, out isLegalPlay);

            Assert.IsFalse(isLegalPlay);
        }
        public void ShouldStateIllegalPlayIfAddingOnOccupiedPosition()
        {
            var disc = new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 10 };
            var board = new Board
                {
                    BoundaryX = 20,
                    BoundaryY = 20,
                    DiscsOnBoard = new List<DiscPosition>
                        {
                            new DiscPosition { PlayerInitialLetter = 'T', X = 15, Y = 10 }
                        }
                };
            bool isLegalPlay = true;

            _gameManager.AddDisc(disc, board, out isLegalPlay);

            Assert.IsFalse(isLegalPlay);
        }
 public DiscPosition Play(Board board)
 {
     return Player.Play(board);
 }