Re-indent with tabs

This commit is contained in:
2024-06-10 20:37:26 +02:00
parent d5b86b057e
commit 285549568d
7 changed files with 298 additions and 293 deletions
+45 -45
View File
@@ -13,58 +13,58 @@ report_counter = REPORT_INTERVAL
def report(k):
global report_counter
if report_counter > 0:
report_counter -= 1
else:
report_counter = REPORT_INTERVAL-1
print(f"Iteration: {k:8d}")
global report_counter
if report_counter > 0:
report_counter -= 1
else:
report_counter = REPORT_INTERVAL-1
print(f"Iteration: {k:8d}")
def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
player_provider.set_debug(with_debug)
for k in range(0, k_max):
report(k)
players = player_provider.choose()
state = create_empty_state()
move = 1
run = True
other_player = players[-1]
while run:
for player in players:
if with_debug:
print(f"---------------------------------------------------")
print(f"- Game {k:06d}, Move {move} -----------------------------")
print(f"---------------------------------------------------")
last_state = state
state, has_moved = player.move(state)
if with_debug:
print(to_state_string(last_state, state))
if not has_moved:
if with_debug:
print(f"{player.mark}: No more moves")
player.reward(0.0)
other_player.reward(0.0)
run = False
if player.has_won(state):
if with_debug:
print(f"{player.mark}: Has won the game")
player.reward(1.0)
other_player.reward(0.0)
run = False
player_provider.set_debug(with_debug)
for k in range(0, k_max):
report(k)
players = player_provider.choose()
state = create_empty_state()
move = 1
run = True
other_player = players[-1]
while run:
for player in players:
if with_debug:
print(f"---------------------------------------------------")
print(f"- Game {k:06d}, Move {move} -----------------------------")
print(f"---------------------------------------------------")
last_state = state
state, has_moved = player.move(state)
if with_debug:
print(to_state_string(last_state, state))
if not has_moved:
if with_debug:
print(f"{player.mark}: No more moves")
player.reward(0.0)
other_player.reward(0.0)
run = False
if player.has_won(state):
if with_debug:
print(f"{player.mark}: Has won the game")
player.reward(1.0)
other_player.reward(0.0)
run = False
other_player = player
if not run:
break
other_player = player
if not run:
break
move += 1
move += 1
with open("values_x.json", "r") as fp:
x_values = json.load(fp)
x_values = json.load(fp)
with open("values_o.json", "r") as fp:
o_values = json.load(fp)
o_values = json.load(fp)
#px = MachinePlayer(mark='X', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1), values=x_values)
px = HumanPlayer(mark='X', name="Jens")
@@ -74,13 +74,13 @@ player_provider = PlayerProvider(px, po)
do_training = 1
if do_training:
play(player_provider, 10000, True)
play(player_provider, 10000, True)
play(player_provider, 10, True)
# Convert and write JSON object to file
with open("values_x.json", "w") as fp:
json.dump(x_values, fp, indent=0)
json.dump(x_values, fp, indent=0)
with open("values_o.json", "w") as fp:
json.dump(o_values, fp, indent=0)
json.dump(o_values, fp, indent=0)