예제 #1
0
    // Priority #0: If the ant is attacked and is not capital, it fights back (an ant is capital if it has more than or equal to MEDIUM food, or knows where the enemy Queen is (AMS7 or recent analyse))
    // Priority #1: If the ant detects that it is on the spawn tile, it moves away to the right or to the left of the Queen, and leaves three PHER3 in the same direction as the ones under the Queen
    // AMS0 (exploration): If there is 0 pheromone under the ant, it moves straight and turns randomly when there is an obstacle (without going back), and leaves a PHER0
    // AMS0 (exploration): If there is 1 to 3 pheromones under the ant, it follows them without leaving anything, and has a chance to leave the path, leaving a trace
    // AMS0 (exploration): If there is 4 pheromones under the ant, it follows them without leaving anything
    // AMS0 (exploration): If there is 2 to 4 pheromones, if the ant tried to leave the path but found an obstacle, in has to remove its mark
    // AMS0 (exploration): If the ant bumps into an enemy, it analyses it
    public override Decision OnWorkerTurn(TurnInformation info)
    {
        AntMindset             mindset    = info.mindset;
        ChoiceDescriptor       choice     = ChoiceDescriptor.ChooseNone();
        List <PheromoneDigest> pheromones = info.pheromones;

        // Analyses the situation
        bool isImportant = IsImportant(info);
        KeyValuePair <HexDirection, List <PheromoneDigest> > queenPheromones = FindAdjacentQueen(info.adjacentPheromoneGroups);
        HexDirection attackOrigin = HasBeenAttacked(info.eventInputs);

        // Priority #0: Fights back if attacked and not important
        if (attackOrigin != HexDirection.CENTER == !isImportant)
        {
            choice = ChoiceDescriptor.ChooseAttack(attackOrigin);
        }
        // Priority #1: Checks if the Worker is in the spawn tile
        if (queenPheromones.Key != HexDirection.CENTER && queenPheromones.Value != null && queenPheromones.Value[0].direction == DirectionManip.InvertDirection(queenPheromones.Key))
        {
            mindset = AntMindset.AMS0;

            int rand = Random.Range(0, 2);
            if (rand == 0)
            {
                choice = ChoiceDescriptor.ChooseMove(DirectionManip.RotateDirectionCCW(queenPheromones.Key));
            }
            else
            {
                choice = ChoiceDescriptor.ChooseMove(DirectionManip.RotateDirectionCW(queenPheromones.Key));
            }

            pheromones = new List <PheromoneDigest>();
        }
        else
        {
            switch (mindset)
            {
            case AntMindset.AMS0:
                break;
            }
        }

        return(new Decision(mindset, choice, pheromones));
    }
예제 #2
0
    public override Decision OnWorkerTurn(TurnInformation info)
    {
        // Setting the defaults
        AntMindset             mindset    = AntMindset.AMS0;
        ChoiceDescriptor       choice     = ChoiceDescriptor.ChooseNone();
        List <PheromoneDigest> pheromones = null;


        HexDirection attackDirection = HexDirection.CENTER;

        if (info.pastTurn != null)
        {
            attackDirection = GetAttackDirection(info.eventInputs);
        }

        if (info.pastTurn == null)
        {
            choice = ChoiceDescriptor.ChooseMove((HexDirection)Random.Range(1, 8));
        }

        else if (attackDirection != HexDirection.CENTER)
        {
            choice = ChoiceDescriptor.ChooseAttack(attackDirection);
        }

        else
        {
            switch (info.pastTurn.pastDecision.choice.type)
            {
            case ActionType.MOVE:

                switch (info.pastTurn.error)
                {
                case TurnError.NONE:
                    int rand = Random.Range(0, 10);
                    if (rand < 8)
                    {
                        choice = ChoiceDescriptor.ChooseMove(info.pastTurn.pastDecision.choice.direction);
                    }
                    else
                    {
                        choice = ChoiceDescriptor.ChooseMove((HexDirection)Random.Range(1, 8));
                    }
                    break;

                case TurnError.COLLISION_ANT:
                    choice = ChoiceDescriptor.ChooseAttack(info.pastTurn.pastDecision.choice.direction);
                    break;

                default:
                    choice = ChoiceDescriptor.ChooseMove((HexDirection)Random.Range(1, 8));
                    break;
                }

                break;

            case ActionType.ATTACK:

                switch (info.pastTurn.error)
                {
                case TurnError.NONE:
                    choice = ChoiceDescriptor.ChooseAttack(info.pastTurn.pastDecision.choice.direction);
                    break;

                default:
                    choice = ChoiceDescriptor.ChooseMove((HexDirection)Random.Range(1, 8));
                    break;
                }

                break;

            default:
                choice = ChoiceDescriptor.ChooseMove((HexDirection)Random.Range(1, 8));
                break;
            }
        }

        if (choice.type == ActionType.MOVE)
        {
            pheromones = new List <PheromoneDigest>();
            pheromones.Add(new PheromoneDigest(PheromoneType.PHER0, choice.direction));
        }

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