コード例 #1
0
        public void indicate_current_state_is_goal_state()
        {
            var buildingState = new BuildingState(new List <char>()
            {
                'H', 'L'
            });

            buildingState.SetChipLocation('H', 3);
            buildingState.SetGeneratorLocation('H', 3);
            buildingState.SetChipLocation('L', 3);
            buildingState.SetGeneratorLocation('L', 3);
            buildingState.ElevatorLocation = 3;

            var goalState = BuildingState.CreateGoalState(buildingState);

            var stateTraverser = new StateTraverser();

            var stepsToGoalState = stateTraverser.GetStepsToGoalState(buildingState, goalState);

            Assert.AreEqual(0, stepsToGoalState);
        }
コード例 #2
0
        public void indicate_no_possible_path_from_current_state()
        {
            var buildingState = new BuildingState(new List <char>()
            {
                'H', 'L', 'S'
            });

            buildingState.SetChipLocation('H', 0);
            buildingState.SetGeneratorLocation('H', 0);
            buildingState.SetChipLocation('L', 1);
            buildingState.SetGeneratorLocation('L', 3);
            buildingState.SetChipLocation('S', 2);
            buildingState.SetGeneratorLocation('S', 2);
            buildingState.ElevatorLocation = 1;

            var goalState = BuildingState.CreateGoalState(buildingState);

            var stateTraverser = new StateTraverser();

            var stepsToGoalState = stateTraverser.GetStepsToGoalState(buildingState, goalState);

            Assert.AreEqual(-1, stepsToGoalState);
        }
コード例 #3
0
        public static BuildingState CreateGoalState(BuildingState currentState)
        {
            var goalState = new BuildingState(currentState.ElementNames)
            {
                ElevatorLocation = TopFloor
            };

            foreach (var element in currentState.ElementNames)
            {
                goalState.SetChipLocation(element, TopFloor);
                goalState.SetGeneratorLocation(element, TopFloor);
            }

            return(goalState);
        }