Exemplo n.º 1
0
        public void TestGetCanJumpCells()
        {
            Jumper      jump1  = new Jumper(GetTestTable1());
            List <Cell> cells1 = jump1.GetCanJumpCells(new Cell(0, 0), new JumpRoute(GetTestTable1()));

            // 可能なcell (2,1)(1,2)
            Assert.AreEqual(2, cells1.Count);
            Assert.AreEqual(true, cells1.Any(a => a.X == 2 && a.Y == 1));
            Assert.AreEqual(true, cells1.Any(a => a.X == 1 && a.Y == 2));

            Jumper    jump2 = new Jumper(GetTestTable1());
            JumpRoute route = new JumpRoute(GetTestTable1());

            route.AddCell(new Cell(0, 3));
            List <Cell> cells2 = jump2.GetCanJumpCells(new Cell(2, 2), route);

            // 可能なcell (1,0)(0,1) (3,0)(4,1) (0,3)(1,4) (4,3)(3,4)
            Assert.AreEqual(7, cells2.Count);
            Assert.AreEqual(true, cells2.Any(a => a.X == 1 && a.Y == 0));
            Assert.AreEqual(true, cells2.Any(a => a.X == 0 && a.Y == 1));
            Assert.AreEqual(true, cells2.Any(a => a.X == 3 && a.Y == 0));
            Assert.AreEqual(true, cells2.Any(a => a.X == 4 && a.Y == 1));
            //Assert.AreEqual(true, cells2.Any(a => a.X == 0 && a.Y == 3));
            Assert.AreEqual(true, cells2.Any(a => a.X == 1 && a.Y == 4));
            Assert.AreEqual(true, cells2.Any(a => a.X == 4 && a.Y == 3));
            Assert.AreEqual(true, cells2.Any(a => a.X == 3 && a.Y == 4));
        }
Exemplo n.º 2
0
        public void TesCanEatAllCheese()
        {
            Table t1 = GetTestTable1();

            Assert.AreEqual(true, t1.CanEatAllCheese(GetJumpRoute1()));

            Table t2 = new Table(2, 2);

            Assert.AreEqual(false, t2.CanEatAllCheese(new JumpRoute(t2)));

            Table     t3    = GetTestTable3();
            JumpRoute route = new JumpRoute(t3);

            route.AddCell(new Cell(0, 0));
            Assert.AreEqual(false, t3.CanEatAllCheese(route));
            route.AddCell(new Cell(1, 2));
            Assert.AreEqual(true, t3.CanEatAllCheese(route));
        }
Exemplo n.º 3
0
        protected JumpRoute GetJumpRoute1()
        {
            JumpRoute route = new JumpRoute(GetTestTable1());

            foreach (Cell cell in route.Table.CheeseCells)
            {
                route.AddCell(cell);
            }
            return(route);
        }
Exemplo n.º 4
0
        public void TestCanJumpeToNext()
        {
            JumpRoute route1 = new JumpRoute(GetTestTable1());

            route1.AddCell(new Cell(0, 0));
            Assert.AreEqual(true, GetTestTable1().CanJumpeToNext(route1, new Cell(2, 1)));

            JumpRoute route2 = new JumpRoute(GetTestTable1());

            foreach (var tt in GetTestTable1().CheeseCells)
            {
                route2.AddCell(tt);
            }
            Assert.AreEqual(false, GetTestTable1().CanJumpeToNext(route2, new Cell(2, 1)));

            JumpRoute route3 = new JumpRoute(GetTestTable1());

            route3.AddCell(new Cell(0, 0));
            route3.AddCell(new Cell(2, 1));
            Assert.AreEqual(false, GetTestTable1().CanJumpeToNext(route3, new Cell(2, 1)));

            JumpRoute route4 = new JumpRoute(GetTestTable1());

            route4.AddCell(new Cell(0, 0));
            route4.AddCell(new Cell(2, 1));
            Assert.AreEqual(true, GetTestTable1().CanJumpeToNext(route4, new Cell(3, 3)));

            // (0,0) (1,2) (2,0) (3,2) (1,1) (3,0) (2,2) (1,0) (0,2) (2,1) (4,0)
            JumpRoute route5 = new JumpRoute(GetTestTable1());

            route5.AddCell(new Cell(0, 0));
            route5.AddCell(new Cell(2, 1));
            route5.AddCell(new Cell(3, 2));
            route5.AddCell(new Cell(4, 0));
            Assert.AreEqual(false, GetTestTable1().CanJumpeToNext(route5, new Cell(2, 1)));

            JumpRoute route6 = new JumpRoute(GetTestTable2());

            route6.Complete = true;
            Assert.AreEqual(false, GetTestTable2().CanJumpeToNext(route6, new Cell(2, 1)));
        }
