E_BEHAVIOR_ACTIONS CAggressiveBehaviorModule::playBehavior(const CGame& inGame)
{
    E_BEHAVIOR_ACTIONS nextAction = E_ACTION_STAY;

    int opponentIdWithMaxMineCount = -1;
    int maxMineCount = 0;

    if (inGame.getOpponentIdWithMaxMineCount(opponentIdWithMaxMineCount, maxMineCount))
    {
        const CHero &targetHero = inGame.getHero(opponentIdWithMaxMineCount);
        const CPosition targetHeroPos(targetHero.getPosition());
        const int targetHeroCellId = inGame.get1DCoordOnBoard(targetHeroPos);
        const CHero &myHero = inGame.getMyHero();

        path_t targetHeroPath;
        if (inGame.getPathTo(myHero.getId(), targetHeroCellId, false, targetHeroPath))
        {
//             inGame.printPath(targetHeroPath, m_name);

            const CPosition nextPosition(inGame.get2DCoordOnBoard(*targetHeroPath.cbegin()));
            int deltaX = nextPosition.getX() - myHero.getPosition().getX();
            int deltaY = nextPosition.getY() - myHero.getPosition().getY();

            if      (deltaX ==  1) nextAction = E_ACTION_MOVE_EAST;
            else if (deltaX == -1) nextAction = E_ACTION_MOVE_WEST;
            else if (deltaY ==  1) nextAction = E_ACTION_MOVE_SOUTH;
            else if (deltaY == -1) nextAction = E_ACTION_MOVE_NORTH;
        } else {}
    } else
    {
        // WAIT
    } // else

    return nextAction;
} // playBehavior
Example #2
0
// Call diz function implies an existing CPosition component
void CSprite::updatePosition() {
  CPosition * position =(CPosition *) parent->getComponent("Position");
  sprite.setPosition( position->getX() , position->getY());
}