def gameStatus(self, status, playerStatus, players, passengers): """ Called to send an update message to this A.I. We do NOT have to send a response. status -- The status message. playerStatus -- The player this status is about. THIS MAY NOT BE YOU. players -- The status of all players. passengers -- The status of all passengers. """ # bugbug - Framework.cs updates the object's in this object's Players, # Passengers, and Companies lists. This works fine as long as this app # is single threaded. However, if you create worker thread(s) or # respond to multiple status messages simultaneously then you need to # split these out and synchronize access to the saved list objects. try: # bugbug - we return if not us because the below code is only for # when we need a new path or our limo hits a bus stop. If you want # to act on other players arriving at bus stops, you need to # remove this. But make sure you use self.me, not playerStatus for # the Player you are updating (particularly to determine what tile # to start your path from). if playerStatus != self.me: return ptDest = None pickup = [] if status == "UPDATE": return elif ((status == "PASSENGER_NO_ACTION" or status == "NO_PATH") and playerStatus == self.me): if playerStatus.limo.passenger is None: pickup = self.allPickups(self.me, passengers, players) ptDest = pickup[0].lobby.busStop else: ptDest = playerStatus.limo.passenger.destination.busStop elif (status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED"): pickup = self.allPickups(self.me, passengers, players) ptDest = pickup[0].lobby.busStop elif status == "PASSENGER_REFUSED": pickup = self.allPickups(self.me, passengers, players) ptDest = pickup[0].lobby elif (status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP"): pickup = self.allPickups(self.me, passengers, players) ptDest = self.me.limo.passenger.destination.busStop else: raise TypeError("unknown status %r", status) # get the path from where we are to the dest. path = self.calculatePathPlus1(self.me, ptDest) sendOrders(self, "move", path, pickup) except Exception as e: traceback.print_exc() printrap ("somefin' bad, foo'!") raise e
def setup(self, gMap, me, allPlayers, companies, passengers, client): """ Called at the start of the game; initializes instance variables. gMap -- The game map. me -- Your Player object. allPlayers -- List of all Player objects (including you). companies -- The companies on the map. passengers -- The passengers that need a lift. client -- TcpClient to use to send orders to the server. """ self.gameMap = gMap self.players = allPlayers self.me = me self.companies = companies self.passengers = passengers self.client = client self.pickup = pickup = self.allPickups(me, passengers) self.calcDists() # i = 3 #self.makeId(x1,y1,d1) # j = 8 #self.makeId(x2,y2,d2) # r = nx.shortest_path(self.G, None, None, weight="weight") # print r # get the path from where we are to the dest. path = self.calculatePathPlus1(me, pickup[0].lobby.busStop) sendOrders(self, "ready", path, pickup)
def setup(self, gMap, me, allPlayers, companies, passengers, client, stores, powerUpDeck, framework): """ Called at the start of the game; initializes instance variables. gMap -- The game map. me -- Your Player object. allPlayers -- List of all Player objects (including you). companies -- The companies on the map. passengers -- The passengers that need a lift. client -- TcpClient to use to send orders to the server. stores -- All the coffee stores. powerUpDeck -- The powerups this player has in their hand (may have to wait before playing it). powerUpHand -- The powerups this player can draw. myPassenger -- The passenger currently in my limo, none to start. MAX_TRIPS_BEFORE_REFILL -- The maximum number of trips allowed before a refill is required. """ self.framework = framework self.gameMap = gMap self.players = allPlayers self.me = me self.companies = companies self.passengers = passengers self.client = client self.stores = stores self.powerUpDeck = powerUpDeck self.powerUpHand = [] self.myPassenger = None self.MAX_TRIPS_BEFORE_REFILL = 3 self.status = dict() # Set of status flags self.carrying = { player.guid : None for player in self.players } self.carried = { player.guid : set() for player in self.players } # self.pickup = pickup = dest.allPickups(me, passengers) target = dest.getBestStrategy(self) # get the path from where we are to the dest. path = self.calculatePathPlus1(me, target) sendOrders(self, "ready", path, self.pickup)
def setup(self, gMap, me, allPlayers, companies, passengers, client, stores, powerUpDeck, framework): """ Called at the start of the game; initializes instance variables. gMap -- The game map. me -- Your Player object. allPlayers -- List of all Player objects (including you). companies -- The companies on the map. passengers -- The passengers that need a lift. client -- TcpClient to use to send orders to the server. stores -- All the coffee stores. powerUpDeck -- The powerups this player has in their hand (may have to wait before playing it). powerUpHand -- The powerups this player can draw. myPassenger -- The passenger currently in my limo, none to start. MAX_TRIPS_BEFORE_REFILL -- The maximum number of trips allowed before a refill is required. """ self.framework = framework self.gameMap = gMap self.players = allPlayers self.me = me self.companies = companies self.passengers = passengers self.client = client self.stores = stores self.powerUpManager = powerUpManager(self, powerUpDeck) self.powerUpHand = self.powerUpManager.hand self.powerUpDeck = self.powerUpManager.deck print self.powerUpManager self.myPassenger = None self.MAX_TRIPS_BEFORE_REFILL = 3 self.coffee_lock = False self.coffee_state = 0 self.pickup = pickup = self.allPickups(me, passengers) # get the path from where we are to the dest. path = self.calculatePathPlus1(me, pickup[0].lobby.busStop) sendOrders(self, "ready", path, pickup)
def setup(self, gMap, me, allPlayers, companies, passengers, client): """ Called at the start of the game; initializes instance variables. gMap -- The game map. me -- Your Player object. allPlayers -- List of all Player objects (including you). companies -- The companies on the map. passengers -- The passengers that need a lift. client -- TcpClient to use to send orders to the server. """ self.gameMap = gMap self.players = allPlayers self.me = me self.companies = companies self.passengers = passengers self.client = client self.pickup = pickup = self.allPickups(me, passengers, self.players) # get the path from where we are to the dest. path = self.calculatePathPlus1(me, pickup[0].lobby.busStop) sendOrders(self, "ready", path, pickup)
def gameStatus(self, status, playerStatus): """ Called to send an update message to this A.I. We do NOT have to send a response. status -- The status message. playerStatus -- The player this status is about. THIS MAY NOT BE YOU. players -- The status of all players. passengers -- The status of all passengers. """ # bugbug - Framework.cs updates the object's in this object's Players, # Passengers, and Companies lists. This works fine as long as this app # is single threaded. However, if you create worker thread(s) or # respond to multiple status messages simultaneously then you need to # split these out and synchronize access to the saved list objects. try: # bugbug - we return if not us because the below code is only for # when we need a new path or our limo hits a bus stop. If you want # to act on other players arriving at bus stops, you need to # remove this. But make sure you use self.me, not playerStatus for # the Player you are updating (particularly to determine what tile # to start your path from). if playerStatus != self.me: return ptDest = None pickup = [] if status == "UPDATE": self.maybePlayPowerUp() return self.displayStatus(status, playerStatus) if (status == "PASSENGER_NO_ACTION" or status == "NO_PATH"): if self.me.limo.passenger is None: pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop else: ptDest = self.me.limo.passenger.destination.busStop elif (status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED"): pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop elif status == "PASSENGER_REFUSED_ENEMY": ptDest = rand.choice(filter(lambda c: c != self.me.limo.passenger.destination, self.companies)).busStop elif (status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP"): pickup = self.allPickups(self.me, self.passengers) ptDest = self.me.limo.passenger.destination.busStop # coffee store override if(status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED"): if(self.me.limo.coffeeServings <= 0): ptDest = rand.choice(self.stores).busStop elif(status == "PASSENGER_REFUSED_NO_COFFEE" or status == "PASSENGER_DELIVERED_AND_PICK_UP_REFUSED"): ptDest = rand.choice(self.stores).busStop elif(status == "COFFEE_STORE_CAR_RESTOCKED"): pickup = self.allPickups(self.me, self.passengers) if len(pickup) != 0: ptDest = pickup[0].lobby.busStop if(ptDest == None): return self.displayOrders(ptDest) # get the path from where we are to the dest. path = self.calculatePathPlus1(self.me, ptDest) sendOrders(self, "move", path, pickup) except Exception as e: print traceback.format_exc() raise e
def gameStatus(self, status, playerStatus): """ Called to send an update message to this A.I. We do NOT have to send a response. status -- The status message. playerStatus -- The player this status is about. THIS MAY NOT BE YOU. players -- The status of all players. passengers -- The status of all passengers. """ # bugbug - Framework.cs updates the object's in this object's Players, # Passengers, and Companies lists. This works fine as long as this app # is single threaded. However, if you create worker thread(s) or # respond to multiple status messages simultaneously then you need to # split these out and synchronize access to the saved list objects. try: # bugbug - we return if not us because the below code is only for # when we need a new path or our limo hits a bus stop. If you want # to act on other players arriving at bus stops, you need to # remove this. But make sure you use self.me, not playerStatus for # the Player you are updating (particularly to determine what tile # to start your path from). if status == "PASSENGER_PICKED_UP": self.carrying[playerStatus.guid] = playerStatus.limo.passenger if status == "PASSENGER_ABANDONED": self.carrying[playerStatus.guid] = None if status == "PASSENGER_DELIVERED": self.carried[playerStatus.guid].add(self.carrying[playerStatus.guid]) self.carrying[playerStatus.guid] = None if status == "PASSENGER_DELIVERED_AND_PICKED_UP": self.carried[playerStatus.guid].add(self.carrying[playerStatus.guid]) self.carrying[playerStatus.guid] = playerStatus.limo.passenger if playerStatus != self.me: # print("Ignoring player status...") return ptDest = None pickup = [] if status == "UPDATE": print(self.pickup) # print("Current passenger: {}".format(self.me.limo.passenger)) # print(self.me.limo.path) # print("UPDATE TICK") # self.maybePlayPowerUp() return self.displayStatus(status, playerStatus) if (status == "PASSENGER_NO_ACTION" or status == "NO_PATH"): if self.me.limo.passenger is None: ptDest = dest.getBestStrategy(self) else: print("WHY NO PATH") elif (status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED"): ptDest = dest.getBestStrategy(self) elif status == "PASSENGER_REFUSED_ENEMY": ptDest = dest.handleRefusedEnemy(self) elif (status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP"): ptDest = dest.getBestStrategy(self) # ptDest = handleCurrentPassenger(self) elif(status == "PASSENGER_REFUSED_NO_COFFEE" or status == "PASSENGER_DELIVERED_AND_PICK_UP_REFUSED"): # coffee store override print("Passenger refused coffee!") ptDest = planCoffee(self) elif(status == "COFFEE_STORE_CAR_RESTOCKED"): ptDest = dest.getBestStrategy(self) if(ptDest == None): print("No path set!") return self.displayOrders(ptDest) # get the path from where we are to the dest. path = self.calculatePathPlus1(self.me, ptDest) print("Pickup: {}".format(self.pickup)) sendOrders(self, "move", path, self.pickup) except Exception as e: print traceback.format_exc() raise e
def gameStatus(self, status, playerStatus): """ Called to send an update message to this A.I. We do NOT have to send a response. status -- The status message. playerStatus -- The player this status is about. THIS MAY NOT BE YOU. players -- The status of all players. passengers -- The status of all passengers. """ if self.me.score < 0.5: self.setOkToPlay() # bugbug - Framework.cs updates the object's in this object's Players, # Passengers, and Companies lists. This works fine as long as this app # is single threaded. However, if you create worker thread(s) or # respond to multiple status messages simultaneously then you need to # split these out and synchronize access to the saved list objects. try: # bugbug - we return if not us because the below code is only for # when we need a new path or our limo hits a bus stop. If you want # to act on other players arriving at bus stops, you need to # remove this. But make sure you use self.me, not playerStatus for # the Player you are updating (particularly to determine what tile # to start your path from). if playerStatus != self.me: if status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP": if playerStatus.limo.passenger == self.me.pickup[0] and self.me.limo.coffeeServings > 0: pickup = self.allPickups(self.me, self.passengers) print "Changing targets because someone else picked up ours" print "Now picking up" print pickup[0] ptDest = pickup[0].lobby.busStop self.displayOrders(ptDest) # get the path from where we are to the dest. path = self.calculatePathPlus1(self.me, ptDest) sendOrders(self, "move", path, pickup) elif self.me.limo.coffeeServings <= 0: print "Gotta get more coffee" path = self.calculatePathPlus1(self.me, self.findClosestStore().busStop) pickup = self.allPickups(self.me, self.passengers) sendOrders(self, "move", path, pickup) return ptDest = None pickup = [] if status == "UPDATE" and self.me.limo.coffeeServings > 0: self.maybePlayPowerUp() if self.me.limo.passenger: # if passenger in limo if self.enemyAtDestination(self.me.limo.passenger): print "enemy deposited at destination, changing passenger" pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop self.displayOrders(ptDest) # get the path from where we are to the dest. path = self.calculatePathPlus1(self.me, ptDest) sendOrders(self, "move", path, pickup) elif self.me.limo.coffeeServings <= 0: # no passenger in limo print "No passenger in limo. Heading for " print self.me.pickup[0] elif self.me.limo.coffeeServings <= 0: print "Gotta get more coffee" path = self.calculatePathPlus1(self.me, self.findClosestStore().busStop) pickup = self.allPickups(self.me, self.passengers) sendOrders(self, "move", path, pickup) return self.displayStatus(status, playerStatus) print "status:" print status if status == "PASSENGER_NO_ACTION" or status == "NO_PATH": if self.me.limo.passenger is None: pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop print "Now picking up" print pickup[0] else: ptDest = self.me.limo.passenger.destination.busStop elif status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED": pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop self.setOkToPlay() elif status == "PASSENGER_REFUSED_ENEMY": pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop self.setOkToPlay() elif status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP": pickup = self.allPickups(self.me, self.passengers) ptDest = self.me.limo.passenger.destination.busStop self.setOkToPlay() # coffee store override if ( status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED" ): if self.me.limo.coffeeServings <= 0: ptDest = self.findClosestStore().busStop self.setOkToPlay() elif status == "PASSENGER_REFUSED_NO_COFFEE" or status == "PASSENGER_DELIVERED_AND_PICK_UP_REFUSED": ptDest = self.findClosestStore().busStop self.setOkToPlay() elif status == "COFFEE_STORE_CAR_RESTOCKED": pickup = self.allPickups(self.me, self.passengers) if len(pickup) != 0: ptDest = pickup[0].lobby.busStop self.setOkToPlay() if ptDest == None: return self.displayOrders(ptDest) # get the path from where we are to the dest. path = self.calculatePathPlus1(self.me, ptDest) sendOrders(self, "move", path, pickup) except Exception as e: print traceback.format_exc() raise e
def gameStatus(self, status, playerStatus): """ Called to send an update message to this A.I. We do NOT have to send a response. status -- The status message. playerStatus -- The player this status is about. THIS MAY NOT BE YOU. players -- The status of all players. passengers -- The status of all passengers. """ # bugbug - Framework.cs updates the object's in this object's Players, # Passengers, and Companies lists. This works fine as long as this app # is single threaded. However, if you create worker thread(s) or # respond to multiple status messages simultaneously then you need to # split these out and synchronize access to the saved list objects. try: # bugbug - we return if not us because the below code is only for # when we need a new path or our limo hits a bus stop. If you want # to act on other players arriving at bus stops, you need to # remove this. But make sure you use self.me, not playerStatus for # the Player you are updating (particularly to determine what tile # to start your path from). if playerStatus != self.me: return ptDest = None pickup = [] path = None if status == "UPDATE": self.drawCards() self.updateStategy() return self.displayStatus(status, playerStatus) if not self.coffee_lock: # get passengers if (status == "PASSENGER_NO_ACTION" or status == "NO_PATH"): if self.me.limo.passenger is None: pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop else: ptDest = self.me.limo.passenger.destination.busStop elif (status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED"): pickup = self.allPickups(self.me, self.passengers) ptDest = pickup[0].lobby.busStop elif status == "PASSENGER_REFUSED_ENEMY": all_but_current = filter(lambda c: c != self.me.limo.passenger.destination, self.companies) closest_next = self.findClosest(all_but_current) ptDest = closest_next['destination'] path = closest_next['path'] elif (status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP"): pickup = self.allPickups(self.me, self.passengers) ptDest = self.me.limo.passenger.destination.busStop # coffee store override if(status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED"): if(self.me.limo.coffeeServings <= 0): self.updateCoffeeState(True, 1, -1) elif (self.me.limo.coffeeServings == 1 and bool(rand.getrandbits(1))): self.updateCoffeeState(True, 1, 15) elif(status == "PASSENGER_REFUSED_NO_COFFEE" or status == "PASSENGER_DELIVERED_AND_PICK_UP_REFUSED"): self.updateCoffeeState(True, 1, -1) elif(status == "COFFEE_STORE_CAR_RESTOCKED"): self.updateCoffeeState(False, 0, -1) pickup = self.allPickups(self.me, self.passengers) if len(pickup) != 0: ptDest = pickup[0].lobby.busStop if self.coffee_lock and self.coffee_state is 1: print "<--------- COFFEE LOCK IN EFFECT :D" pickup = [] closest_store = self.findClosestStore() # distance mod if self.coffee_dist == -1 or closest_store['distance'] < self.coffee_dist: ptDest = closest_store['destination'] path = closest_store['path'] self.updateCoffeeState(True, 2, -1) else: print "<--------- COFFEE too far.. Will get it later" self.updateCoffeeState(False, 0, -1) if(ptDest == None): return self.displayOrders(ptDest) # get the path from where we are to the dest. if path is None: path = self.calculatePathPlus1(self.me, ptDest) sendOrders(self, "move", path, pickup) except Exception as e: print traceback.format_exc() raise e
def gameStatus(self, status, playerStatus, players, passengers): """ Called to send an update message to this A.I. We do NOT have to send a response. status -- The status message. playerStatus -- The player this status is about. THIS MAY NOT BE YOU. players -- The status of all players. passengers -- The status of all passengers. """ # bugbug - Framework.cs updates the object's in this object's Players, # Passengers, and Companies lists. This works fine as long as this app # is single threaded. However, if you create worker thread(s) or # respond to multiple status messages simultaneously then you need to # split these out and synchronize access to the saved list objects. # bugbug - we return if not us because the below code is only for # when we need a new path or our limo hits a bus stop. If you want # to act on other players arriving at bus stops, you need to # remove this. But make sure you use self.me, not playerStatus for # the Player you are updating (particularly to determine what tile # to start your path from). print ("hello") self.status = status self.playerStatus = playerStatus self.players = players self.passenger = passengers if playerStatus != self.me: return print ("Now i'm me") ptDest = None pickup = [] if status == "UPDATE": return elif status == "PASSENGER_NO_ACTION" or status == "NO_PATH": if playerStatus.limo.passenger is None: pickup = self.allPickups(playerStatus, passengers) ptDest = pickup[0].lobby.busStop else: ptDest = playerStatus.limo.passenger.destination.busStop elif status == "PASSENGER_DELIVERED" or status == "PASSENGER_ABANDONED": pickup = self.allPickups(playerStatus, passengers) ptDest = pickup[0].lobby.busStop elif status == "PASSENGER_REFUSED": ptDest = random.choice( filter(lambda c: c != playerStatus.limo.passenger.destination, self.companies) ).busStop elif status == "PASSENGER_DELIVERED_AND_PICKED_UP" or status == "PASSENGER_PICKED_UP": pickup = self.allPickups(playerStatus, passengers) ptDest = playerStatus.limo.passenger.destination.busStop else: raise TypeError("unknown status %r", status) print ("1") pprint(self.companies) pprint(passengers) combs = [] for ceo in passengers: for end in self.companies: print ("hi") combs += [(self.getCost(ceo, end), ceo, end)] print ("2") pprint(combs) self.getCost(passengers[0], passengers[0].destination) # get the path from where we are to the dest. path = self.calculatePathPlus1(playerStatus, ptDest) sendOrders(self, "move", path, pickup)