Esempio n. 1
0
        public void testSimpleBoardSuccessorGenerator()
        {
            ICollection <QueenAction> actions = CollectionFactory.CreateQueue <QueenAction>(actionsFn.apply(oneBoard));

            Assert.AreEqual(1, actions.Size());
            NQueensBoard next = resultFn.apply(oneBoard, actions.Get(0));

            Assert.AreEqual(1, next.getNumberOfQueensOnBoard());
        }
Esempio n. 2
0
        public void testSuccessors()
        {
            ICollection <AgentPosition>             succPositions   = CollectionFactory.CreateQueue <AgentPosition>();
            ICollection <AgentPosition.Orientation> succOrientation = CollectionFactory.CreateQueue <AgentPosition.Orientation>();

            // From every position the possible actions are:
            //    - Turn right (change orientation, not position)
            //    - Turn left (change orientation, not position)
            //    - Forward (change position, not orientation)
            AgentPosition P11U = new AgentPosition(1, 1, AgentPosition.Orientation.FACING_NORTH);

            succPositions.Add(new AgentPosition(1, 2, AgentPosition.Orientation.FACING_NORTH));
            succOrientation.Add(AgentPosition.Orientation.FACING_EAST);
            succOrientation.Add(AgentPosition.Orientation.FACING_WEST);
            foreach (IAction a in actionFn.apply(P11U))
            {
                if (a is Forward)
                {
                    Assert.IsTrue(succPositions.Contains(((Forward)a).getToPosition()));
                    Assert.IsTrue(succPositions.Contains(resultFn.apply(P11U, a)));
                }
                else if (a is TurnLeft)
                {
                    Assert.IsTrue(succOrientation.Contains(((TurnLeft)a).getToOrientation()));
                    Assert.AreEqual("[1,1]->FacingWest", resultFn.apply(P11U, a).ToString());
                }
                else if (a is TurnRight)
                {
                    Assert.IsTrue(succOrientation.Contains(((TurnRight)a).getToOrientation()));
                    Assert.AreEqual("[1,1]->FacingEast", resultFn.apply(P11U, a).ToString());
                }
            }


            //If you are in front of a wall forward action is not possible
            AgentPosition P31D = new AgentPosition(3, 1, AgentPosition.Orientation.FACING_SOUTH);
            AgentPosition P41R = new AgentPosition(4, 1, AgentPosition.Orientation.FACING_EAST);

            foreach (IAction a in actionFn.apply(P31D))
            {
                Assert.IsFalse(a is Forward);
            }

            foreach (IAction a in actionFn.apply(P41R))
            {
                Assert.IsFalse(a is Forward);
            }
        }
Esempio n. 3
0
        public void testSuccessors()
        {
            ICollection <string> locations = CollectionFactory.CreateQueue <string>();

            // A
            locations.Clear();
            locations.Add("B");
            locations.Add("C");
            foreach (MoveToAction a in actionsFn.apply("A"))
            {
                Assert.IsTrue(locations.Contains(a.getToLocation()));
                Assert.IsTrue(locations.Contains(resultFn.apply("A", a)));
            }

            // B
            locations.Clear();
            locations.Add("A");
            locations.Add("C");
            locations.Add("E");
            foreach (MoveToAction a in actionsFn.apply("B"))
            {
                Assert.IsTrue(locations.Contains(a.getToLocation()));
                Assert.IsTrue(locations.Contains(resultFn.apply("B", a)));
            }

            // C
            locations.Clear();
            locations.Add("A");
            locations.Add("B");
            locations.Add("D");
            foreach (MoveToAction a in actionsFn.apply("C"))
            {
                Assert.IsTrue(locations.Contains(a.getToLocation()));
                Assert.IsTrue(locations.Contains(resultFn.apply("C", a)));
            }

            // D
            locations.Clear();
            locations.Add("C");
            foreach (MoveToAction a in actionsFn.apply("D"))
            {
                Assert.IsTrue(locations.Contains(a.getToLocation()));
                Assert.IsTrue(locations.Contains(resultFn.apply("D", a)));
            }
            // E
            locations.Clear();
            Assert.IsTrue(0 == actionsFn.apply("E").Size());
        }
Esempio n. 4
0
 public S getResult(S state, A action)
 {
     return(resultFn.apply(state, action));
 }