public void FallActionsFallPiece2x2()
        {
            var board = builder.FromTypeGrid(new int[, ] {
                { 0, 1, 2, 0 },
                { 1, 0, 0, 2 },
                { 1, 1, 1, 2 },
                { 0, 1, 1, 2 }
            });
            var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var moves = new PotentialMove[] {
                new PotentialMove(c10, Orientation.Top),
                new PotentialMove(c01, Orientation.Right),
                new PotentialMove(c21, Orientation.Left),
            };

            foreach (var move in moves)
            {
                var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));
                simulator.Simulate();
                Assert.IsTrue(simulator.IsMovePossible());
                var actions     = simulator.GetMove().consequences;
                var fallActions = actions.Where(IsFallAction);
                foreach (var action in fallActions)
                {
                    Assert.AreEqual(2, (action as FallAction).rows);
                }
            }
        }
Exemple #2
0
        void Enter()
        {
            var board = new BoardGenerator().GenerateRandom(16, 3);
            var game  = new Game(board, GameRules.KeepSameRules, PieceType.GetRange(0, 3));

            bc.SetGame(game, logo);
        }
        public void NewPieceHasExpectedCoords()
        {
            var board = builder.FromTypeGrid(new int[, ] {
                { 0, 1, 2, 0 },
                { 1, 0, 0, 2 },
                { 1, 1, 1, 2 },
                { 0, 1, 1, 2 }
            });
            var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var moves = new PlayLogic(board).AvailableMoves();

            foreach (var move in moves)
            {
                var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));
                simulator.Simulate();
                var coord          = simulator.moveCoord;
                var piece          = simulator.oldPiece;
                var actions        = simulator.GetMove().consequences;
                var newPieceAction = actions.First(IsNewPieceAction) as NewPieceAction;
                Assert.AreEqual(new Coord {
                    col = coord.col, row = board.Size - piece.size
                }, newPieceAction.coord);
            }
        }
Exemple #4
0
        public void NotSolvedGameDetected()
        {
            var board = builder.FromTypeGrid("01 11");
            var types = PieceType.GetRange(0, 2);
            var game  = new Game(board, GameRules.ClassicRules, types);

            Assert.IsFalse(game.IsSolved);
        }
Exemple #5
0
        public void SolvedGameDetected()
        {
            var board = builder.FromTypeGrid("10 00");
            var types = PieceType.GetRange(0, 2);
            var game  = new Game(board, GameRules.ClassicRules, types);

            game.Execute(new PotentialMove(c01, game.Orientation));
            Assert.IsTrue(game.IsSolved);
        }
Exemple #6
0
        void CannotBeSolved(string typeGrid, int fromType, int countTypes, int maxIterations = 10000, int maxMoves = 25)
        {
            var board  = builder.FromTypeGrid(typeGrid);
            var game   = new Game(board, GameRules.ClassicRules, PieceType.GetRange(fromType, countTypes));
            var solver = new Solver(game);
            var result = solver.Solve(maxIterations, maxMoves);

            Assert.IsTrue(result.IsUnsolvable);
        }
Exemple #7
0
        void BoardCanBeSolvedAndVerified(Board board, int fromType, int countTypes, int maxIterations = 10000, int maxMoves = 25)
        {
            var game   = new Game(board, GameRules.ClassicRules, PieceType.GetRange(fromType, countTypes));
            var solver = new Solver(game);
            var result = solver.Solve(maxIterations, maxMoves);

            Assert.IsTrue(result.IsSolvable, "result: " + result);
            Assert.GreaterOrEqual(maxMoves, result.Moves.Count());
            Assert.IsTrue(MovesAreSolution(game, result.Moves), result.ToString());
        }
Exemple #8
0
        public void CannotBeBuildWithNullBoard()
        {
            var rules = new GameRules {
                NextTypePolicy = NextTypePolicy.RemovedType
            };
            var types = PieceType.GetRange(0, 3);

            Assert.Throws(typeof(InvalidGameStateException),
                          new TestDelegate(() => new Game(null, rules, types)));
        }
        public void LookAheadGoesBackAfterUndo()
        {
            var types = PieceType.GetRange(0, 3);
            var queue = IncomingQueue.GetQueue(GameRules.ClassicRules, types);

            CollectionAssert.AreEqual(types, queue.Incoming());
            queue.Next();
            queue.Undo();
            CollectionAssert.AreEqual(types, queue.Incoming());
        }
