Add a monitor suggesting moves to players
This commit is contained in:
parent
e07bd78235
commit
be2ab8a702
@ -48,12 +48,15 @@ class Computer(Player):
|
||||
play_round(*cards)
|
||||
return cards
|
||||
|
||||
def search_play(self):
|
||||
def search_play(self, hand=None):
|
||||
if hand is None:
|
||||
hand = self.hand
|
||||
|
||||
importance = self.importance()
|
||||
|
||||
# On regroupe les cartes identiques
|
||||
cardgroup = {}
|
||||
for card in self.hand:
|
||||
for card in hand:
|
||||
if type(card) not in cardgroup:
|
||||
cardgroup[type(card)] = []
|
||||
cardgroup[type(card)].append(card)
|
||||
|
10
server.py
10
server.py
@ -125,6 +125,7 @@ while True:
|
||||
if nameP2 is not None:
|
||||
connP2.send(("\n\nWelcome back! We are at round %d. \033[96m%d citie(s) discovered.\033[0m \033[93m%s\033[0m collected %d cards, you collected %d card(s).\n" % (game.round // 2, game.board.roundCity, game.player1.name, len(game.player1.défausse), len(game.player2.défausse))).encode())
|
||||
|
||||
monitor = opale.computer.Computer(game.board)
|
||||
game.player1.print = functools.partial(writeSocket, connP1)
|
||||
game.player1.input = functools.partial(readSocket, connP1)
|
||||
if type(game.player2) == opale.computer.Computer:
|
||||
@ -163,7 +164,7 @@ while True:
|
||||
game.current_player.print("\033[1mHere is your hand currently:\033[0m %s" % {i+1: game.current_player.hand[i] for i in range(len(game.current_player.hand))})
|
||||
game.current_partner.print("\033[1mHere is your hand currently:\033[0m %s" % {i+1: game.current_partner.hand[i] for i in range(len(game.current_partner.hand))})
|
||||
game.current_partner.print("\n =============:[ Please wait until \033[1;96m" + game.current_player.name + "\033[0m plays... :-) ]:=============\r",None)
|
||||
printWatchers("\n =============:[ Please wait until \033[1;96m" + game.current_player.name + "\033[0m plays... :-) ]:=============\r",None)
|
||||
printWatchers(" =============:[ Waiting \033[1;93m" + game.current_player.name + "\033[0m move... :-) ]:=============\r",None)
|
||||
icards = game.current_player.input("\nChoose one or more card to play: ")
|
||||
pcards = map(lambda x: int(x), icards.split(" "))
|
||||
good = True
|
||||
@ -204,6 +205,10 @@ while True:
|
||||
|
||||
curRound = game.board.roundCity
|
||||
hasDragon = game.current_player.dragonPetrified
|
||||
if type(game.current_player) != opale.computer.Computer:
|
||||
computer_move = monitor.search_play(game.current_player.hand)
|
||||
else:
|
||||
computer_move = None
|
||||
|
||||
try:
|
||||
cards = play_turn()
|
||||
@ -219,6 +224,9 @@ while True:
|
||||
game.current_player.print("\n\033[93m%s\033[0m plays: %s\n" % (game.current_partner.name, cards))
|
||||
printWatchers("\n\033[93m%s\033[0m plays: %s\n" % (game.current_partner.name, cards))
|
||||
game.current_partner.print("\nYou played: %s\n" % (cards))
|
||||
if computer_move is not None:
|
||||
printWatchers("Best move according to \033[96mOpaleIA\033[0m: %s\n" % (computer_move))
|
||||
game.current_partner.print("Your monitor would have played: %s\n" % (computer_move))
|
||||
if game.current_partner.dragonPetrified != hasDragon:
|
||||
game.current_player.print("\n\033[1;93m%s\033[95m takes the petrified dragon!\033[0m\n" % game.current_partner.name)
|
||||
printWatchers("\n\033[1;93m%s\033[95m takes the petrified dragon!\033[0m\n" % game.current_partner.name)
|
||||
|
Loading…
Reference in New Issue
Block a user