Exemplo n.º 5
0
        public void TestAddCell()
        {
            JumpRoute route1 = new JumpRoute(GetTestTable1());

            route1.Complete = true;
            Assert.AreEqual(false, route1.AddCell(new Cell(2, 1)));
            Assert.AreEqual(0, route1.CellsCount);

            JumpRoute route2 = new JumpRoute(GetTestTable1());

            Assert.AreEqual(true, route2.AddCell(new Cell(0, 0)));
            Assert.AreEqual(true, route2.AddCell(new Cell(2, 1)));
            Assert.AreEqual(true, route2.AddCell(new Cell(0, 2)));
            Assert.AreEqual(false, route2.AddCell(new Cell(2, 1)));
            Assert.AreEqual(3, route2.CellsCount);

            JumpRoute route3 = new JumpRoute(GetTestTable1());

            route3.AddCell(new Cell(0, 0));
            route3.AddCell(new Cell(2, 1));
            Assert.AreEqual(true, route3.AddCell(new Cell(0, 2)));
            Assert.AreEqual(3, route3.CellsCount);
        }
Exemplo n.º 6
0
        public void TestGenerateJumpRouteByCurrentRoutes()
        {
            // 5x5 (0,0)からスタートCanJumpeToNext
            ShortestJumpRouteFinder finder1 = new ShortestJumpRouteFinder(GetTestTable1());
            // ReSharper disable once PossibleNullReferenceException
            List <JumpRoute> routes = finder1.GetType()
                                      .GetField("routes", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField)
                                      .GetValue(finder1) as List <JumpRoute>;
            JumpRoute route = new JumpRoute(finder1.Table, new Cell(0, 0));

            // ReSharper disable once PossibleNullReferenceException
            routes.Add(route);
            finder1.GetType().InvokeMember("GenerateJumpRouteByCurrentRoutes",
                                           BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, finder1, null);

            List <JumpRoute> routesNew1 = finder1.GetRouteEnumerator.ToList();

            Assert.AreEqual(2, routesNew1.Count);
            Assert.AreEqual(true, routesNew1.Any(a => a.ToString() == "0,0 2,1"));
            Assert.AreEqual(true, routesNew1.Any(a => a.ToString() == "0,0 1,2"));

            // 5x5 (0,0) (2,1)からスタート
            ShortestJumpRouteFinder finder2 = new ShortestJumpRouteFinder(GetTestTable1());
            // ReSharper disable once PossibleNullReferenceException
            List <JumpRoute> routes2 = finder2.GetType()
                                       .GetField("routes", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField)
                                       .GetValue(finder2) as List <JumpRoute>;
            JumpRoute route2 = new JumpRoute(finder2.Table, new Cell(0, 0));

            route2.AddCell(new Cell(2, 1));
            // ReSharper disable once PossibleNullReferenceException
            routes2.Add(route2);
            finder2.GetType().InvokeMember("GenerateJumpRouteByCurrentRoutes",
                                           BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, finder2, null);

            List <JumpRoute> routesNew2 = finder2.GetRouteEnumerator.ToList();

            Assert.AreEqual(5, routesNew2.Count);
            Assert.AreEqual(true, routesNew2.Any(a => a.ToString() == "0,0 2,1 4,0"));
            Assert.AreEqual(true, routesNew2.Any(a => a.ToString() == "0,0 2,1 0,2"));
            Assert.AreEqual(true, routesNew2.Any(a => a.ToString() == "0,0 2,1 1,3"));
            Assert.AreEqual(true, routesNew2.Any(a => a.ToString() == "0,0 2,1 4,2"));
            Assert.AreEqual(true, routesNew2.Any(a => a.ToString() == "0,0 2,1 3,3"));
        }