public AIDodgeNode() { // variable declarations AIPositionDecisionNode dodgeNode1; AISetVelocityNode dodgeLeftNode; AISetVelocityNode dodgeRightNode; AIPositionDecisionNode dodgeNode2; AIJumpNode jumpDodgeNode; double[] v; // Decide which direction horizontally to move dodgeNode1 = new AIPositionDecisionNode(3, 1, 0, 0); { // If it's on the left, go right v = new double[2]; v[0] = 10000; v[1] = 0; dodgeLeftNode = new AISetVelocityNode(v); dodgeNode1.setLeftChild(dodgeLeftNode); } // else { // If it's on the right, go left v = new double[2]; v[0] = -10000; v[1] = 0; dodgeRightNode = new AISetVelocityNode(v); dodgeNode1.setRightChild(dodgeRightNode); } // check whether the incoming projectile is too high dodgeNode2 = new AIPositionDecisionNode(3, 0, 1, 20); dodgeLeftNode.setNextNode(dodgeNode2); dodgeRightNode.setNextNode(dodgeNode2); // If the projectile isn't too high, then jump and go past it { // Jump jumpDodgeNode = new AIJumpNode(); dodgeNode2.setLeftChild(jumpDodgeNode); } this.setFirstNode(dodgeNode1); }
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; } }