Ejemplo n.º 1
0
        static void Test(ADTreeContext context, ADTreeParser parser)
        {
            Console.WriteLine("Test Cases for ADTs");

            ADTreeExample1(context, parser);
            ADTreeExample2(context, parser);
            ADTreeExample3(context, parser);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var context = new ADTreeContext();
            var parser  = new ADTreeParser();

            Test(context, parser);

            Console.WriteLine("All test cases passed");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void ADTreeExample1(ADTreeContext context, ADTreeParser parser)
        {
            context.SetNodeOutcome("ForceDoor", false);
            var input = "LEAF,ForceDoor,100,120";
            Console.WriteLine("ADTree: " + input);
            var adt = parser.Parse(input);

            var expected_success = false;
            var actual_success = EvaluateSuccessAndPrint(adt, context);
            var expected_cost = 100;
            var actual_cost = EvaluateCostAndPrint(adt, context);
            var expected_duration = 120;
            var actual_duration = EvaluateDurationAndPrint(adt, context);

            Debug.Assert(expected_success == actual_success && expected_cost == actual_cost && expected_duration == actual_duration);
        }
Ejemplo n.º 4
0
        static void ADTreeExample2(ADTreeContext context, ADTreeParser parser)
        {
            context.SetNodeOutcome("BribeGuard", true);
            context.SetNodeOutcome("ForceDoor", false);
            var input = "AND,GrabTreasure,0,2 LEAF,BribeGuard,500,60 LEAF,ForceDoor,100,120";
            Console.WriteLine("ADTree: " + input);
            var adt = parser.Parse(input);

            var expected_success = false;
            var actual_success = EvaluateSuccessAndPrint(adt, context);
            var expected_cost = 600;
            var actual_cost = EvaluateCostAndPrint(adt, context);
            var expected_duration = 182;
            var actual_duration = EvaluateDurationAndPrint(adt, context);

            Debug.Assert(expected_success == actual_success && expected_cost == actual_cost && expected_duration == actual_duration);
        }
Ejemplo n.º 5
0
        static void ADTreeExample3(ADTreeContext context, ADTreeParser parser)
        {
            context.SetNodeOutcome("HelicopterExit", true);
            context.SetNodeOutcome("EmergencyExit", false);
            context.SetNodeOutcome("BribeGuard", true);
            context.SetNodeOutcome("ForceDoor", true);
            var input = "AND,TreasureStolen,0,0 OR,GetAway,0,0 LEAF,HelicopterExit,500,3 LEAF,EmergencyExit,0,10 AND,GrabTreasure,0,2 LEAF,BribeGuard,500,60 LEAF,ForceDoor,100,120";
            Console.WriteLine("ADTree: " + input);
            var adt = parser.Parse(input);

            var expected_success = true;
            var actual_success = EvaluateSuccessAndPrint(adt, context);
            var expected_cost = 600;
            var actual_cost = EvaluateCostAndPrint(adt, context);
            var expected_duration = 185;
            var actual_duration = EvaluateDurationAndPrint(adt, context);

            Debug.Assert(expected_success == actual_success && expected_cost == actual_cost && expected_duration == actual_duration);
        }