Added human player
This commit is contained in:
+7
-12
@@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
from helper import create_empty_state, to_state_string
|
||||
from machine_player import MachinePlayer
|
||||
from human_player import HumanPlayer
|
||||
from player_provider import PlayerProvider
|
||||
import json
|
||||
|
||||
@@ -42,17 +43,13 @@ def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
|
||||
if not has_moved:
|
||||
if with_debug:
|
||||
print(f"{player.mark}: No more moves")
|
||||
if isinstance(player, MachinePlayer):
|
||||
player.reward(0.0)
|
||||
if isinstance(other_player, MachinePlayer):
|
||||
other_player.reward(0.0)
|
||||
run = False
|
||||
if player.has_won(state):
|
||||
if with_debug:
|
||||
print(f"{player.mark}: Has won the game")
|
||||
if isinstance(player, MachinePlayer):
|
||||
player.reward(1.0)
|
||||
if isinstance(other_player, MachinePlayer):
|
||||
other_player.reward(0.0)
|
||||
run = False
|
||||
|
||||
@@ -69,23 +66,21 @@ with open("values_x.json", "r") as fp:
|
||||
with open("values_o.json", "r") as fp:
|
||||
o_values = json.load(fp)
|
||||
|
||||
px = MachinePlayer(mark='X', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1))
|
||||
po = MachinePlayer(mark='O', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1))
|
||||
|
||||
px.assign_values(x_values)
|
||||
po.assign_values(o_values)
|
||||
#px = MachinePlayer(mark='X', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1), values=x_values)
|
||||
px = HumanPlayer(mark='X', name="Jens")
|
||||
po = MachinePlayer(mark='O', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1), values=o_values)
|
||||
|
||||
player_provider = PlayerProvider(px, po)
|
||||
|
||||
do_training = 1
|
||||
if do_training:
|
||||
play(player_provider, 10000, False)
|
||||
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(px.values, fp, indent=0)
|
||||
json.dump(x_values, fp, indent=0)
|
||||
|
||||
with open("values_o.json", "w") as fp:
|
||||
json.dump(po.values, fp, indent=0)
|
||||
json.dump(o_values, fp, indent=0)
|
||||
|
||||
Reference in New Issue
Block a user