public AiKillingLogic(AiBase aiBase) { this.aiBase = aiBase; rdyToShoot = false; frameToShoot = 15; targetObject = aiBase.gameObject; }
public void linkAI(AiBase playerAI, int index) { if (playerAI == null) { Debug.Log("Clearing AI Slot " + index.ToString()); } //don't forget to generate their networks when we do this! switch (index) { case 1: ai1 = playerAI; break; case 2: ai2 = playerAI; break; case 3: ai3 = playerAI; break; case 4: ai4 = playerAI; break; } if (playerAI != null) { playerAI.aiBroodmother = this; } }
public bool aiPickup2 = false; //used to initiate an item pickup protected virtual void Awake() { physics = GetComponent <PlayerPhysics>(); animator = GetComponent <CustomAnimator>(); box = GetComponent <BoxCollider2D>(); ai = GetComponent <AiBase>(); passives = new List <Item>(); }
public AiAvoidBulletLogic(AiBase aiBase) { this.aiBase = aiBase; bulletMask = aiBase.bulletMask; aiMovementLogic = aiBase.aiMovementLogic; characterColliderWidth = aiBase.characterColliderWidth; characterColliderHeight = aiBase.characterColliderHeight; }
private float e = 0.1f; //odchylka #endregion Fields #region Constructors //public AiAvoidBulletLogic aiAvoidBulletLogic; public AiMovementLogic(AiBase aiBase) { this.aiBase = aiBase; characterColliderWidth = aiBase.characterColliderWidth; characterColliderHeight = aiBase.characterColliderHeight; collider = aiBase.GetComponent<Collider2D>(); walkingFront = new List<Vector2>(); barrierMask = aiBase.barrierMask; notproofBarrierMask = 1 << 14; }
//public AiAvoidBulletLogic aiAvoidBulletLogic; public AiMovementLogic(AiBase aiBase) { this.aiBase = aiBase; characterColliderWidth = aiBase.characterColliderWidth; characterColliderHeight = aiBase.characterColliderHeight; collider = aiBase.GetComponent <Collider2D>(); walkingFront = new List <Vector2>(); barrierMask = aiBase.barrierMask; notproofBarrierMask = 1 << 14; }
public void loadNetwork(AiBase ai) { ai.preload(inputLayerCount, layer1Count, layer2Count, outputLayerCount); double[] inputLayer1 = new double[inputLayerCount * layer1Count]; double[] layer1Layer2 = new double[layer2Count * layer1Count]; double[] layer2Output = new double[layer2Count * outputLayerCount]; inputToLayer1Genes[currentGenome - 1].CopyTo(inputLayer1); layer1ToLayer2Genes[currentGenome - 1].CopyTo(layer1Layer2); layer2ToOutputGenes[currentGenome - 1].CopyTo(layer2Output); ai.createNetwork(inputLayer1, layer1Layer2, layer2Output); }
//calculate what risk this target AI is double rateDanger(AiBase target) { if (target == null) { return(0); //can't gauge a non-existent target } double total = 300; //start it out here if (target.ourPlayer != null && ourPlayer != null) { //add potency if two items if (target.ourPlayer.active1 != null) { total += 100; } if (target.ourPlayer.active2 != null) { total += 100; } //add proximity value, small total += Math.Abs(36 - (target.ourPlayer.transform.position.x - ourPlayer.transform.position.x)); total += Math.Abs(24 - (target.ourPlayer.transform.position.y - ourPlayer.transform.position.y)) / 2; total *= Math.Pow(10 * target.ourPlayer.currentHealth / target.ourPlayer.maxHealth, 2); //multiply it by their current health, squared total *= 1 + (target.ourPlayer.currentMagic / target.ourPlayer.maxMagic); //factor in mana //check for invincibility if (target.ourPlayer.invincible) { total = 999999; } //check us for invincibility if (ourPlayer.invincible) { total = 0; } } return(total); }
public AiWeaponLogic(AiBase aiBase) { this.aiBase = aiBase; itemWeapons = new List <GameObject>(); }
public AiActionLogic(AiBase aiBase) { this.aiBase = aiBase; }
public void ChangeBase(AiBase obj) { aiBaseObj = obj; }
public AiPowerUpLogic(AiBase aiBase) { this.aiBase = aiBase; itemMask = aiBase.itemMask; itemPowerUps = new List <GameObject>(); }
public void SwapAIFunction(AiBase aiBaseObj) { aiBrainObj.aiBaseObj = aiBaseObj; }
public void ChangeBase(AiBase b) { Base = b; }
void makeDecisions() { if (ourPlayer == null) { return; } AiBase playerA = null; AiBase playerB = null; AiBase playerC = null; if (aiBroodmother.ai1 != this && aiBroodmother.ai1 != null) { if (playerA == null) { playerA = aiBroodmother.ai1; } else if (playerB == null) { playerB = aiBroodmother.ai1; } else { playerC = aiBroodmother.ai1; } } if (aiBroodmother.ai2 != this && aiBroodmother.ai2 != null) { if (playerA == null) { playerA = aiBroodmother.ai2; } else if (playerB == null) { playerB = aiBroodmother.ai2; } else { playerC = aiBroodmother.ai2; } } if (aiBroodmother.ai3 != this && aiBroodmother.ai3 != null) { if (playerA == null) { playerA = aiBroodmother.ai3; } else if (playerB == null) { playerB = aiBroodmother.ai3; } else { playerC = aiBroodmother.ai3; } } if (aiBroodmother.ai4 != this && aiBroodmother.ai4 != null) { if (playerA == null) { playerA = aiBroodmother.ai4; } else if (playerB == null) { playerB = aiBroodmother.ai4; } else { playerC = aiBroodmother.ai4; } } ourPlayer.aiAttack = false; ourPlayer.aiSpecial = false; //character specific attack protocols if (ourPlayer.id == 1) //hero { //check if enemy is close enough to melee double meleeRadius = 2.0; //adjust if (playerA != null && playerA.ourPlayer != null) { double dist = Math.Pow(playerA.ourPlayer.transform.position.x - ourPlayer.transform.position.x, 2) + Math.Pow(playerA.ourPlayer.transform.position.y - ourPlayer.transform.position.y, 2); if (dist <= meleeRadius) { ourPlayer.aiAttack = true; } } if (playerB != null && playerB.ourPlayer != null) { double dist = Math.Pow(playerB.ourPlayer.transform.position.x - ourPlayer.transform.position.x, 2) + Math.Pow(playerB.ourPlayer.transform.position.y - ourPlayer.transform.position.y, 2); if (dist <= meleeRadius) { ourPlayer.aiAttack = true; } } if (playerC != null && playerC.ourPlayer != null) { double dist = Math.Pow(playerC.ourPlayer.transform.position.x - ourPlayer.transform.position.x, 2) + Math.Pow(playerC.ourPlayer.transform.position.y - ourPlayer.transform.position.y, 2); if (dist <= meleeRadius) { ourPlayer.aiAttack = true; } } //if we didn't use a melee, use a ranged if they're within a distance and range if (!ourPlayer.aiAttack) { double rangedWidth = 6.0; //adjust double rangedHeight = 1.5; //adjust if (playerA != null && playerA.ourPlayer != null) { if (Math.Pow(playerA.ourPlayer.transform.position.x - ourPlayer.transform.position.x, 2) <= rangedWidth && Math.Pow(playerA.ourPlayer.transform.position.y - ourPlayer.transform.position.y, 2) <= rangedHeight) { ourPlayer.aiSpecial = true; } } if (playerB != null && playerB.ourPlayer != null) { if (Math.Pow(playerB.ourPlayer.transform.position.x - ourPlayer.transform.position.x, 2) <= rangedWidth && Math.Pow(playerB.ourPlayer.transform.position.y - ourPlayer.transform.position.y, 2) <= rangedHeight) { ourPlayer.aiSpecial = true; } } if (playerC != null && playerC.ourPlayer != null) { if (Math.Pow(playerC.ourPlayer.transform.position.x - ourPlayer.transform.position.x, 2) <= rangedWidth && Math.Pow(playerC.ourPlayer.transform.position.y - ourPlayer.transform.position.y, 2) <= rangedHeight) { ourPlayer.aiSpecial = true; } } if (ourPlayer.aiSpecial && ourPlayer.specialChargeTime >= ourPlayer.specialChargeTimeMax) { ourPlayer.aiSpecial = false; } } } //determine where we want to go //find highest danger rating double ourRating = rateDanger(this); AiBase highestDanger = this; double highestDangerRating = ourRating; //find lowest danger rating AiBase lowestDanger = this; double lowestDangerRating = ourRating; //now check all other players to see whom the highest and lowest is double tempRating = ourRating; int living = 1; if (playerA != null) { tempRating = rateDanger(playerA); if (tempRating > highestDangerRating) { highestDanger = playerA; highestDangerRating = tempRating; } else if (tempRating < lowestDangerRating) { lowestDanger = playerA; lowestDangerRating = tempRating; } //default to first AI found to be strongest else { highestDanger = playerA; highestDangerRating = tempRating; } if (playerA.ourPlayer != null) { if (playerA.ourPlayer.currentHealth > 0) { living++; } } } if (playerB != null) { tempRating = rateDanger(playerB); if (tempRating > highestDangerRating) { highestDanger = playerB; highestDangerRating = tempRating; } else if (tempRating < lowestDangerRating) { lowestDanger = playerB; lowestDangerRating = tempRating; } if (playerB.ourPlayer != null) { if (playerB.ourPlayer.currentHealth > 0) { living++; } } } if (playerC != null) { tempRating = rateDanger(playerC); if (tempRating > highestDangerRating) { highestDanger = playerC; highestDangerRating = tempRating; } else if (tempRating < lowestDangerRating) { lowestDanger = playerC; lowestDangerRating = tempRating; } //default to last AI found to be weakest else { lowestDanger = playerC; lowestDangerRating = tempRating; } if (playerC.ourPlayer != null) { if (playerC.ourPlayer.currentHealth > 0) { living++; } } } double oldDesiredX = desiredX; double oldDesiredY = desiredY; if (lowestDanger.ourPlayer != null && highestDanger.ourPlayer != null) { //now check if the we are not the weakest for aggressive behavior if (ourRating >= highestDangerRating / 2 || lowestDanger != this) { //pick on the weakest desiredX = lowestDanger.ourPlayer.transform.position.x; desiredY = lowestDanger.ourPlayer.transform.position.y; } //if just us, fite em else if (living == 2) { //believe in me who believes in you (ur gona get rekt son) desiredX = highestDanger.ourPlayer.transform.position.x; desiredY = highestDanger.ourPlayer.transform.position.y; } //now check if the we are the lowest for evasive behavior, try to be at the opposite position of our aggressor else if (lowestDanger == this) { //evasive maneuver alpha gamma desiredX = 36 - highestDanger.ourPlayer.transform.position.x; desiredY = 24 - highestDanger.ourPlayer.transform.position.y; } } //reset timer if far enough of a new desired position if (Math.Pow(oldDesiredX - desiredX, 2) + Math.Pow(oldDesiredY - desiredY, 2) > 2) { ticksToDestination = 0; } if (ourPlayer.active1 == null) { ourPlayer.aiPickup1 = true; } else if (ourPlayer.active2 == null) { ourPlayer.aiPickup2 = true; } }
void pollInputs() { if (ourPlayer == null) { return; //don't run without a player } Node currNode = null; //Time since last jump (jump cooldown) //Other player data //Distance from us (dx, dy) //later (low priority) //passive ids //grab other opponent data AiBase playerA = null; AiBase playerB = null; AiBase playerC = null; if (aiBroodmother.ai1 != this && aiBroodmother.ai1 != null) { if (playerA == null) { playerA = aiBroodmother.ai1; } else if (playerB == null) { playerB = aiBroodmother.ai1; } else { playerC = aiBroodmother.ai1; } } if (aiBroodmother.ai2 != this && aiBroodmother.ai2 != null) { if (playerA == null) { playerA = aiBroodmother.ai2; } else if (playerB == null) { playerB = aiBroodmother.ai2; } else { playerC = aiBroodmother.ai2; } } if (aiBroodmother.ai3 != this && aiBroodmother.ai3 != null) { if (playerA == null) { playerA = aiBroodmother.ai3; } else if (playerB == null) { playerB = aiBroodmother.ai3; } else { playerC = aiBroodmother.ai3; } } if (aiBroodmother.ai4 != this && aiBroodmother.ai4 != null) { if (playerA == null) { playerA = aiBroodmother.ai4; } else if (playerB == null) { playerB = aiBroodmother.ai4; } else { playerC = aiBroodmother.ai4; } } //get our x and y currNode = getNode(nodeLayerInput, 0); if (currNode != null) { currNode.value = ourPlayer.transform.position.x; } currNode = getNode(nodeLayerInput, 1); if (currNode != null) { currNode.value = ourPlayer.transform.position.y; } currNode = getNode(nodeLayerInput, 2); if (currNode != null) { currNode.value = rateDanger(playerA); } currNode = getNode(nodeLayerInput, 3); if (currNode != null) { currNode.value = rateDanger(playerB); } currNode = getNode(nodeLayerInput, 4); if (currNode != null) { currNode.value = rateDanger(playerC); } currNode = getNode(nodeLayerInput, 5); if (currNode != null) { currNode.value = 1; //character ID, change later } currNode = getNode(nodeLayerInput, 6); if (currNode != null) { if (ourPlayer.active1 != null) { currNode.value = ourPlayer.active1.id * 10; //Item 1 ID } else { currNode.value = 0; } } currNode = getNode(nodeLayerInput, 7); if (currNode != null) { if (ourPlayer.active2 != null) { currNode.value = ourPlayer.active2.id * 10; //Item 2 ID } else { currNode.value = 0; } } currNode = getNode(nodeLayerInput, 8); if (currNode != null) { currNode.value = ourPlayer.active1CooldownCurrent; //Item 1 CD } currNode = getNode(nodeLayerInput, 9); if (currNode != null) { currNode.value = ourPlayer.active2CooldownCurrent; //Item 2 CD } //direction currNode = getNode(nodeLayerInput, 10); if (currNode != null) { currNode.value = ourPlayer.direction; } //passives here //jump cd currNode = getNode(nodeLayerInput, 11); if (currNode != null) { currNode.value = ourPlayer.extraJumpsCurrent; } //desired position currNode = getNode(nodeLayerInput, 12); if (currNode != null) { currNode.value = desiredX; } currNode = getNode(nodeLayerInput, 13); if (currNode != null) { currNode.value = desiredY; } //score for distance from target if (Math.Abs(desiredX - ourPlayer.transform.position.x) + Math.Abs(desiredY - ourPlayer.transform.position.y) > 2) { ticksToDestination++; } else { ticksToDestination = 0; } double scale = 5 - ticksToDestination / 20; score += scale * Math.Pow((36 - (desiredX - ourPlayer.transform.position.x)) / 16, 2) / 2; score += scale * Math.Pow((24 - (desiredY - ourPlayer.transform.position.y)) / 4, 2) / 2; }
public AiPriorityLogic(AiBase aiBase) { this.aiBase = aiBase; }
public bool aiPickup2 = false; //used to initiate an item pickup protected virtual void Start() { physics = GetComponent <PlayerPhysics>(); animator = GetComponent <CustomAnimator>(); box = GetComponent <BoxCollider2D>(); ai = GetComponent <AiBase>(); passives = new List <Item>(); if (inputType == "Keyboard") { horizontal = "KB Horizontal"; vertical = "KB Vertical"; jump = "KB Jump"; attack = "KB Attack"; special = "KB Special"; item1 = "KB Item1"; item2 = "KB Item2"; grab1 = "KB Grab1"; grab2 = "KB Grab2"; pause = "KB Pause"; select = "KB Select"; } else if (inputType == "Joy1") { horizontal = "Joy1 Horizontal"; vertical = "Joy1 Vertical"; jump = "Joy1 Jump"; attack = "Joy1 Attack"; special = "Joy1 Special"; item1 = "Joy1 Item1"; item2 = "Joy1 Item2"; grab1 = "Joy1 Grab1"; grab2 = "Joy1 Grab2"; pause = "Joy1 Pause"; select = "Joy1 Select"; } else if (inputType == "Joy2") { horizontal = "Joy2 Horizontal"; vertical = "Joy2 Vertical"; jump = "Joy2 Jump"; attack = "Joy2 Attack"; special = "Joy2 Special"; item1 = "Joy2 Item1"; item2 = "Joy2 Item2"; grab1 = "Joy2 Grab1"; grab2 = "Joy2 Grab2"; pause = "Joy2 Pause"; select = "Joy2 Select"; } else if (inputType == "Joy3") { horizontal = "Joy3 Horizontal"; vertical = "Joy3 Vertical"; jump = "Joy3 Jump"; attack = "Joy3 Attack"; special = "Joy3 Special"; item1 = "Joy3 Item1"; item2 = "Joy3 Item2"; grab1 = "Joy3 Grab1"; grab2 = "Joy3 Grab2"; pause = "Joy3 Pause"; select = "Joy3 Select"; } else if (inputType == "Joy4") { horizontal = "Joy4 Horizontal"; vertical = "Joy4 Vertical"; jump = "Joy4 Jump"; attack = "Joy4 Attack"; special = "Joy4 Special"; item1 = "Joy4 Item1"; item2 = "Joy4 Item2"; grab1 = "Joy4 Grab1"; grab2 = "Joy4 Grab2"; pause = "Joy4 Pause"; select = "Joy4 Select"; } else if (inputType == "AI") { ai.ourPlayer = this;//this activate the AI, essentially aiEnabled = true; } //grab our overhead display GetComponent <PlayerOverhead>().connectedPlayer = this; }
public void ChangeBase(AiBase obj) { aiBaseObj = obj; //aibase is = to incomming obj. }
public void ChangeBase(AiBase b) { aiBaseObj = b; }
public AiMapLogic(AiBase aiBase) { this.aiBase = aiBase; }
public void ChangeBase(AiBase ai) { Brain.Base = ai; }