Refactored
This commit is contained in:
+11
-4
@@ -119,10 +119,14 @@ class APlayer(object):
|
|||||||
|
|
||||||
|
|
||||||
class MachinePlayer(APlayer):
|
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)
|
APlayer.__init__(self, mark)
|
||||||
self.with_debug = with_debug
|
self.with_debug = with_debug
|
||||||
|
if values is None:
|
||||||
self.values = {}
|
self.values = {}
|
||||||
|
else:
|
||||||
|
self.values = values
|
||||||
|
|
||||||
|
|
||||||
def get_value(self, state):
|
def get_value(self, state):
|
||||||
try:
|
try:
|
||||||
@@ -230,8 +234,11 @@ def play(player_provider: PlayerProvider, k_max=10000, with_print=False):
|
|||||||
move += 1
|
move += 1
|
||||||
|
|
||||||
|
|
||||||
with_debug = True
|
px = MachinePlayer(mark='X')
|
||||||
players = PlayerProvider(MachinePlayer(mark='X', with_debug=with_debug), MachinePlayer(mark='O', with_debug=with_debug))
|
po = MachinePlayer(mark='O')
|
||||||
play(players, 10000, with_debug)
|
|
||||||
|
|
||||||
|
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)
|
play(players, 100, True)
|
||||||
|
|||||||
Reference in New Issue
Block a user