/// <summary> /// Adds the actions pack to the chooser /// </summary> /// <returns>wether the addition was successful</returns> public bool AddActionsPack(ActionsPack pack, double value) { if (pack == null || pack.IsEmpty || value <= 0) { return(false); } // give the pack the consistency bonuses foreach (Command cmd in pack.GetCommands()) { foreach (Pirate pirate in cmd.GetMyPiratesUsed()) { if (pirate != null && this.executingEvents[pirate.Id] == cmd.SourceEvent) { value += EVENT_CONSISTENCY_BONUS; } if (pirate != null && this.turnsSinceActive[pirate.Id] != -1 && this.game.GetAllMyPiratesCount() > this.game.ActionsPerTurn) { value += PIRATE_CONSISTENCY_BONUS / this.turnsSinceActive[pirate.Id]; } } } this.list.Add(new KeyValuePair <double, ActionsPack>(value, pack)); return(true); }
/// <summary> /// Returns the best ActionsPack the can be fabricated from the contained ActionsPacks /// </summary> public ActionsPack ChooseBestStableCombination() { this.game.Log(LogType.ActionsChoosing, LogImportance.Important, "Packs' count: {0}", this.list.Count); // sort the list, by descending order this.list.Sort(new ReverseKeyValueComparer <double, ActionsPack>()); // initialize the heuristics this.game.Log(LogType.Timing, LogImportance.SomewhatImportant, "start heuristics calculation: {0}", this.game.GetTimeRemaining()); this.heuristics = new HeuristicsManager(this.list, this.game); this.game.Log(LogType.Timing, LogImportance.SomewhatImportant, "end heuristics calculation: {0}", this.game.GetTimeRemaining()); // will be used to hold the best option ActionsPack bestOption = new ActionsPack(this.game); // start up the recursion this.chooseBestStableCombination(new ActionsPack(this.game), // no packs until now; no need to track this pack, as it will be cleared out anyways 0, // 0 value until now bestOption, // the best option until now 0, // and its value 0, // choose from the start this.game.MaxCommandsPerTurn); // the maximum count of ActionsPacks that can be merged // update the consistency bonus // reset executing events for (int i = 0; i < this.executingEvents.Length; i++) { this.executingEvents[i] = -1; } // reset turns since active for (int i = 0; i < this.turnsSinceActive.Length; i++) { Pirate curPirate = game.GetMyPirate(i); if (curPirate.State == PirateState.Drunk || curPirate.State == PirateState.Lost || curPirate.Location.Equals(curPirate.InitialLocation)) { this.turnsSinceActive[i] = -1; } else if (this.turnsSinceActive[i] != -1) { this.turnsSinceActive[i] += 1; } } // update the arrays foreach (Command cmd in bestOption.GetCommands()) { foreach (Pirate pirate in cmd.GetMyPiratesUsed()) { if (pirate != null) { this.executingEvents[pirate.Id] = cmd.SourceEvent; this.turnsSinceActive[pirate.Id] = 1; } } } // return the best option return(bestOption); }