Exemplo n.º 1
0
        public ResultNode GenerateResultNode()
        {
            Array      values = Enum.GetValues(typeof(Move));
            ResultNode Result = new ResultNode((Move)values.GetValue(R.Next(0, values.Length)));

            //Console.WriteLine("Result: {0}", Result.Move.ToString());
            return(Result);
        }
Exemplo n.º 2
0
        public static DecisionTree CreateEnemy(CryptoRandom r, State state, List <Test> tests)
        {
            ResultNode node3 = new ResultNode {
                Key = 3, Move = Move.LONG_MOVE_FORWARD
            };
            ResultNode node5 = new ResultNode {
                Key = 5, Move = Move.LONG_MOVE_FORWARD
            };
            ResultNode node6 = new ResultNode {
                Key = 6, Move = Move.ATTACK_ROCKET
            };
            ResultNode node9 = new ResultNode {
                Key = 9, Move = Move.SHORT_MOVE_FORWARD_THEN_ATTACK
            };
            ResultNode node10 = new ResultNode {
                Key = 10, Move = Move.SHORT_MOVE_FORWARD
            };
            ResultNode node11 = new ResultNode {
                Key = 11, Move = Move.ATTACK_FAR
            };
            DecisionNode node4 = new DecisionNode {
                Key = 4, Decision = new Decision {
                    Statistic = "enemyIsInDanger", Param = 0, Test = tests[0]
                }, leftChild = node5, rightChild = node6
            };
            DecisionNode node8 = new DecisionNode {
                Key = 8, Decision = new Decision {
                    Statistic = "distance", Param = 4, Test = tests[2]
                }, leftChild = node9, rightChild = node10
            };
            DecisionNode node2 = new DecisionNode {
                Key = 2, Decision = new Decision {
                    Statistic = "enemyIsDefending", Param = 0, Test = tests[0]
                }, leftChild = node3, rightChild = node4
            };
            DecisionNode node7 = new DecisionNode {
                Key = 7, Decision = new Decision {
                    Statistic = "enemyIsInDanger", Param = 0, Test = tests[0]
                }, leftChild = node8, rightChild = node11
            };
            DecisionNode node1 = new DecisionNode {
                Key = 1, Decision = new Decision {
                    Statistic = "distance", Param = 6, Test = tests[0]
                }, leftChild = node2, rightChild = node7
            };

            return(new DecisionTree {
                R = r, elementCount = 11, fitness = 0, root = node1
            });
        }
Exemplo n.º 3
0
        public static void Mutation(DecisionTree individual, CryptoRandom r, State state, State maxValues, List <Test> tests)
        {
            int  node         = r.Next(1, individual.elementCount + 1);
            Node nodeToMutate = individual.Find(node, individual.root);

            if (nodeToMutate is DecisionNode)
            {
                DecisionNode newNode = individual.generateDecisionNode(state, maxValues, tests);
                ((DecisionNode)nodeToMutate).Decision = newNode.Decision;
            }
            else if (nodeToMutate is ResultNode)
            {
                ResultNode newNode = individual.GenerateResultNode();
                ((ResultNode)nodeToMutate).Move = newNode.Move;
            }
        }