예제 #1
0
        public void CanPlayDoublePieceFromCoord()
        {
            var board = builder.FromTypeGrid("0101 1101 1100 1110");

            foreach (var coord in Coord.SquareRange(c00, 2))
            {
                var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s2);
                simulator.Simulate();
                Assert.Pass();
            }
        }
예제 #2
0
        public void NewPieceHasExpectedType()
        {
            var board = builder.FromTypeGrid("10 21");

            foreach (var coord in board.AllCoords)
            {
                var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1);
                simulator.Simulate();
                var actions        = simulator.GetMove().consequences;
                var newPieceAction = actions.First(IsNewPieceAction) as NewPieceAction;
                Assert.AreEqual(t0, newPieceAction.newPiece.type);
            }
        }
예제 #3
0
        public void NotValidMoveDetected()
        {
            var board = builder.FromTypeGrid("10 20");

            foreach (var coord in new Coord[] { c10, c11 })
            {
                var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1);
                simulator.Simulate();
                Assert.IsFalse(simulator.IsMovePossible());
                Assert.Throws(typeof(InvalidGameOperationException),
                              new TestDelegate(() => { simulator.GetMove(); }));
            }
        }
예제 #4
0
        public void BoardIsUntouched()
        {
            var board  = builder.FromTypeGrid("1020 1201 2201 0021");
            var backup = board.Clone();

            Assert.IsTrue(board.Matches(backup));
            foreach (var coord in board.AllCoords)
            {
                var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1);
                simulator.Simulate();
                Assert.IsTrue(board.Matches(backup));
            }
        }
예제 #5
0
        public void OnlyOneNewPieceAdded()
        {
            // all coords have moves
            var board = builder.FromTypeGrid("12 01");

            foreach (var coord in board.AllCoords)
            {
                var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1);
                simulator.Simulate();
                var actions        = simulator.GetMove().consequences;
                var newPieceAction = actions.Where(IsNewPieceAction);
                Assert.AreEqual(1, newPieceAction.Count());
            }
        }
예제 #6
0
        void ProcessClickedCoord(Coord coord)
        {
            coord = GetBaseCoord(coord);
            var simulator = MoveSimulator.FromCoord(board, coord, Game.NextPieceIfPlaying(coord));

            simulator.Simulate();
            if (simulator.IsMovePossible())
            {
                Execute(simulator.GetMove());
            }
            else
            {
                DisplayObstacles(simulator.Obstacles());
            }
        }
예제 #7
0
        public void CompactsIfNeeded()
        {
            var board = builder.FromTypeGrid("01 00");
            var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var simulator = MoveSimulator.FromCoord(board, c11, game.NextPieceIfPlaying(new PotentialMove(c11, board.Orientation)));

            simulator.Simulate();
            Assert.IsTrue(simulator.IsMovePossible());
            var actions = simulator.GetMove().consequences;

            Assert.AreEqual(1, actions.Count(IsCompactAction));
            var compactAction = actions.First(IsCompactAction) as CompactAction;

            Assert.AreEqual(c00, compactAction.coord);
            Assert.IsTrue(piece_t0_s2.Matches(compactAction.bigPiece));
        }
예제 #8
0
        public void StartsAndEndsInCorrectOrientation()
        {
            var board = builder.FromTypeGrid("10 21");

            for (int i = 0; i < 4; i++)
            {
                board.RotateLeft();
                foreach (var coord in board.AllCoords)
                {
                    var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1);
                    simulator.Simulate();
                    var actions  = simulator.GetMove().consequences;
                    var expected = OrientateAction.Get(board.Orientation);
                    Assert.AreEqual(expected, actions.First(), "first action orientates in board's current orientation");
                    Assert.AreEqual(expected, actions.Last(), "last action orientates in board's current orientation");
                }
            }
        }
예제 #9
0
        public void FallActionsStartFromBottom()
        {
            var board = builder.FromTypeGrid("0100 0200 1212 2021");
            var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var simulator = MoveSimulator.FromCoord(board, c10, game.NextPieceIfPlaying(new PotentialMove(c10, board.Orientation)));

            simulator.Simulate();
            Assert.IsTrue(simulator.IsMovePossible());
            var move        = simulator.GetMove();
            var actions     = move.consequences;
            var fallActions = actions.Where(IsFallAction);

            Assert.IsNotEmpty(fallActions);
            var arrActions = fallActions.ToArray();

            Assert.AreEqual(c11, (arrActions[0] as FallAction).coord);
            Assert.AreEqual(c12, (arrActions[1] as FallAction).coord);
            Assert.AreEqual(c13, (arrActions[2] as FallAction).coord);
        }