private void TakeActionOnEachBot(ActiveTurnData turnData) { if (BattleActive) { // TODO: CHECK INACTIVE and DEAD BOTS DONT GET TURNS (unit test) // TODO : UNIT TEST, bot that thorws exception is killed EachActiveBot((mappedBot) => { LastTickRecord ltr; if (turnData.LastTickRecords.ContainsKey(mappedBot.EngineId)) { ltr = turnData.LastTickRecords[mappedBot.EngineId]; turnData.LastTickRecords.Remove(mappedBot.EngineId); } else { ltr = new LastTickRecord(); } try { mappedBot.Bot.TakeAction(Turn, Tick, ltr); } catch (Exception ex) { b.Info.Dump(ex, "Exception in BOT" + mappedBot.Bot.Name); PerformBotDeath(mappedBot, BotEndReason.ExceptionOccured); } }); } }
private void ManageDynamicTurnData_Pre() { if (Tick == 11) { ActiveTurnData atd = new ActiveTurnData(); atd.LastTickRecords = new Dictionary <int, LastTickRecord>(); foreach (int v in activeData.LastTickRecords.Keys) { atd.LastTickRecords.Add(v, activeData.LastTickRecords[v]); } } }
private void BattleStarts() { BattleActive = true; SystemMessageContext smc = new SystemMessageContext(); smc.BotId = -1; smc.Message = "Let Battle Commence...."; hub.Launch <Message_Game>(new Message_Game(MainMessageKind.GameStructure, KnownSubkinds.BattleStarts) { RequestContext = smc }); activeData = new ActiveTurnData(); }
public void PerformNextTick() { if (!HavePrepared) { throw new BdBaseException("Must prepare before performing next tick"); } WriteDiagnosticTurnSummary(); // Conditional, debug only. ManageDynamicTurnData_Pre(); PerformBotPerTickManipulation(); Tick = (Tick + 1) % 11; LaunchTurnNotification(); if (Tick == 0) { if (Turn == 0) { BattleStarts(); } b.Info.Log("New Turn starts, creating activeData"); Turn++; Tick++; // TODO : UNIT TEST MAKE SURE IT GOES 1,1 1,2, 1,3 --> TakeActionOnEachBot(activeData); activeData = new ActiveTurnData(); PerformBotPerTurnManipulation(); } PerformMovementForTick(); DEBUG_CheckForDeadBots(); CheckEndCondition(); if (!BattleActive) { PerformBattleShutdownEvents(); return; } TakeActionOnEachBot(activeData); SendBotStatusNotifications(); ManageDynamicTurnData_Post(); }