public void MoveAtk(CreatureBase creat) { Debug.Log("Moving or attacking: " + creat.name + ", in lane: " + creat.LaneIndex.ToString()); if (creat != null) { bool TargetInRange = false; List <CreatureBase> Targets = creat.ActiveLaneNode.laneManager.SearchRange((int)creat.Range, creat.ActiveLaneNode, this); foreach (CreatureBase creature in Targets) { if (creature.Owner != creat.Owner) { TargetInRange = true; AIResponse.Attack(creat); } } if (!TargetInRange) { int spaces = creat.ActiveLaneNode.laneManager.GetOpenNodes(creat.ActiveLaneNode, creat.RightFacing); if (spaces > AIResponse.Tokens) { spaces = AIResponse.Tokens; } if (spaces > 10) { spaces = 10; } AIResponse.Move(creat, spaces); } } }
private bool ShiftLane(int iLane) { List <CreatureBase> LaneCreatures = TournamentManager._instance.lanes[iLane].GetFriendliesInLane(this); //LogStack.Log("Shifting lane... creatures to shift = " + LaneCreatures.Count, LogLevel.Debug); if (iFriendlyCount >= iOffensiveThreshold) { LaneCreatures.Reverse(); } foreach (CreatureBase _creature in LaneCreatures) { //LogStack.Log("Current Creature = " + _creature.name + " Current ID = " + _creature.GetInstanceID(), LogLevel.Debug); if (AIResponse.Move(_creature, 1)) { //LogStack.Log("Current Creature = " + _creature.name + " Current ID = " + _creature.GetInstanceID() + " | Can move", LogLevel.Debug); if (TokenCheck() == false) { return(true); } } else if (iFriendlyCount > iOffensiveThreshold) { return(false); // Ensures front troops push for end. } } return(true); }
void AttemptMoveAttack(CreatureBase creature) { if (creature != null) { List <CreatureBase> searchTargetCreatures = creature.ActiveLaneNode.laneManager.SearchRange((int)creature.Range, creature.ActiveLaneNode, this); bool foundAttackTarget = false; foreach (CreatureBase _creature in searchTargetCreatures) { if (_creature.Owner != creature.Owner) //Found enemy creature in range { foundAttackTarget = true; AIResponse.Attack(creature); } } if (!foundAttackTarget) { int moveSpaces = creature.ActiveLaneNode.laneManager.GetOpenNodes(creature.ActiveLaneNode, _RightFacing); if (moveSpaces > AIResponse.Tokens) { moveSpaces = AIResponse.Tokens; } if (AIResponse.Move(creature, moveSpaces)) { LogStack.Log("Hal Move " + creature.GetInstanceID() + " - " + moveSpaces + " spaces - " + creature.LaneProgress, LogLevel.System); } } } }
public void Auto_Nearest(LaneManager[] Board) { Tuple <CreatureBase, int> nearestAndRange = GetNearestCreatureToNearestEnemy(Board); if (nearestAndRange != null && _Creatures.Count > 0) { LogStack.Log("I have a nearby unit", Logging.LogLevel.Color); List <CreatureBase> inRange = nearestAndRange.Item1.ActiveLaneNode.laneManager.SearchRange((int)nearestAndRange.Item1.Range, nearestAndRange.Item1.ActiveLaneNode, nearestAndRange.Item1.Owner); if (inRange.GetEnemies(nearestAndRange.Item1.Owner).Count > 0) { // if (AIResponse.Attack (nearestAndRange.Item1)) { if (!AIResponse.Attack(nearestAndRange.Item1, nearestAndRange.Item1.CreatureType == Spawnable.Bunny ? 1 : (int)GetNearestEnemy(Board).Health)) { // LogStack.Log ("Attack Validation check failed", Logging.LogLevel.System); } else { LogStack.Log("Nearby Unit Attacking", Logging.LogLevel.Color); } } else { LogStack.Log("Try Move " + nearestAndRange.Item1.GetInstanceID(), Logging.LogLevel.System); if (!AIResponse.Move(nearestAndRange.Item1)) { LogStack.Log("Move validation check failed", Logging.LogLevel.Color); } else { LogStack.Log("Nearby Unit Moving", Logging.LogLevel.Stack); } } } else if (Opponent._Creatures.Count > 0) { CreatureBase nearestCreature = GetNearestEnemy(Board); int nearestLane = 1; Spawnable spawnCreature = Spawnable.Bunny; if (nearestCreature != null) { spawnCreature = nearestCreature.LaneProgress < 6 ? Spawnable.Unicorn : Spawnable.Bunny; nearestLane = nearestCreature.ActiveLaneNode.laneManager.LaneNumber; } if (!AIResponse.Spawn(spawnCreature, nearestLane)) { LogStack.Log("Spawn Validation check failed", Logging.LogLevel.Stack); } } else if (Opponent._Creatures.Count == 0) { LogStack.Log("Wait till opponent does something", Logging.LogLevel.Stack); } }
public override void OnTick(IBoardState[] data) { boardState = (LaneManager[])data; for (int i = 1; i < (TournamentManager._instance.tokensPerRound == 1?3:6); i++) { FormPattern(LanePattern, i, boardState); } //for (int i = 0; i < 3; i++) //{ // AIResponse.Attack(boardState[i].GetFriendliesInLane(this).Count>0? boardState[i].GetFriendliesInLane(this)[0]:null); //} Auto_Nearest(boardState); CreatureBase nearest = null; for (int i = 0; i < 2; i++) { if (boardState[i].GetFriendliesInLane(this).Count != 0) { if (nearest != null) { if (boardState[i].GetFriendliesInLane(this) [0].LaneProgress > nearest.LaneProgress) { nearest = boardState[i].GetFriendliesInLane(this) [0]; } } else { nearest = boardState[i].GetFriendliesInLane(this) [0]; } } } if (AIResponse.Tokens > Threshhold) { AIResponse.Move(nearest, AIResponse.Tokens - Threshhold); } else { AIResponse.Move(nearest, 1); } for (int i = 0; i < AIResponse.Tokens; i++) { Auto_Nearest(boardState); } AIResponse.FinalizeResponse(); }
public IEnumerator MoveConfirm() { LogStack.Log("MoveConfirm () " + this.name, LogLevel.Stack); bool foundCreature = false; while (!foundCreature) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Debug.DrawLine(ray.origin, ray.direction * 500, Color.yellow, 1); if (Physics.Raycast(ray, out hit, 500, layerMask, QueryTriggerInteraction.Collide)) { CreatureBase creature = hit.transform.gameObject.GetComponent <CreatureBase> (); LogStack.Log("MoveConfirm () " + this.name + " | " + hit.transform.name, LogLevel.Stack); if (Input.GetMouseButtonDown(0) && creature?.Owner == this) { foundCreature = true; if (!AIResponse.Move(creature)) { LogStack.Log("Could Not Move Creature", LogLevel.Stack); OpenUI(); } else if (AIResponse.Tokens > 0) { LogStack.Log("Creature Moved", LogLevel.Stack); _uiAnimator.SetBool("Actions", false); yield return(null); OpenUI(); } else { LogStack.Log("Creature Moved", LogLevel.Stack); Finalise(); CloseUI(); } } else if (Input.GetMouseButtonDown(1)) { OpenUI(); foundCreature = true; } } yield return(null); } }
private void CheckIfClosestenemyIsInAttackingrange(CreatureBase allyWithMostProgress) { if (allyWithMostProgress == null) { return; } List <CreatureBase> searchTargetCreatures; searchTargetCreatures = allyWithMostProgress.ActiveLaneNode.laneManager.SearchRange( (int)allyWithMostProgress.Range, allyWithMostProgress.ActiveLaneNode, this); var hasTraget = false; foreach (CreatureBase creature in searchTargetCreatures) { if (creature.Owner != allyWithMostProgress.Owner) { //Found enemy creature in range hasTraget = true; AIResponse.Attack(allyWithMostProgress); } } if (hasTraget) { return; } int moveSpaces = allyWithMostProgress.ActiveLaneNode.laneManager.GetOpenNodes(allyWithMostProgress.ActiveLaneNode, _RightFacing); if (moveSpaces > AIResponse.Tokens) { moveSpaces = AIResponse.Tokens; } if (AIResponse.Move(allyWithMostProgress, moveSpaces)) { } else if (AIResponse.Move(_Creatures[_Creatures.Count - 1], 2)) { } }
private bool CheckIfCreatureCanFinish(CreatureBase creature) { if (creature == null) { return(false); } int remaining = creature.LaneProgress - 10; if (remaining > AIResponse.Tokens) { if (AIResponse.Move(creature, remaining)) { return(true); } } return(false); }
public override void OnTick(IBoardState[] data) { if (!B_Init) { Init(); } I_Round++; // ####### --- Performance Tracking (Learning) System --- ####### PrintPerformance(); UpdatePerformanceData(); CalculatePerformance(); if (I_Round % I_TurnsBetweenChecks == 0) { EvaluatePerformance(); } if (I_Round % I_TurnsBetweenChanges == 0) { Adapt(); } AttackedThisTurn.Clear(); UpdateLaneAdvantage(); iUnicornAttacks = 0; // ####### --- Advanced Response System --- ####### responseState = EResponseState.Basic; EmergencyCheck(); if (responseState == EResponseState.Emergency) { SpawnTroop(iResponseLane); responseState = EResponseState.Basic; } else // Ensures emergencies are priorities over point pushing and bunny rushing. { PointPushCheck(); if (responseState == EResponseState.PointPush) { LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Point Push Triggered - iSavingTokens =" + iSavingTokens, LogLevel.Debug); if (AIResponse.Tokens >= iSavingTokens) { AdvancedResponse(); } } else // Ensures point pushes are priorities over bunny rushing. { BunnyThreatCheck(); if (responseState == EResponseState.BunnyRush && AIResponse.Tokens > iSavingTokens) { iSavingTokens--; AdvancedResponse(); } } } LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Advanced Responses Complete - iSavingTokens =" + iSavingTokens, LogLevel.Debug); // ####### --- Basic Response System --- ####### // ####### --- Defense --- ####### int iCount = 0; int iCurrentThreshold = iDefTokenThreshold + iSavingTokens; while ((AIResponse.Tokens > iCurrentThreshold) && iCount < 5) { iCount++; if (TokenCheck() == false) { return; } int iWeakLane = GetDefendingLane(); LogStack.Log("Weak Lane = " + iWeakLane.ToString(), LogLevel.Debug); SpawnTroop(iWeakLane); } //if (TokenCheck() == false) return; // ####### --- Offense (A) --- ####### // ------- Stage One - Bunnies ------- List <CreatureBase> StageTroops = GetTroops(Spawnable.Bunny, true); // Front Bunnies. LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Front Bunnies Count =" + StageTroops.Count, LogLevel.Debug); AttackWithTroops(StageTroops); StageTroops.Clear(); // Reset for Second Stage // ------- Stage Two - Unicorns ------- StageTroops = GetTroops(Spawnable.Unicorn); // All Unicorns. AttackWithTroops(StageTroops); StageTroops.Clear(); // ####### --- Offense (M) --- ####### ------------------------------------------------------------------------ TODO - Change to use all available extra tokens? Use dedicated "Push" and "Push Support" lanes. if (TokenCheck() == false) { return; } iCurrentThreshold = iAttackTokenThreshold + iSavingTokens; int iAvalableTokens = AIResponse.Tokens - iCurrentThreshold; if (iAvalableTokens > 0) { int iLane = UnityEngine.Random.Range(1, 3); List <CreatureBase> AvailableLaneTroops = TournamentManager._instance.lanes[iLane].GetFriendliesInLane(this); if (AvailableLaneTroops.Count > 0) { AIResponse.Move(AvailableLaneTroops[0], iAvalableTokens); } } AIResponse.FinalizeResponse(); }
private void AdvancedResponse() { AIResponse.Move(responseCreature, iSavingTokens); iSavingTokens = 0; }