+class NetworkPlayer(Player):
+ def __init__(self, colour, network, player):
+ Player.__init__(self, "@network:"+str(network.address), colour)
+ self.player = player
+ self.network = network
+
+ def __str__(self):
+ return "NetworkPlayer<"+str(self.colour)+","+str(self.player)+">"
+
+ def select(self):
+ #debug(str(self) + " select called")
+ if self.player != None:
+ s = self.player.select()
+ self.send_message(str(s[0]) + " " + str(s[1]))
+ else:
+ s = map(int, self.get_response().split(" "))
+ for p in game.players:
+ if p != self and isinstance(p, NetworkPlayer) and p.player == None:
+ p.network.send_message(str(s[0]) + " " + str(s[1]))
+ if s == [-1,-1]:
+ game.final_result = "network terminate"
+ game.stop()
+ return s
+
+ def send_message(self, message):
+ #debug(str(self) + " send_message(\""+str(message)+"\") called")
+ self.network.send_message(message)
+
+ def get_response(self):
+ #debug(str(self) + " get_response() called")
+ s = self.network.get_response()
+ #debug(str(self) + " get_response() returns \""+str(s)+"\"")
+ return s
+
+
+ def get_move(self):
+ #debug(str(self) + " get_move called")
+ if self.player != None:
+ s = self.player.get_move()
+ self.send_message(str(s[0]) + " " + str(s[1]))
+ else:
+ s = map(int, self.get_response().split(" "))
+ for p in game.players:
+ if p != self and isinstance(p, NetworkPlayer) and p.player == None:
+ p.network.send_message(str(s[0]) + " " + str(s[1]))
+
+ if s == [-1,-1]:
+ game.final_result = "network terminate"
+ game.stop()
+ return s
+
+ def update(self, result):
+ #debug(str(self) + " update(\""+str(result)+"\") called")
+ if self.network.server == True:
+ if self.player == None:
+ self.send_message(result)
+ elif self.player != None:
+ result = self.get_response()
+ if result == "-1 -1":
+ game.final_result = "network terminate"
+ game.stop()
+ return "-1 -1"
+ self.board.update(result, deselect=False)
+
+
+
+ if self.player != None:
+ result = self.player.update(result)
+
+ return result
+
+
+
+ def base_player(self):
+ if self.player == None:
+ return self
+ else:
+ return self.player.base_player()
+
+ def quit(self, result):
+ try:
+ self.send_message("-1 -1")
+ except:
+ pass
+