Exemple #10
0
        public void IncomingQueueAsExpectedOnDeterministic()
        {
            var board = builder.FromTypeGrid("01 12");
            var rules = new GameRules {
                NextTypePolicy = NextTypePolicy.Deterministic
            };
            var types = PieceType.GetRange(0, 3);
            var game  = new Game(board, rules, types);

            Assert.AreEqual(types, game.Incoming.Incoming());
        }
Exemple #11
0
        void AvailableMovesAreValid(Board board, int fromType, int numTypes)
        {
            var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(fromType, numTypes));
            var logic = new PlayLogic(board);

            foreach (var move in logic.AvailableMoves())
            {
                System.Console.WriteLine("move: " + move);
                game.Execute(move);
                game.Undo();
            }
        }
Exemple #12
0
        public void NextTypeIsExpectedOnRemovedType()
        {
            var board = builder.FromTypeGrid("01 12");
            var rules = new GameRules {
                NextTypePolicy = NextTypePolicy.RemovedType
            };
            var types = PieceType.GetRange(0, 3);
            var game  = new Game(board, rules, types);

            foreach (var coord in board.AllCoords)
            {
                Assert.IsTrue(new Piece(board.Get(coord).type, 1).Matches(game.NextPieceIfPlaying(new PotentialMove(coord, board.Orientation))));
            }
        }
        public void OnlyExpectedPiecesReturnedInRandom()
        {
            var types = PieceType.GetRange(0, 4);
            var queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy    = NextTypePolicy.Random,
                MatchAllWeight    = 0,
                MatchNoneWeight   = 0,
                OtherPiecesWeight = 100
            }, types);

            for (int i = 0; i < 100; i++)
            {
                Assert.Contains(queue.Next(), types);
            }
        }
        void Start()
        {
            var types = new PieceType[] {
                PieceType.Get(0),
                PieceType.Get(1),
                PieceType.Get(2)
            };

            var game = new Game(
                new BoardGenerator().GenerateRandom(16, types),
                GameRules.ClassicRules,
                PieceType.GetRange(0, 3));

            bc.SetGame(game, texture);
        }
        public void OnlyMatchNoneReturned()
        {
            var types = PieceType.GetRange(0, 4);
            var queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy    = NextTypePolicy.Random,
                MatchAllWeight    = 0,
                MatchNoneWeight   = 1,
                OtherPiecesWeight = 0
            }, types);

            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(PieceType.MatchNone, queue.Next());
            }
        }
