Exemplo n.º 1
0
def shouldIBeStriker():
    # If there are 2 or less forwards alive, it is better that
    # non-attacker be a defender.
    if hTeam.forwardAlive() <= 2:
        return False

    # If there is an attacker and no striker, then be a striker.
    numAttacker = hTeam.countAttacker()
    numStriker = hTeam.countStriker()
    if numAttacker == 1 and numStriker == 0:
        return True
    # If there is no attacker and a striker, then be a striker.
    if numAttacker == 0 and numStriker == 1:
        return True

    # If my estimate time to reach striker pos is the smallest among
    # all the forwards except an attacker.
    selfLoc = Global.selfLoc
    myEstimateTime = hTrack.timeToReachStrikerPos(selfLoc.getX(),\
                                                 selfLoc.getY(),\
                                                 selfLoc.getHeading(),\
                                                 Global.myLastRole == Constant.STRIKER)
    for i in Global.otherValidForwards:
        mate = Global.teamPlayers[i]
        if not mate.isAttacker():

            mateLoc = Global.teammatesLoc[i]
            mateEstimateTime = hTrack.timeToReachStrikerPos(mateLoc.getX(),\
                                                       mateLoc.getY(),\
                                                       mateLoc.getHeading(),\
                                                       mate.isStriker())
            if myEstimateTime > mateEstimateTime:
                break
    else:
        # When this else branch is reached, it means I can be a
        # striker. But before that, I should check if I should
        # break symmetry when there are more than 1 striker on the
        # field.
        if Global.myLastRole == Constant.STRIKER\
            and Global.myRoleCounter > SYMMETRY_BREAK_COUNT:

            for i in Global.otherValidForwards:
                mate = Global.teamPlayers[i]
                if mate.isStriker()\
                    and mate.getRoleCounter() > SYMMETRY_BREAK_COUNT:

                    if shouldIBreakStrikerSymmetry(i):
                        return False
            else:
                return True

        else:
            return True

    return False
Exemplo n.º 2
0
def shouldIBeSupporter():
    # If there are 2 or less forwards alive, it is better that
    # non-attacker to be a defender.
    if hTeam.forwardAlive() <= 2:
        return False

    # If there is an attacker and no supporter, then be a supporter.
    numAttacker = hTeam.countAttacker()
    numSupporter = hTeam.countSupporter()
    if numAttacker == 1 and numSupporter == 0:
        return True
    # If there is no attacker and a supporter, then be a supporter.
    if numAttacker == 0 and numSupporter == 1:
        return True

    # If you are the furthest back in the field, then be a defender instead.
    if hTeam.amIFurthestBack(30):
        return False

    # If my estimate time to reach defender pos is the largest among
    # all the forwards except an attacker.
    selfLoc = Global.selfLoc
    myEstimateTime = hTrack.timeToReachDefenderPos(selfLoc.getX(),\
                                         selfLoc.getY(),\
                                         selfLoc.getHeading(),\
                                         Global.myLastRole == Constant.DEFENDER)
    for i in Global.otherValidForwards:
        mate = Global.teamPlayers[i]
        if not mate.isAttacker():

            mateLoc = Global.teammatesLoc[i]
            mateEstimateTime = hTrack.timeToReachDefenderPos(mateLoc.getX(),\
                                                       mateLoc.getY(),\
                                                       mateLoc.getHeading(),\
                                                       mate.isDefender())

            # hysterisis introduced for furthest back.
            if myEstimateTime < mateEstimateTime and hTeam.amIFurthestBack(0):
                break  # It returns False
    else:
        # When this else branch is reached, it means I can be a
        # supporter. But before that, I should check if I should
        # break symmetry when there are more than 1 supporter on the
        # field.
        if Global.myLastRole == Constant.SUPPORTER\
            and Global.myRoleCounter > pForward.SYMMETRY_BREAK_COUNT:

            for i in Global.otherValidForwards:
                mate = Global.teamPlayers[i]
                if mate.isSupporter()\
                    and mate.getRoleCounter() > pForward.SYMMETRY_BREAK_COUNT:

                    if pForward.shouldIBreakSupporterSymmetry(i):
                        return False
            else:
                return True

        else:
            return True

    return False
Exemplo n.º 3
0
def shouldIBeAttacker():

    # If there is no other attacker then be an attacker.
    numAttacker = hTeam.countAttacker()
    if numAttacker == 0:
        #print "Criteria A"
        #print "Global.otherValidTeammates : ", Global.otherValidTeammates
        #print "no other attackers"
        return True

    # There is at least one other attacker, but if they can't see the ball
    # and I can and I'm close to the ball then be attacker
    numAttacker = hTeam.countAttacker(True)
    if numAttacker == 0 and Global.lostBall < Constant.LOST_BALL_LAST_VISUAL \
            and Global.ballD < VBALL_ATTACK_DIST:

        #print "Criteria B"
        #print "Global.lostBall < Constant.LOST_BALL_LAST_VISUAL ", (Global.lostBall < Constant.LOST_BALL_LAST_VISUAL)
        #print "numAttacker == 0 ", (numAttacker == 0)
        #print "Global.ballD < VBALL_ATTACK_DIST ", (Global.ballD < VBALL_ATTACK_DIST)
        #print "Global.otherValidTeammates : ", Global.otherValidTeammates
        return True

    # If I am grabbing a ball, then continue as an attacker.
    if sGrab.isGrabbed\
        or sGrab.grabbingCount > 0\
        or sFindBall.shouldIForce():

        #print "Criteria C"
        #print "sGrab.isGrabbed ", sGrab.isGrabbed
        #print "sGrab.grabbingCount ", sGrab.grabbingCount
        #print "sFindBall.shouldIForce() ", sFindBall.shouldIForce()
        #print "Global.otherValidTeammates : ", Global.otherValidTeammates
        return True

    # If my estimate time to reach ball is the smallest among all the
    # forwards, then be an attacker.
    myEstimateTime = hTrack.timeToReachBall()
    for i in Global.otherValidForwards:
        mate = Global.teamPlayers[i]

        mateEstimateTime = mate.getTimeToReachBall()
        if myEstimateTime > mateEstimateTime\
            and myEstimateTime > 1500:
            break
    else:
        # When this else branch is reached, it means I can be an
        # attacker. But before that, I should check if I should
        # break symmetry when there are more than 1 attacker on the
        # field.
        if Global.myLastRole == Constant.ATTACKER\
            and Global.myRoleCounter > SYMMETRY_BREAK_COUNT:

            for i in Global.otherValidForwards:
                mate = Global.teamPlayers[i]
                if mate.isAttacker()\
                    and mate.getRoleCounter() > SYMMETRY_BREAK_COUNT:

                    if shouldIBreakAttackerSymmetry(i):
                        return False
            else:
                #print "Criteria D"
                #print "Global.otherValidTeammates : ", Global.otherValidTeammates
                return True

        else:
            #print "Criteria E"
            #print "Global.otherValidTeammates : ", Global.otherValidTeammates
            return True

    return False