Esempio n. 1
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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        private DiscPosition GetPossibleDiscPosition(IList<DiscPosition> occupiedPositions, int boundaryX, int boundaryY)
        {
            var suggestion = new DiscPosition();
            var positionComparer = new PositionComparer();
            var maxIterations = boundaryX * boundaryY;

            do
            {
                suggestion = new DiscPosition
                {
                    X = Randomizer.Next(1, boundaryX + 1),
                    Y = Randomizer.Next(1, boundaryY + 1)
                };

                maxIterations--;
            }
            while (occupiedPositions.Contains(suggestion, positionComparer)
                && maxIterations >= 0);

            return suggestion;
        }
Esempio n. 6
0
        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);
        }