//returns your nearest creature and how far away it is // retuns null if no creature in the lane public Tuple <CreatureBase, int> GetMyNearestCreature(CreatureBase OpponentCreature, LaneManager[] Board) { if (OpponentCreature == null) { return(null); } List <CreatureBase> CreaturesInLane = OpponentCreature.ActiveLaneNode.laneManager.GetFriendliesInLane(this); CreatureBase NearestCreature = null; if (CreaturesInLane.Count > 0) { NearestCreature = OpponentCreature.ActiveLaneNode.laneManager.GetFriendliesInLane(this) [0]; } else { NearestCreature = null; } LogStack.Log("GetMyNearestCreature() " + NearestCreature, Logging.LogLevel.System); if (NearestCreature == null) { return(null); } return(Tuple.Create(NearestCreature, Mathf.Abs(NearestCreature.LaneIndex - OpponentCreature.LaneIndex))); }
public CreatureBase[] GetNearestEnemies(LaneManager[] Board) { LogStack.Log("GetNearestEnemies()", Logging.LogLevel.Color); List <CreatureBase> nearestCreatures = new List <CreatureBase> (); foreach (LaneManager lane in Board) { LaneNode startNode = lane.GetFirstLaneNode(this); List <CreatureBase> tempCreatures = lane.GetEnemiesInLane(this); if (tempCreatures.Count > 0) { nearestCreatures.Add(tempCreatures[0]); } } LogStack.Log("Three nearest enemies: " + nearestCreatures.Count, Logging.LogLevel.Debug); // Func<int, int, bool> FindNearestOfTwoDependatOnPlayerSide = (x, y) => _PlayerNumber == 1 ? x > y : x < y; if (_PlayerNumber == 1) { nearestCreatures.Sort((a, b) => a.LaneIndex.CompareTo(b.LaneIndex)); // ascending sort } else { nearestCreatures.Sort((a, b) => - 1 * a.LaneIndex.CompareTo(b.LaneIndex)); // descending sort } return(nearestCreatures.ToArray()); }
public bool Attack(CreatureBase creature) { if (creature == null) { return(false); } List <CreatureBase> inRange = creature.ActiveLaneNode.laneManager.SearchRange((int)creature.Range, creature.ActiveLaneNode, creature.Owner); if (inRange.GetEnemies(creature.Owner).Count > 0 && inRange.GetEnemies(creature.Owner) [0].Health > 0) { if (!SpendToken()) { return(false); } // LogStack.Log ("Response | Attack", LogLevel.Stack); IResponse response = new ActionResponse(creature, 0, logicBase, ResponseActionType.Attack, creature.ActiveLaneNode); if (!ResponseChain.Contains(response)) { ResponseChain.Add(response); } else { LogStack.Log("##### Duplicate Attack Response", LogLevel.System); RefundToken(); return(false); } return(true); } else { return(false); } }
/// <summary> /// Spawns a creature // detailed instructions /// </summary> /// <param name="spawnable">the creature</param> public bool Spawn(Spawnable creature, int lane) { LaneNode node = TournamentManager._instance.lanes[lane - 1].GetFirstLaneNode(logicBase); IResponse response = new ActionResponse(creature == Spawnable.Bunny ? TournamentManager._instance.bunnyPrefab.GetComponent <CreatureBase> () : TournamentManager._instance.unicornPrefab.GetComponent <CreatureBase> (), lane, logicBase, ResponseActionType.Spawn, node); /* fail the Spawn */ // LogStack.Log ("Tokens: " + tokens, LogLevel.Debug); // LogStack.Log ("Node Creature Count: " + (node.activeCreature != null ? 1 : 0), LogLevel.System); if (lane > TournamentManager._instance.lanes.Count || node.activeCreature != null || spawnNodesTaken.Contains(node)) { // LogStack.Log ("Response | Spawn Failed Lane: " + lane, LogLevel.Stack); return(false); } else { if (!SpendToken()) { return(false); } // LogStack.Log ("Response | Spawn Success Lane: " + lane, LogLevel.Stack); spawnNodesTaken.Add(node); if (!ResponseChain.Contains(response)) { ResponseChain.Add(response); } else { LogStack.Log("##### Duplicate Spawn Response", LogLevel.System); RefundToken(); } return(true); } }
private void BunnyThreatCheck() { // TODO LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% BunnyThreatCheck(1) %%%%%%%%%%%%%% - iSavingTokens = " + iSavingTokens, LogLevel.Debug); List <CreatureBase> ThreatenedBunnies = GetTroops(Spawnable.Bunny, true); int iMaxThreatDist = 99; foreach (CreatureBase bunny in ThreatenedBunnies) { if (bunny.Health == 1) { continue; } int iTargetDist = -1; CreatureBase Target = GetClosestEnemy(bunny, out iTargetDist); if (Target != null && Target.CreatureType == Spawnable.Unicorn && iMaxThreatDist >= iTargetDist && iTargetDist <= bunny.Health + 1) { LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% BunnyThreatCheck(2) %%%%%%%%%%%%%% - FoundTarget = " + Target.name + " @ " + iTargetDist + " Tiles Away", LogLevel.Debug); responseCreature = bunny; iMaxThreatDist = iTargetDist; } } if (iMaxThreatDist != 99) { iSavingTokens = iMaxThreatDist + 1; responseState = EResponseState.BunnyRush; LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% BunnyThreatCheck(3) %%%%%%%%%%%%%% - iSavingTokens = " + iSavingTokens, LogLevel.Debug); } LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% BunnyThreatCheck(4) %%%%%%%%%%%%%% - iSavingTokens = " + iSavingTokens, LogLevel.Debug); }
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 Log(LogMessage message) { LogStack.Push(message); _listener?.OnLog(message); if (message.Exception != null) { } }
private void Add(cLogItem log) { LogStack.Add(log); if (_isSaveToFile) { sw.WriteLine(ToXML(log)); } }
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 void Attack() { if (health > 0) { LogStack.Log(this.name + " attacking", LogLevel.Stack); animator.SetBool("Attack", true); animator.SetTrigger("AttackInit"); CameraShake._CameraShake.DoCameraShake(0.1f, rightFacing ? 0.5f : -0.5f); KillInRange(); } }
public void Win() { if ((activeLaneNode == lane.endNode && rightFacing) || (activeLaneNode == lane.startNode && !rightFacing) && dead != true) { //Made it to the end LogStack.Log(gameObject.name + " made it to the end. 1 point to " + owner.name, LogLevel.Stack); TournamentManager._instance.ScoreUpdate(this); animator.SetBool("Win", true); Die(); } }
public void Damage(CreatureBase killer, float amount) { LogStack.Log(transform.name + " killed by Player " + (killer == TournamentManager._instance.P1 ? "1" : "2") + "'s " + killer.CreatureType, LogLevel.Stack); health -= amount; uiHealth.SetHealth(health); if (health <= 0) { Die(); // shouldDie = true; } }
public void KillInRange() { LogStack.Log("--- " + owner + "searchInRange ---", LogLevel.Stack); foreach (var creature in lane.SearchRange((int)range, activeLaneNode, owner)) { if (creature.Owner != owner) { LogStack.Log(creature + " in range. Kill it.", LogLevel.Stack); creature.Damage(this, damageAmount); break; } } }
public int GetNearestEnemyNodesAwayFrom(CreatureBase myCreature) { LogStack.Log("GetNearestEnemyNodesAwayFrom()", Logging.LogLevel.Color); CreatureBase creature = GetNearestEnemyTo(myCreature); if (creature != null) { return(Mathf.Abs(myCreature.LaneIndex - creature.LaneIndex)); } else { return(-1); } }
public int GetNearestEnemyLane(LaneManager[] Board) { LogStack.Log("GetNearestEnemyLane()", Logging.LogLevel.Color); CreatureBase creature = GetNearestEnemy(Board); if (creature != null) { return(TournamentManager._instance.lanes.IndexOf(creature.ActiveLaneNode.laneManager)); } else { return(-1); } }
public CreatureBase GetNearestEnemy(LaneManager[] Board) { CreatureBase[] NearestEnemies = GetNearestEnemies(Board); if (NearestEnemies.Length > 0) { LogStack.Log("GetNearestEnemy()" + NearestEnemies[0], Logging.LogLevel.Color); return(NearestEnemies[0]); } else { LogStack.Log("GetNearestEnemy()" + null, Logging.LogLevel.Color); return(null); } }
public int GetNearestEnemyNodesAway(LaneManager[] Board) { LogStack.Log("GetNearestEnemyNodesAway()", Logging.LogLevel.Color); CreatureBase creature = GetNearestEnemy(Board); if (creature != null) { return(creature.ActiveLaneNode.laneManager.GetNodeCount - creature.LaneProgress); } else { return(-1); } }
public CreatureBase GetNearestEnemyTo(CreatureBase myCreature) { List <CreatureBase> enemyCreatures = myCreature.ActiveLaneNode.laneManager.GetEnemiesInLane(this); if (enemyCreatures.Count > 0) { LogStack.Log("GetNearestEnemy()" + enemyCreatures[0], Logging.LogLevel.Color); return(enemyCreatures[0]); } else { LogStack.Log("GetNearestEnemy()" + null, Logging.LogLevel.Color); return(null); } }
public IEnumerator AttackConfirm() { LogStack.Log("AttackConfirm () " + 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("AttackConfirm () " + this.name + " | " + hit.transform.name, LogLevel.Stack); if (Input.GetMouseButtonDown(0) && creature?.Owner == this) { foundCreature = true; if (!AIResponse.Attack(creature)) { LogStack.Log("Could Not Attack Creature", LogLevel.Stack); OpenUI(); } else if (AIResponse.Tokens > 0) { LogStack.Log("Creature Attacked", LogLevel.Stack); _uiAnimator.SetBool("Actions", false); yield return(null); OpenUI(); } else { LogStack.Log("Creature Attacked", LogLevel.Stack); Finalise(); CloseUI(); } } else if (Input.GetMouseButtonDown(1)) { OpenUI(); foundCreature = true; } } yield return(null); } }
private void Awake() { if (_instance == null) { _instance = this; LogLevel console = (int)LogLevel.All - LogLevel.System; logger = new ConsoleLogger(console); // chain the stack log to follow the console. makes it reachable through logger.message LoggerSystem = logger.SetNext(new SystemLogger(LogLevel.System | LogLevel.System)); loggerStack = LoggerSystem.SetNext(new StackLogger(LogLevel.Stack, 5)); Color = loggerStack.SetNext(new ColorLogger(LogLevel.Color, "green")); } else { Destroy(this); } }
void Awake() { DontDestroyOnLoad(gameObject); if (config == null) { config = Resources.Load <TerminalConfig>("Config/ZSH"); } if (mobileTouchCount <= 0) { mobileTouchCount = 4; } AutoCompIndex = 0; AutoCompList = new List <string>(); terminalMethods = new TerminalMethods(); inputHandler = new TerminalInputHandler(this); terminalGui = new TerminalGUI(this); logStack = new LogStack(config); }
public override void OnTick(IBoardState[] board) { boardState = (LaneManager[])board; Debug.Log(boardState.Length); LogStack.Log("Run Auto Response Nearest for:" + AIResponse.Tokens, Logging.LogLevel.Color); //for (int i = 0; i < AIResponse.Tokens; i++) //{ // Auto_Nearest(boardState); //} Auto_Nearest(boardState); Auto_Nearest(boardState); Auto_Nearest(boardState); //} ////IResponse[] responses = AIResponse.QueryResponse(); AIResponse.FinalizeResponse(); }
public bool Move(CreatureBase creature, int range = 1) { if (creature == null || creature.isDead) { return(false); } range = Mathf.Clamp(range, 0, tokens); LogStack.Log("creature.ActiveLaneNode: " + creature.ActiveLaneNode, LogLevel.System); LogStack.Log("creature.Owner._RightFacing: " + creature.Owner._RightFacing, LogLevel.System); LaneNode nextNode = creature.ActiveLaneNode.laneManager.GetNextLaneNode(creature.ActiveLaneNode, creature.Owner._RightFacing, creature.ActiveLaneNode.laneManager.GetMaxNodes(creature.ActiveLaneNode, creature.Owner._RightFacing, Mathf.Abs(range))); // LaneNode nextNode = creature.ActiveLaneNode.laneManager.GetNextLaneNode (creature.ActiveLaneNode, creature.Owner._RightFacing, Mathf.Abs (range)); LogStack.Log ("nextNode: " + nextNode, LogLevel.System); if (creature != null && nextNode != null && nextNode.activeCreature == null) { LogStack.Log("Next Node: " + nextNode.GetInstanceID(), LogLevel.System); if (SpendToken(range)) { LogStack.Log("Response | Move " + range, LogLevel.Stack); IResponse response = new ActionResponse(creature, 0, logicBase, ResponseActionType.Move, nextNode); if (!ResponseChain.Contains(response)) { ResponseChain.Add(response); } else { LogStack.Log("##### Duplicate Move Response", LogLevel.System); RefundToken(); return(false); } return(true); } else { return(false); } } else { return(false); } }
public void Move(LaneNode nextNode) { LogStack.Log("Moving Creature", LogLevel.Stack); CameraShake._CameraShake.DoCameraShake(0.2f, rightFacing ? 0.2f : -0.2f); if (activeLaneNode.activeCreature == this) { activeLaneNode.activeCreature = null; } LogStack.Log("MOVING: Current Node - " + activeLaneNode.name, LogLevel.System); activeLaneNode = nextNode; if (nextNode != null) { LogStack.Log("MOVING: New Node - " + activeLaneNode.name, LogLevel.System); activeLaneNode.activeCreature = this; transform.position = activeLaneNode.transform.position; } laneProgress = LaneProgress; Win(); }
private void EvaluatePerformance() { float fAveragePerformance = 0f; foreach (float performance in Q_RoundPerformances) { LogStack.Log("Performance = " + performance, LogLevel.Debug); fAveragePerformance += performance; } fAveragePerformance /= Q_RoundPerformances.Count; LogStack.Log("fAveragePerformance = " + fAveragePerformance, LogLevel.Debug); if (fAveragePerformance > 2.1f) { ELearningState = EPerformanceState.VeryGood; } else if (fAveragePerformance < -2.7f) { ELearningState = EPerformanceState.VeryBad; } else if (fAveragePerformance > 0.7f) { ELearningState = EPerformanceState.Good; } else if (fAveragePerformance < -1.3f) { ELearningState = EPerformanceState.Bad; } else { ELearningState = EPerformanceState.Normal; } Q_PerformanceStates.Enqueue(ELearningState); if (Q_PerformanceStates.Count > 2) { Q_PerformanceStates.Dequeue(); } }
private void StartEvent(object sender, StartupEventArgs e) { if (e != null && e.Args.Select(arg => arg.Equals("--debug-console")).Count() > 0) { this.LogStack = new LogStack(); LogWindow logWindow = new LogWindow(); logWindow.Show(); LoggingConfiguration conf = LogManager.Configuration; LogTarget consoleTarget = new LogTarget("consoleWrapper", this.LogStack); conf.AddRule(LogLevel.Trace, LogLevel.Fatal, consoleTarget); LogManager.Configuration = conf; } AppDomain.CurrentDomain.UnhandledException += this.UnhandledException; logger.Info("Start application."); this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.notify = new NotifycationWrapper(); this.Initialize(); }
private void PointPushCheck() { List <CreatureBase> PotentialPushers = GetTroops(true); int iMinDistance = iPointPushThreshold; bool bOpenLane = false; foreach (CreatureBase troop in PotentialPushers) { LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% Checking Troop: " + troop.name + " LaneProgress = " + troop.LaneProgress, LogLevel.Debug); int EndDist = 10 - troop.LaneProgress; LogStack.Log("********************** Open Nodes = " + troop.ActiveLaneNode.laneManager.GetOpenNodes(troop.ActiveLaneNode, B_StartLeft) + " ********************* ", LogLevel.Debug); if (troop.LaneProgress > 1 && (10 - troop.LaneProgress <= troop.ActiveLaneNode.laneManager.GetOpenNodes(troop.ActiveLaneNode, B_StartLeft))) { LogStack.Log("********************** OPEN LANE DETECTED ********************* ", LogLevel.Debug); responseCreature = troop; iMinDistance = EndDist; bOpenLane = true; break; } if (EndDist < iMinDistance && !bOpenLane) { iMinDistance = EndDist; responseCreature = troop; } } if (!bOpenLane && iMinDistance == iPointPushThreshold) { //LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% iMinDistance = iPointPushThreshold", LogLevel.Debug); iSavingTokens = 0; } else { iSavingTokens = iMinDistance; responseState = EResponseState.PointPush; } }
private CreatureBase GetClosestEnemy(CreatureBase Troop, out int iDistance, int iMaxDist = 7) { List <CreatureBase> searchTargets = Troop.ActiveLaneNode.laneManager.SearchRange(iMaxDist, Troop.ActiveLaneNode, this); if (searchTargets != null && searchTargets.Count > 0) { iDistance = Troop.ActiveLaneNode.laneManager.GetOpenNodes(Troop.ActiveLaneNode, _RightFacing); LogStack.Log("%%%%%%%%%%%%%%%%%%%%%% GetClosestEnemy(1) %%%%%%%%%%%%%% - iDistance = " + iDistance, LogLevel.Debug); if (iDistance >= iMaxDist) { iDistance = 0; } if (iDistance == 0) { return(null); } return(searchTargets[0]); } else { iDistance = -1; return(null); } }
private void PrintPerformance() { LogStack.Log("########################################################", LogLevel.Debug); LogStack.Log("################ PERFORMANCE REPORT - ACTION ################", LogLevel.Debug); LogStack.Log("########################################################", LogLevel.Debug); LogStack.Log("--------------------------- ", LogLevel.Debug); LogStack.Log("--- SCORE STATUS --- ", LogLevel.Debug); LogStack.Log("Enemy Points = " + I_EnemyPoints + " | Gained " + I_EnemyPointsGain, LogLevel.Debug); LogStack.Log("Points = " + I_Points + " | Gained " + I_PointsGain, LogLevel.Debug); LogStack.Log("--------------------------- ", LogLevel.Debug); LogStack.Log("--- PROGRESS STATUS --- ", LogLevel.Debug); LogStack.Log("Enemy Progress = " + I_EnemyProgress + " | Average = " + F_AverageEnemyProgress, LogLevel.Debug); LogStack.Log("Progress = " + I_Progress + " | Average " + F_AverageProgress, LogLevel.Debug); LogStack.Log("--------------------------- ", LogLevel.Debug); LogStack.Log("--- CREATURE STATUS --- ", LogLevel.Debug); LogStack.Log("Enemy Kills Last Turn = " + I_Kills, LogLevel.Debug); LogStack.Log("Friendly Deaths Last Turn = " + I_Deaths, LogLevel.Debug); LogStack.Log("--------------------------- ", LogLevel.Debug); LogStack.Log("--- TOKEN STATUS --- ", LogLevel.Debug); LogStack.Log("Enemy Tokens = " + I_EnemyTokens + " | Spent " + I_EnemyTokensSpent, LogLevel.Debug); LogStack.Log("Tokens = " + I_Tokens + " | Spent " + I_TokensSpent, LogLevel.Debug); LogStack.Log("--------------------------- ", LogLevel.Debug); LogStack.Log("########################################################", LogLevel.Debug); }
private void OnDestroy() { _instance = null; }