Exemplo n.º 1
0
def chaseAroundBox(player):
    if player.firstFrame():
        player.shouldNotChaseAroundBox = 0

        player.brain.CoA.setRobotGait(player.brain.motion)

    if transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldAvoidObstacle(
            player):  # Has potential to go into box!
        return player.goLater('avoidObstacle')

    if not transitions.shouldChaseAroundBox(player):
        player.shouldChaseAroundBox += 1
    else:
        player.shouldChaseAroundBox = 0
    if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX:
        return player.goLater('chase')

    ball = player.brain.ball
    my = player.brain.my
    if my.x > NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if ball.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_TOP_Y +
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))

        if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_BOTTOM_Y -
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))

    if my.x < NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if my.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_TOP_Y +
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))

        if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation(
                    NogginConstants.MY_GOALBOX_RIGHT_X +
                    constants.GOALBOX_OFFSET,
                    NogginConstants.MY_GOALBOX_BOTTOM_Y -
                    constants.GOALBOX_OFFSET, NogginConstants.MY_GOAL_HEADING))
    return player.stay()
Exemplo n.º 2
0
def chaseAroundBox(player):
    if player.firstFrame():
        player.shouldNotChaseAroundBox = 0

        player.brain.CoA.setRobotGait(player.brain.motion)

    if transitions.shouldKick(player):
        return player.goNow('waitBeforeKick')
    elif transitions.shouldScanFindBall(player):
        return player.goLater('scanFindBall')
    elif transitions.shouldAvoidObstacle(player): # Has potential to go into box!
        return player.goLater('avoidObstacle')

    if not transitions.shouldChaseAroundBox(player):
        player.shouldChaseAroundBox += 1
    else :
        player.shouldChaseAroundBox = 0
    if player.shouldChaseAroundBox > constants.STOP_CHASING_AROUND_BOX:
        return player.goLater('chase')

    ball = player.brain.ball
    my = player.brain.my
    if my.x > NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if ball.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X +
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOALBOX_TOP_Y +
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOAL_HEADING ))

        if ball.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation(NogginConstants.MY_GOALBOX_RIGHT_X +
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOALBOX_BOTTOM_Y -
                              constants.GOALBOX_OFFSET,
                              NogginConstants.MY_GOAL_HEADING ))

    if my.x < NogginConstants.MY_GOALBOX_RIGHT_X:
        # go to corner nearest ball
        if my.y > NogginConstants.MY_GOALBOX_TOP_Y:
            player.brain.nav.goTo(
                RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X +
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOALBOX_TOP_Y +
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOAL_HEADING ))

        if my.y < NogginConstants.MY_GOALBOX_BOTTOM_Y:
            player.brain.nav.goTo(
                RobotLocation( NogginConstants.MY_GOALBOX_RIGHT_X +
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOALBOX_BOTTOM_Y -
                               constants.GOALBOX_OFFSET,
                               NogginConstants.MY_GOAL_HEADING ))
    return player.stay()
Exemplo n.º 3
0
def avoidObstacle(player):
    """
    If we detect something in front of us, dodge it
    """
    if player.firstFrame():
        player.doneAvoidingCounter = 0
        player.printf(player.brain.sonar)

        player.brain.CoA.setRobotGait(player.brain.motion)

        if (transitions.shouldAvoidObstacleLeft(player) and
            transitions.shouldAvoidObstacleRight(player)):
            # Backup
            player.printf("Avoid by backup");
            player.setSpeed(constants.DODGE_BACK_SPEED, 0, 0)

        elif transitions.shouldAvoidObstacleLeft(player):
            # Dodge right
            player.printf("Avoid by right dodge");
            player.setSpeed(0, constants.DODGE_RIGHT_SPEED, 0)

        elif transitions.shouldAvoidObstacleRight(player):
            # Dodge left
            player.printf("Avoid by left dodge");
            player.setSpeed(0, constants.DODGE_LEFT_SPEED, 0)

    if not transitions.shouldAvoidObstacle(player):
        player.doneAvoidingCounter += 1
    else :
        player.doneAvoidingCounter -= 1
        player.doneAvoidingCounter = max(0, player.doneAvoidingCounter)

    if player.doneAvoidingCounter > constants.DONE_AVOIDING_FRAMES_THRESH:
        player.shouldAvoidObstacleRight = 0
        player.shouldAvoidObstacleLeft = 0
        player.stopWalking()
        return player.goLater(player.lastDiffState)

    return player.stay()
Exemplo n.º 4
0
def avoidObstacle(player):
    """
    If we detect something in front of us, dodge it
    """
    if player.firstFrame():
        player.doneAvoidingCounter = 0
        player.printf(player.brain.sonar)

        player.brain.CoA.setRobotGait(player.brain.motion)

        if (transitions.shouldAvoidObstacleLeft(player)
                and transitions.shouldAvoidObstacleRight(player)):
            # Backup
            player.printf("Avoid by backup")
            player.setWalk(constants.DODGE_BACK_SPEED, 0, 0)

        elif transitions.shouldAvoidObstacleLeft(player):
            # Dodge right
            player.printf("Avoid by right dodge")
            player.setWalk(0, constants.DODGE_RIGHT_SPEED, 0)

        elif transitions.shouldAvoidObstacleRight(player):
            # Dodge left
            player.printf("Avoid by left dodge")
            player.setWalk(0, constants.DODGE_LEFT_SPEED, 0)

    if not transitions.shouldAvoidObstacle(player):
        player.doneAvoidingCounter += 1
    else:
        player.doneAvoidingCounter -= 1
        player.doneAvoidingCounter = max(0, player.doneAvoidingCounter)

    if player.doneAvoidingCounter > constants.DONE_AVOIDING_FRAMES_THRESH:
        player.shouldAvoidObstacleRight = 0
        player.shouldAvoidObstacleLeft = 0
        player.stopWalking()
        return player.goLater(player.lastDiffState)

    return player.stay()
Exemplo n.º 5
0
def shouldAvoidObstacle(player):
    return ChaseBallTransitions.shouldAvoidObstacle(player) and \
        (player.brain.nav.currentState == 'omniWalkToPoint' or
         player.brain.nav.currentState == 'walkStraightToPoint')
Exemplo n.º 6
0
def shouldAvoidObstacle(player):
    return ChaseBallTransitions.shouldAvoidObstacle(player) and \
        (player.brain.nav.currentState == 'omniWalkToPoint' or
         player.brain.nav.currentState == 'walkStraightToPoint')