Esempio n. 1
0
    // The Queen leaves four PHER0 pheromones on its tile to show where she is
    public override Decision OnQueenTurn(TurnInformation info)
    {
        ChoiceDescriptor choice = ChoiceDescriptor.ChooseNone();

        // If there is enough energy
        if (info.energy > Value.LOW)
        {
            // If it is the first turn
            if (info.pastTurn == null || info.pastTurn.pastDecision == null || info.pastTurn.pastDecision.choice == null)
            {
                choice = ChoiceDescriptor.ChooseEgg((HexDirection)Random.Range(1, 7));
            }

            // If there was no error
            else if (info.pastTurn.error == TurnError.NONE)
            {
                choice = ChoiceDescriptor.ChooseEgg(info.pastTurn.pastDecision.choice.direction);
            }

            // If there was an error because of auto-egg
            else if (info.pastTurn.pastDecision.choice.direction == HexDirection.CENTER)
            {
                choice = ChoiceDescriptor.ChooseEgg(DirectionManip.RotateDirectionCW((HexDirection)Random.Range(1, 7)));
            }

            // If there was an error
            else
            {
                choice = ChoiceDescriptor.ChooseEgg(DirectionManip.RotateDirectionCW(info.pastTurn.pastDecision.choice.direction));
            }
        }
        else
        {
            choice = ChoiceDescriptor.ChooseEat(HexDirection.CENTER, 100);
        }

        // Puts the pheromone signal on the ground to show its position
        List <PheromoneDigest> pheromoneSignal = new List <PheromoneDigest>();

        for (int i = 0; i < Const.MAX_PHEROMONE_BY_CELL; i++)
        {
            pheromoneSignal.Add(new PheromoneDigest(PheromoneType.PHER0, HexDirection.CENTER));
        }

        return(new Decision(AntMindset.AMS0, choice, pheromoneSignal));
    }
Esempio n. 2
0
    // AMS0 - AMS1 - AMS2: The Queen tries to find the center of the three free tiles to lay her eggs in
    // AMS0: The Queen is rotating CCW in order to find a out-of-bounds tile ; the first out-of-bounds tile makes the Queen become AMS1
    // AMS1: An out-of-bound tile has been found, now the Queen is rotating CW to find the first free tile
    // AMS1: When the Queen has found the first free time, it places four PHER3 showing the next tile CW, which is the center of the three free tiles to lay eggs in ; the Queen goes AMS2
    // AMS2: The Queen spawns eggs randomly in the center free tile
    // AMS2: If the Queen has a low energy, it eats if it has carried food, or else tries to lay eggs
    public override Decision OnQueenTurn(TurnInformation info)
    {
        AntMindset             mindset    = info.mindset;
        ChoiceDescriptor       choice     = ChoiceDescriptor.ChooseNone();
        List <PheromoneDigest> pheromones = info.pheromones;

        if (info.pastTurn == null)
        {
            mindset = AntMindset.AMS0;
            choice  = ChoiceDescriptor.ChooseAnalyse((HexDirection)Random.Range(1, 7));
            Debug.Log(choice.direction);
        }
        else
        {
            switch (mindset)
            {
            case AntMindset.AMS0:

                switch (info.pastTurn.error)
                {
                case TurnError.NONE:         // The out-of-bounds tile has not been found

                    choice = ChoiceDescriptor.ChooseAnalyse(DirectionManip.RotateDirectionCCW(info.pastTurn.pastDecision.choice.direction));

                    break;

                case TurnError.COLLISION_VOID:         // The out-of-bounds tile has been found

                    mindset = AntMindset.AMS1;
                    choice  = ChoiceDescriptor.ChooseAnalyse(DirectionManip.RotateDirectionCW(info.pastTurn.pastDecision.choice.direction));

                    break;

                default:         // Should not happen

                    choice = ChoiceDescriptor.ChooseNone();

                    break;
                }

                break;

            case AntMindset.AMS1:

                switch (info.pastTurn.error)
                {
                case TurnError.COLLISION_VOID:         // The free tile has not been found

                    choice = ChoiceDescriptor.ChooseAnalyse(DirectionManip.RotateDirectionCW(info.pastTurn.pastDecision.choice.direction));

                    break;

                case TurnError.NONE:         // The out-of-bounds tile has been found

                    mindset = AntMindset.AMS2;
                    HexDirection freeCenter = DirectionManip.RotateDirectionCW(info.pastTurn.pastDecision.choice.direction);

                    pheromones = new List <PheromoneDigest>();
                    for (int i = 0; i < 4; i++)
                    {
                        pheromones.Add(new PheromoneDigest(PheromoneType.PHER3, freeCenter));
                    }

                    choice = ChoiceDescriptor.ChooseEgg(freeCenter);

                    break;

                default:         // Should not happen

                    choice = ChoiceDescriptor.ChooseNone();

                    break;
                }

                break;

            case AntMindset.AMS2:

                if (info.energy >= Value.MEDIUM)
                {
                    HexDirection freeCenter = FindFreeCenter(info.pheromones);
                    choice = ChoiceDescriptor.ChooseEgg(freeCenter);
                }
                else if (info.carriedFood > Value.NONE)
                {
                    choice = ChoiceDescriptor.ChooseEat(HexDirection.CENTER, 100);
                }
                else
                {
                    HexDirection freeCenter = FindFreeCenter(info.pheromones);
                    choice = ChoiceDescriptor.ChooseEgg(freeCenter);
                }

                break;
            }
        }

        return(new Decision(mindset, choice, pheromones));
    }