From 8cdb8164095cea2d5a916fadc12544df2f1d2885 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 8 Jun 2024 21:00:00 +0200 Subject: [PATCH] Refactored --- tic_tac_toe.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tic_tac_toe.py b/tic_tac_toe.py index 232d6e4..31ed24c 100644 --- a/tic_tac_toe.py +++ b/tic_tac_toe.py @@ -119,10 +119,14 @@ class APlayer(object): class MachinePlayer(APlayer): - def __init__(self, mark='X', with_debug=False): + def __init__(self, mark='X', with_debug=False, values=None): APlayer.__init__(self, mark) self.with_debug = with_debug - self.values = {} + if values is None: + self.values = {} + else: + self.values = values + def get_value(self, state): try: @@ -230,8 +234,11 @@ def play(player_provider: PlayerProvider, k_max=10000, with_print=False): move += 1 -with_debug = True -players = PlayerProvider(MachinePlayer(mark='X', with_debug=with_debug), MachinePlayer(mark='O', with_debug=with_debug)) -play(players, 10000, with_debug) +px = MachinePlayer(mark='X') +po = MachinePlayer(mark='O') +players = PlayerProvider(px, po) +play(players, 10000, False) + +players = PlayerProvider(MachinePlayer(mark='X', with_debug=True, values=px.values), MachinePlayer(mark='O', with_debug=True, values=po.values)) play(players, 100, True)