예제 #1
0
        /// <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);
        }
예제 #2
0
    // Performed when run button pressed
    void Awake()
    {
        grid              = GetComponent <Grid> ();
        requestManager    = GetComponent <PathRequestManager> ();
        heuristicsManager = GetComponent <HeuristicsManager> ();

        // SET HEURISTIC:
        // 0: Manhattan
        // 1: Euclidian
        // 2: Diagonals
        heuristic = 1;
    }