Exemplo n.º 1
0
def tick():
    """Each tick, update your beliefs about the world then decide what action to
    take based on this"""
    updatePositions()
    #playBall()
    # test out each individual function by commenting the above line
    # and uncommenting one of the following:
    #
    collectBall()
    #passBall()
    #confuseEnemy()
    #shoot()
    #receivePass()
    #guardGoal()
    #blockPass()
    #
    print
    print(me.goal)
    print(ball.status)
    print
    threading.Timer(TICK_TIME, tick).start()
Exemplo n.º 2
0
def playBall():
    # if we are closest to ball
    heldByMe = ball.status == BallStatus.me
    heldByAlly = ball.status == BallStatus.ally
    heldByEnemyA = ball.status == BallStatus.enemyA
    heldByEnemyB = ball.status == BallStatus.enemyB
    ballFree = ball.status == BallStatus.free

    # If the enemy has the ball
    if heldByEnemyA or heldByEnemyB:
        # if I'm closer to our goal than the ally, go defend it
        if me.distance(ourGoal) < ally.distance(ourGoal):
            guardGoal()
        # otherwise, intercept the pass
        else:
            blockPass()

    # if we have the ball
    elif heldByMe:
        # shoot if possible
        if lineOfSight(me.currentPoint, opponentGoal):
            shoot()
        # else, try and pass to ally
        elif lineOfSight(me.currentPoint, ally.currentPoint):
            passBall()
        else:
            confuseEnemy()

    # if our ally has the ball, set up a pass
    elif ball.status == BallStatus.ally:
        receivePass()

    # if noone has the ball, go grab the ball or defend
    elif me.distance(ball) < ally.distance(ball) and not isEnemyBox(
            ball.currentPoint):
        collectBall()
    else:
        guardGoal()