コード例 #1
0
ファイル: task4_q1.c プロジェクト: mujavidb/roboticsChallenge
void checkMove(char first,char last){
	moveStart(temp,first);
  if ((first=='A' && last=='B')||(first=='B' && last=='C')){
    moveBot(sheet_space);
    high(26);
    pause(2000);
    low(26);
  } else if ((first=='B'&& last=='A')||(first=='C' && last=='B')){
    moveBot(-sheet_space);
    high(26);
    pause(2000);
    low(26);
  } else if (first=='A' && last=='C'){
    moveBot(sheet_space * 2);
    high(26);
    pause(2000);
    low(26);
  } else if (first=='C'&& last=='A'){
    moveBot(-sheet_space * 2);
    high(26);
    pause(2000);
    low(26);      
  }
	temp = last;
}
コード例 #2
0
ファイル: task4_q1.c プロジェクト: mujavidb/roboticsChallenge
void moveStart(char first,char last){
	if ((first=='A' && last=='B')||(first=='B' && last=='C')){
    moveBot(sheet_space);
    high(26);
    pause(2000);
    low(26);
  } else if ((first=='B' && last=='A')||(first=='C' && last=='B')){
    moveBot(-sheet_space);
    high(26);
    pause(2000);
    low(26);
  } else if (first=='A' && last=='C'){
    moveBot(sheet_space * 2);
    high(26);
    pause(2000);
    low(26);
  } else if (first=='C' && last=='A'){
    moveBot(-sheet_space * 2);
    high(26);
    pause(2000);
    low(26);
  }
}
コード例 #3
0
ファイル: KikiBot.cpp プロジェクト: Mistress-Anna/kiki
// __________________________________________________________________________________________________
void KikiBot::actionFinished ( KikiAction * action )
{
    int actionId = action->getId();

    if (isDead())
    {
        if (!died) die();

        if (actionId != ACTION_PUSH && actionId != ACTION_FALL)
        {
            // dead player may only fall, nothing else
            return;
        }
    }

    if (spiked)
    {
        move_action = NULL;
        startTimedAction (getActionWithId(ACTION_NOOP), 0);
        return;
    }

    if (actionId == ACTION_PUSH || direction != KVector())
    {
        KikiPushable::actionFinished (action);
        return;
    }

    if (move_action) return; // action was not a move action -> return

    // find next action depending on type of finished action and surrounding environment
    if (actionId == ACTION_JUMP_FORWARD)
    {
        KVector forwardPos = position + getDir();
        if (Controller.world->isUnoccupiedPos (forwardPos))
        {   // forward will be empty
            if (Controller.world->isUnoccupiedPos (forwardPos - getUp()))
            {   // below forward will also be empty
                move_action = getActionWithId (ACTION_FALL_FORWARD);
                move_action->takeRest (action);
            }
            else
            {
                move_action = getActionWithId (ACTION_FORWARD);
                Controller.sound->playSoundAtPos (KikiSound::BOT_LAND, getPos(), 0.25);
            }
        }
        else // forward will not be empty
        {
            if (Controller.world->isUnoccupiedPos (position - getUp())) // below is empty
            {
                move_action = getActionWithId (ACTION_CLIMB_UP);
                Controller.sound->playSoundAtPos (KikiSound::BOT_LAND, getPos(), 0.5);
            }
        }
    }
    else if (Controller.world->isUnoccupiedPos (position - getUp())) // below will be empty
    {
        if (move) // sticky if moving
        {
            if (Controller.world->isUnoccupiedPos (position + getDir()))
            {   // forward will be empty
                if (Controller.world->isOccupiedPos (position + getDir() - getUp()))
                {   // below forward is solid
                    KikiObject * occupant = Controller.world->getOccupantAtPos(position + getDir() - getUp());
                    if (occupant == NULL || !occupant->isSlippery())
                        move_action = getActionWithId (ACTION_FORWARD);
                }
            }
            else
            {
                KikiObject * occupant = Controller.world->getOccupantAtPos(position + getDir());
                if (occupant == NULL || !occupant->isSlippery())
                    move_action = getActionWithId (ACTION_CLIMB_UP);
            }
        }

        if (move_action == NULL)
        {
            move_action = getActionWithId (ACTION_FALL);
            move_action->takeRest (action);
        }
    }
    else if (actionId == ACTION_FALL || actionId == ACTION_FALL_FORWARD) // landed
    {
        if (this == (KikiBot*)Controller.player)
        {
            Controller.sound->playSound (KikiSound::BOT_LAND);
        }
        else
        {
            Controller.sound->playSoundAtPos(KikiSound::BOT_LAND, getPos());
        }
    }

    if (move_action)
    {
        Controller.timer_event->addAction (move_action);
        return;
    }

    if (rotate_action) return;

    if (move)
    {
        moveBot();
    }
    else
    {
        dir_sgn = 1.0;
        if (actionId != ACTION_NOOP) jump_once = false;
        // keep action chain flowing in order to detect environment changes
        startTimedAction (getActionWithId (ACTION_NOOP), 0);
    }
}