Exemple #16
0
        public void SpecialCaseAvailableMoves()
        {
            var board = builder.FromTypeGrid("0111 0011 1100 1100");

            board.RotateRight();
            var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 2));
            var logic = new PlayLogic(board);

            foreach (var move in logic.AvailableMoves())
            {
                game.Execute(move);
                game.Undo();
            }
            Assert.Pass("All moves could be done");
        }
        public void CanSimulateRotatedMove()
        {
            var board = builder.FromTypeGrid(new int[, ] {
                { 0, 1, 2, 0 },
                { 1, 0, 0, 2 },
                { 1, 1, 1, 2 },
                { 0, 1, 1, 2 }
            });
            var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var move      = new PotentialMove(c03, Orientation.Right);
            var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));

            simulator.Simulate();
            Assert.IsTrue(simulator.IsMovePossible());
        }
        public void CanAlwaysSimulateAvailableMovesRnd()
        {
            for (int i = 0; i < 10; i++)
            {
                var board = generator.GenerateRandom(8, 3);
                var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

                var logic = new PlayLogic(board);
                var moves = logic.AvailableMoves();
                foreach (var move in moves)
                {
                    var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));
                    simulator.Simulate();
                    Assert.IsTrue(simulator.IsMovePossible());
                }
            }
        }
        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));
        }
        public void ReturnsExpectedPiecesAndSpecials()
        {
            var types = PieceType.GetRange(0, 4);
            var queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy    = NextTypePolicy.Random,
                MatchAllWeight    = 20,
                MatchNoneWeight   = 10,
                OtherPiecesWeight = 100
            }, types);

            var allTypes = new List <PieceType>(types);

            allTypes.Add(PieceType.MatchAll);
            allTypes.Add(PieceType.MatchNone);

            for (int i = 0; i < 100; i++)
            {
                Assert.Contains(queue.Next(), allTypes);
            }
        }
        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);
        }
        public void UndoReturnsToExpectedState()
        {
            var types = PieceType.GetRange(0, 3);
            var queue = IncomingQueue.GetQueue(GameRules.ClassicRules, types);

            Assert.AreEqual(t0, queue.Next());
            queue.Undo();
            Assert.AreEqual(t0, queue.Next());
            Assert.AreEqual(t1, queue.Next());
            queue.Undo();
            Assert.AreEqual(t1, queue.Next());
            Assert.AreEqual(t2, queue.Next());
            queue.Undo();
            Assert.AreEqual(t2, queue.Next());
            Assert.AreEqual(t0, queue.Next());
            queue.Undo();
            Assert.AreEqual(t0, queue.Next());
            queue.Undo();
            queue.Undo();
            Assert.AreEqual(t2, queue.Next());
        }
        public void NewPieceHasExpectedSize()
        {
            var board = builder.FromTypeGrid(new int[, ] {
                { 0, 1, 2, 0 },
                { 2, 1, 0, 2 },
                { 1, 2, 1, 1 },
                { 0, 1, 1, 1 }
            });

            var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));
            var logic = new PlayLogic(board);

            foreach (var move in logic.AvailableMoves())
            {
                var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));
                simulator.Simulate();
                var actions        = simulator.GetMove().consequences;
                var newPieceAction = actions.First(IsNewPieceAction) as NewPieceAction;
                Assert.AreEqual(simulator.oldPiece.size, newPieceAction.newPiece.size);
            }
        }
        public void LookAheadHasExpectedSize()
        {
            var queue = IncomingQueue.GetQueue(GameRules.ClassicRules, t3, t1, t0);

            Assert.AreEqual(3, queue.LookAheadSize());
            queue = IncomingQueue.GetQueue(GameRules.ClassicRules, PieceType.GetRange(0, 100));
            Assert.AreEqual(100, queue.LookAheadSize());

            queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy = NextTypePolicy.Random,
                MatchAllWeight = 0, MatchNoneWeight = 0, OtherPiecesWeight = 100,
            }, PieceType.GetRange(0, 37));
            Assert.AreEqual(37, queue.LookAheadSize());
            queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy = NextTypePolicy.Random,
                MatchAllWeight = 1, MatchNoneWeight = 0, OtherPiecesWeight = 100,
            }, PieceType.GetRange(0, 37));
            Assert.AreEqual(38, queue.LookAheadSize());
            queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy = NextTypePolicy.Random,
                MatchAllWeight = 0, MatchNoneWeight = 0, OtherPiecesWeight = 100,
            }, PieceType.GetRange(0, 37));
            Assert.AreEqual(37, queue.LookAheadSize());
            queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy = NextTypePolicy.Random,
                MatchAllWeight = 1, MatchNoneWeight = 1, OtherPiecesWeight = 100,
            }, PieceType.GetRange(0, 37));
            queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy = NextTypePolicy.Random,
                MatchAllWeight = 10, MatchNoneWeight = 10, OtherPiecesWeight = 0,
            }, PieceType.GetRange(0, 37));
            Assert.AreEqual(2, queue.LookAheadSize());

            queue = IncomingQueue.GetQueue(new GameRules {
                NextTypePolicy = NextTypePolicy.RemovedType
            }, PieceType.GetRange(0, 4));
            Assert.AreEqual(0, queue.LookAheadSize());
        }
        public void FallActionsFallPieceSizeRnd()
        {
            for (int i = 0; i < 50; i++)
            {
                var board = generator.GenerateRandom(4, 3);
                var game  = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

                var logic = new PlayLogic(board);
                foreach (var potentialMove in logic.AvailableMoves())
                {
                    var simulator = MoveSimulator.FromPotentialMove(board, potentialMove, game.NextPieceIfPlaying(potentialMove));
                    simulator.Simulate();
                    var move        = simulator.GetMove();
                    var fallActions = move.consequences.Where(IsFallAction);
                    foreach (var action in fallActions)
                    {
                        var orientatedCoord = board.TransportCoord(potentialMove.coord, potentialMove.orientation);
                        var removedPiece    = board.Get(orientatedCoord);
                        Assert.AreEqual(removedPiece.size, (action as FallAction).rows,
                                        "Fall Action:\n" + action + ",\nboard:\n" + board + "\nmove:\n" + potentialMove);
                    }
                }
            }
        }
Exemple #26
0
        Game ClassicGameFrom(string typeGrid, int fromType, int countTypes)
        {
            var board = builder.FromTypeGrid(typeGrid);

            return(new Game(board, GameRules.ClassicRules, PieceType.GetRange(fromType, countTypes)));
        }