Ejemplo n.º 1
0
        public void TestExtraTurnForBlackBug()
        {
            var sut   = new TurnCalculator();
            var board = new MatrixBoard();
            {
                board.IsTurnOfBlackPlayer = true;

                board.TryConsumeNamedCellByWhitePlayer("E4");
                board.TryConsumeNamedCellByWhitePlayer("E5");

                board.TryConsumeNamedCellByBlackPlayer("C5");
                board.TryConsumeNamedCellByBlackPlayer("D5");
                board.TryConsumeNamedCellByBlackPlayer("D4");
                board.TryConsumeNamedCellByBlackPlayer("E6");
            }


            var result = sut.GetValidTurnsForBoard(board);

            Assert.IsNotNull(result);
            Assert.AreEqual(5, result.Count());

            string strTurnPositions      = BoardCoordinatesConverter.PrintTurnPositions(result);
            string expectedTurnPositions = "E3; F3; F4; F5; F6";

            Assert.AreEqual(expectedTurnPositions, strTurnPositions);
        }
Ejemplo n.º 2
0
        public void TestReverseDiagonalFlips()
        {
            var sut   = new TurnCalculator();
            var board = new MatrixBoard();
            {
                board.IsTurnOfBlackPlayer = false;

                board.TryConsumeNamedCellByWhitePlayer("A8");
                board.TryConsumeNamedCellByWhitePlayer("H1");

                board.TryConsumeNamedCellByBlackPlayer("B7");
                board.TryConsumeNamedCellByBlackPlayer("C6");
                board.TryConsumeNamedCellByBlackPlayer("D5");
                board.TryConsumeNamedCellByBlackPlayer("E4");
                board.TryConsumeNamedCellByBlackPlayer("G2");
            }

            var result = sut.GetValidTurnsForBoard(board);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());

            IReversiTurn turn        = result.First();
            string       strPosition = BoardCoordinatesConverter.CoordinatesToCellName(turn.Position);

            Assert.AreEqual("F3", strPosition);

            Assert.AreEqual(5, turn.PositionsOfFlippedItems.Count());

            var sortedFlips =
                turn.PositionsOfFlippedItems.OrderBy(c =>
            {
                return(BoardCoordinatesConverter.CoordinatesToCellName(c));
            });
            string strSortedFlips = BoardCoordinatesConverter.PrintCoordinates(sortedFlips);
            string expectedFlips  = "B7; C6; D5; E4; G2";

            Assert.AreEqual(expectedFlips, strSortedFlips);
        }
Ejemplo n.º 3
0
        public void TestNoFlipsIfBoardEndReached()
        {
            var sut   = new TurnCalculator();
            var board = new MatrixBoard();
            {
                board.IsTurnOfBlackPlayer = false;
                board.TryConsumeNamedCellByBlackPlayer("A1");
                board.TryConsumeNamedCellByBlackPlayer("H1");
                board.TryConsumeNamedCellByBlackPlayer("A8");
                board.TryConsumeNamedCellByBlackPlayer("H8");
                board.TryConsumeNamedCellByBlackPlayer("A4");
                board.TryConsumeNamedCellByBlackPlayer("H4");
                board.TryConsumeNamedCellByBlackPlayer("D1");
                board.TryConsumeNamedCellByBlackPlayer("D8");


                // Diagonal
                board.TryConsumeNamedCellByBlackPlayer("B2");
                board.TryConsumeNamedCellByBlackPlayer("C3");
                board.TryConsumeNamedCellByBlackPlayer("E5");
                board.TryConsumeNamedCellByBlackPlayer("F6");
                board.TryConsumeNamedCellByBlackPlayer("G7");

                // Horizontal
                board.TryConsumeNamedCellByBlackPlayer("B4");
                board.TryConsumeNamedCellByBlackPlayer("C4");
                board.TryConsumeNamedCellByBlackPlayer("E4");
                board.TryConsumeNamedCellByBlackPlayer("F4");
                board.TryConsumeNamedCellByBlackPlayer("G4");

                // Vertical
                board.TryConsumeNamedCellByBlackPlayer("D2");
                board.TryConsumeNamedCellByBlackPlayer("D3");
                board.TryConsumeNamedCellByBlackPlayer("D5");
                board.TryConsumeNamedCellByBlackPlayer("D6");
                board.TryConsumeNamedCellByBlackPlayer("D7");
            }


            var result = sut.GetValidTurnsForBoard(board);

            Assert.IsNull(result);
        }
Ejemplo n.º 4
0
        public void TestMultipleDirections()
        {
            var sut   = new TurnCalculator();
            var board = new MatrixBoard();
            {
                board.IsTurnOfBlackPlayer = false;
                board.TryConsumeNamedCellByWhitePlayer("A1");
                board.TryConsumeNamedCellByWhitePlayer("H1");
                board.TryConsumeNamedCellByWhitePlayer("A8");
                board.TryConsumeNamedCellByWhitePlayer("H8");
                board.TryConsumeNamedCellByWhitePlayer("A4");
                board.TryConsumeNamedCellByWhitePlayer("H4");
                board.TryConsumeNamedCellByWhitePlayer("D1");
                board.TryConsumeNamedCellByWhitePlayer("D8");


                // Diagonal
                board.TryConsumeNamedCellByBlackPlayer("B2");
                board.TryConsumeNamedCellByBlackPlayer("C3");
                board.TryConsumeNamedCellByBlackPlayer("E5");
                board.TryConsumeNamedCellByBlackPlayer("F6");
                board.TryConsumeNamedCellByBlackPlayer("G7");

                // Horizontal
                board.TryConsumeNamedCellByBlackPlayer("B4");
                board.TryConsumeNamedCellByBlackPlayer("C4");
                board.TryConsumeNamedCellByBlackPlayer("E4");
                board.TryConsumeNamedCellByBlackPlayer("F4");
                board.TryConsumeNamedCellByBlackPlayer("G4");

                // Vertical
                board.TryConsumeNamedCellByBlackPlayer("D2");
                board.TryConsumeNamedCellByBlackPlayer("D3");
                board.TryConsumeNamedCellByBlackPlayer("D5");
                board.TryConsumeNamedCellByBlackPlayer("D6");
                board.TryConsumeNamedCellByBlackPlayer("D7");
            }


            var result = sut.GetValidTurnsForBoard(board);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());

            IReversiTurn turn        = result.First();
            string       strPosition = BoardCoordinatesConverter.CoordinatesToCellName(turn.Position);

            Assert.AreEqual("D4", strPosition);

            Assert.AreEqual(15, turn.PositionsOfFlippedItems.Count());

            var sortedFlips =
                turn.PositionsOfFlippedItems.OrderBy(c =>
            {
                return(BoardCoordinatesConverter.CoordinatesToCellName(c));
            });
            string strSortedFlips = BoardCoordinatesConverter.PrintCoordinates(sortedFlips);
            string expectedFlips  = "B2; B4; C3; C4; D2; D3; D5; D6; D7; E4; E5; F4; F6; G4; G7";

            Assert.AreEqual(expectedFlips, strSortedFlips);
        }