Exemplo n.º 1
0
    public AIChaseNode()
    {
        // move closer
        AITargetDecisionNode leftTargetNode = new AITargetDecisionNode(-1, 0, 1000000);

        // if the user is on the left, go left
        double[]          v           = new double[2]; v[0] = -10000; v[1] = 0;
        AISetVelocityNode goLeftNode1 = new AISetVelocityNode(v);

        leftTargetNode.setLeftChild(goLeftNode1);
        // else
        // if the user is on the left, go right
        v = new double[2]; v[0] = 10000; v[1] = 0;
        AISetVelocityNode goRightNode1 = new AISetVelocityNode(v);

        leftTargetNode.setRightChild(goRightNode1);
        // since we're not in range, switch to a new weapon if it's been out of range for a while
        AITickDecisionNode weaponSwitchCounter = new AITickDecisionNode(1);

        goLeftNode1.setNextNode(weaponSwitchCounter);
        goRightNode1.setNextNode(weaponSwitchCounter);
        AISelectWeaponNode selectWeaponNode1 = new AISelectWeaponNode();

        weaponSwitchCounter.setLeftChild(selectWeaponNode1);
        this.setFirstNode(leftTargetNode);
    }
Exemplo n.º 2
0
    public AI(int intelligence)
    {
        this.randomGenerator = new Random();
        if (intelligence == 0)
        {
            // every once in a while, change direction
            AITickDecisionNode turnNode1 = new AITickDecisionNode(0.005);
            // figure out which direction to turn
            AITickDecisionNode toggleNode1 = new AITickDecisionNode(0.5);
            turnNode1.setLeftChild(toggleNode1);
            // turn left
            double[] leftVelocity = new double[2];
            leftVelocity[0] = -10000; leftVelocity[1] = 0;
            AISetVelocityNode moveLeftNode = new AISetVelocityNode(leftVelocity);
            toggleNode1.setLeftChild(moveLeftNode);
            // turn right
            double[] rightVelocity = new double[2];
            rightVelocity[0] = 10000; rightVelocity[1] = 0;
            AISetVelocityNode moveRightNode = new AISetVelocityNode(rightVelocity);
            toggleNode1.setRightChild(moveRightNode);

            // set the starting node correctly
            this.firstNeuron = turnNode1;
        }
        else    // intelligence > 0
        {
            // release the trigger
            AIFireNode fireNode1 = new AIFireNode(false);

            // switch to a weapon that has ammo
            AISmartSwitchNode switchNode1 = new AISmartSwitchNode();
            fireNode1.setNextNode(switchNode1);

            // decide whether it's time to do another collision test
            AIRandomDecisionNode scanNode1 = new AIRandomDecisionNode(0.3);
            switchNode1.setNextNode(scanNode1);
            // if we get here then it is time to do another collision test
            // check whether the target is in range and shoot if it is
            AITargetDecisionNode targetNode1 = new AITargetDecisionNode(0, 0, 0);
            scanNode1.setLeftChild(targetNode1);
            // if we get here then we're in range
            // So, fire
            AIFireNode fireNode2 = new AIFireNode(true);
            targetNode1.setLeftChild(fireNode2);
            // else
            // if we get here then we're not in range
            // So, chase
            AIChaseNode chaseNode1 = new AIChaseNode();
            targetNode1.setRightChild(chaseNode1);

            // Now check if there is an incoming projectile
            AICollisionDecisionNode dodgeNode1 = new AICollisionDecisionNode(3, 1, 0, 0.3);
            scanNode1.setRightChild(dodgeNode1);
            fireNode2.setNextNode(dodgeNode1);
            chaseNode1.setNextNode(dodgeNode1);
            // if the projectile is close in time, check whether it will miss laterally
            AICollisionDecisionNode dodgeNode2 = new AICollisionDecisionNode(3, 0, 1, 0);
            dodgeNode1.setLeftChild(dodgeNode2);
            AIDodgeNode dodgeNode3 = new AIDodgeNode();
            dodgeNode2.setLeftChild(dodgeNode3);
            {
                // If we're about to bump into a wall, jump
                AICollisionDecisionNode obstacleDecisionNode1 = new AICollisionDecisionNode(1, 1, 0, 0.01);
                dodgeNode1.setRightChild(obstacleDecisionNode1);
                dodgeNode2.setRightChild(obstacleDecisionNode1);
                AICollisionDecisionNode obstacleDecisionNode2 = new AICollisionDecisionNode(1, 0, 1, 0.01);
                obstacleDecisionNode1.setLeftChild(obstacleDecisionNode2);
                AIPositionDecisionNode obstacleDecisionNode3 = new AIPositionDecisionNode(1, 0, -1, 40);
                obstacleDecisionNode2.setLeftChild(obstacleDecisionNode3);
                AIJumpNode wallJumpNode = new AIJumpNode();
                obstacleDecisionNode3.setLeftChild(wallJumpNode);
                // If jumping would help hit the target, then jump
                AITickDecisionNode jumpCheckNode1 = new AITickDecisionNode(0.01);
                obstacleDecisionNode1.setRightChild(jumpCheckNode1);
                obstacleDecisionNode2.setRightChild(jumpCheckNode1);
                obstacleDecisionNode3.setRightChild(jumpCheckNode1);
                //AIPositionDecisionNode jumpCheckNode2 = new AIPositionDecisionNode(2, 0, 1, 250);
                //jumpCheckNode1.setRightChild(jumpCheckNode2);
                AITargetDecisionNode jumpCheckNode2 = new AITargetDecisionNode(0, 1, 10000);
                jumpCheckNode1.setLeftChild(jumpCheckNode2);
                AIJumpNode targetJumpNode = new AIJumpNode();
                jumpCheckNode2.setLeftChild(targetJumpNode);
            }

            // remember the decision tree
            this.firstNeuron = fireNode1;
            fireNode1.setBrain(this);
            //this.firstNeuron = fireNode1;
        }
    }