def __init__(self, teamname, goalie=False, connect=True): # Player attributes self.stamina = 0 self.speed = 0 self.effort = 0 self.head_angle = 0 self.tackled = 0 self.game_status = "before_kick_off" # Initial mode self.observables = [] self.side = 'l' # l or r self.unum = None # Uniform number # Instantiate parser to update info self.parser = Parser() # Set server IP # With is a safety wrapper with open("ip_address.txt", "r") as file: self.ip = file.read() if connect: # Server on port 6000 by default self.init_port = 6000 self.serverAddressPort = (self.ip, self.init_port) # Create client via UDP socket self.UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) # Initialize player on team if not goalie: self.initString = "(init " + teamname + " (version 16)" + ")" else: self.initString = "(init " + teamname + " (version 16) (goalie))" self.send_init(self.initString) # Update unum then get formation self.update_info() self.std_pos = Formations.standard_formation(self.unum) self.gchar_pos = Formations.g_letter_wrapper(self.unum, self.side) self.gchar_pos2 = Formations.shift_letter(self.gchar_pos, self.side) # Set initial formation self.send_action('(move {} {})'.format(self.std_pos[0], self.std_pos[1]))
def sTwoDown(team): # Game Ready Setup if team.brain.game.state == NogginConstants.GAME_READY: # team is kicking off return ['sThreeDown'] + Formations.fReady(team) # Kickoff Formations if (team.brain.game.getTimeSincePlay() < PBConstants.KICKOFF_FORMATION_TIME): return ['sThreeDown'] + Formations.fOneKickoff(team) # Formation for ball in our goal box elif team.shouldUseDubD(): return ['sThreeDown'] + Formations.fDubD(team) elif (team.brain.timeSinceBallSeen() > PBConstants.FINDER_TIME_THRESH and team.brain.game.getTimeSinceUnpenalized() > PBConstants.FINDER_TIME_THRESH): return ['sSpread'] + Formations.fFinder(team) return ['sThreeDown'] + Formations.fThreeDown(team)
def sSpread(team): ''' This is our standard strategy. Based around the 2007 with changes for the middie. ''' # Game Ready Setup if team.brain.game.state == NogginConstants.GAME_READY: # team is kicking off return ['sSpread'] + Formations.fReady(team) # Game Playing Formations elif team.brain.game.state == NogginConstants.GAME_PLAYING: # Kickoff Formations if (team.brain.game.getTimeSincePlay() < PBConstants.KICKOFF_FORMATION_TIME): # Kickoff play if PBConstants.KICKOFF_PLAY: return ['sSpread'] + Formations.fKickoffPlay(team) # Kickoff else: return ['sSpread'] + Formations.fKickoff(team) # Formation for ball in our goal box elif team.shouldUseDubD(): return ['sSpread'] + Formations.fDubD(team) # ball hasn't been seen by me or teammates in a while elif (team.brain.timeSinceBallSeen() > PBConstants.FINDER_TIME_THRESH and team.brain.game.getTimeSinceUnpenalized() > PBConstants.FINDER_TIME_THRESH): return ['sSpread'] + Formations.fFinder(team) # Standard spread formation return ['sSpread'] + Formations.fSpread(team)
def sTestChaser(team): return ['sTestChaser'] + Formations.fTestChaser(team)
def sTestMiddie(team): return ['sTestMiddie'] + Formations.fTestMiddie(team)
def sTestOffender(team): return ['sTestOffender'] + Formations.fTestOffender(team)