/**
 * Pick a random empty location within our neighbourhood as defined by our vision
 *
 * Ranks chosen move randomly
 * @param loc :Our location
 * @see Move Rule
 * @return Our chosen location held in a group object (or our existing location if we have no move)
 * @exception none
 */
group* AgentMoveClosest::formGroup(Location *loc)
{
    group *ourChoice = nullptr;
    if (loc->hasAgent()) {/*!< Agent at this location */
        ourChoice = new group();
        Agent* theAgent=loc->getAgent();
        std::vector<Location*> possibleDestinations=sim->getEmptyNeighbourhood(theAgent->getPosition(), theAgent->getVision());/*!< find all empty locations */
        if (possibleDestinations.size()!=0) {/*!< check to see if we can move anywhere */
            int index=pickIndex(possibleDestinations);
            int xdiff=possibleDestinations[index]->getPosition().first-theAgent->getPosition().first;
            int ydiff=possibleDestinations[index]->getPosition().second-theAgent->getPosition().second;
            if (xdiff<0) xdiff=-xdiff;
            if (ydiff<0) ydiff=-ydiff;
            int rank=xdiff+ydiff;/*!< Manhatten distance */
            ourChoice->push_back(possibleDestinations[index]);
            ourChoice->setRank(rank);
            ourChoice->setPrimeMover(loc);
            ourChoice->setActiveParticipants(1);//one active participant per group - the agent moving
        }
        else{/*!< nowhere to move so stay here */
            ourChoice->push_back(loc);
            ourChoice->setRank(0);
            ourChoice->setPrimeMover(loc);
            ourChoice->setActiveParticipants(1);
        }

    }
    return ourChoice;/*!< is NOT nullPtr only if we assigned it a value earlier */
}
示例#2
0
/**
 * Creates the group containing the vistim we are attacking or empty location we are moving to
 * @param loc :pointer to our location
 * @see Combat Rule
 * @return pointer to group object
 * @exception none
 */
group* AgentCombat::formGroup(Location *loc)
{
    if (loc->hasAgent() && loc->isDone()==false) {/*!< Agent at this location */
        group *ourChoice = nullptr;
        Agent* theAgent=loc->getAgent();
        std::vector<Location*> possibleLocations=sim->getCombatNeighbourhood(theAgent->getPosition(), theAgent->getVision());/*!< Find all possible destinations */
        ourChoice = new group();
        if (possibleLocations.size()!=0) {/*!< check to see if we can move anywhere */
            int index=pickIndex(possibleLocations, theAgent);
            if (index>-1) {//we have a winner -- form  a group
                ourChoice->push_back(possibleLocations[index]);
                                     //sim->getLocation(possibleLocations[index]->getPosition()));
                int rank=possibleLocations[index]->getPosition().first-theAgent->getPosition().first
                +possibleLocations[index]->getPosition().second-theAgent->getPosition().second;
                if (rank<0) rank =-rank;
                ourChoice->setRank(rank);
                ourChoice->setPrimeMover(loc);
                if (possibleLocations[index]->hasAgent()) {
                    ourChoice->setActiveParticipants(2);/*!< have killed agent therefore two participants here */
                }else{
                    ourChoice->setActiveParticipants(1);//one active participant in group - the agent moving
                }
            }
            else{/*!< cannot find anywhere safe to move so stay here */

                ourChoice->setRank(0);
                ourChoice->setPrimeMover(loc);
                ourChoice->setActiveParticipants(1);
            }
        }else{/*!< everywhere is occupied so stay here */
            ourChoice->setRank(0);
            ourChoice->setPrimeMover(loc);
            ourChoice->setActiveParticipants(1);
        }
        return ourChoice;
    }
    return nullptr;/*!< No agent here do nothing */
}
/**
 * Pick a random empty location within our neighbourhood as defined by our vision
 *
 * Ranks chosen move randomly
 * @param loc :Our location
 * @see Move Rule
 * @return Our chosen location held in a group object (or our existing location if we have no move)
 * @exception none
 */
group* AgentMoveStrongest::formGroup(Location *loc)
{
    group *ourChoice = nullptr;
    if (loc->hasAgent()) {/*!< Agent at this location */
        ourChoice = new group();
        Agent* theAgent=loc->getAgent();
        std::vector<Location*> possibleDestinations=sim->getEmptyNeighbourhood(theAgent->getPosition(), theAgent->getVision());/*!< find all empty locations */
        if (possibleDestinations.size()!=0) {/*!< check to see if we can move anywhere */
            int index=pickIndex(possibleDestinations);
            ourChoice->push_back(possibleDestinations[index]);
            ourChoice->setRank(-theAgent->getSugar());/*!< Rank by sugar of moving agent */
            ourChoice->setPrimeMover(loc);
            ourChoice->setActiveParticipants(1);//one active participant per group - the agent moving
        }
        else{/*!< nowhere to move so stay here */
            ourChoice->push_back(loc);
            ourChoice->setRank(0);
            ourChoice->setPrimeMover(loc);
            ourChoice->setActiveParticipants(1);
        }

    }
    return ourChoice;/*!< is NOT nullPtr only if we assigned it a value earlier */
}