Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed errors when running model_vs_game.py #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions game_wrappers/ai_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ def __init__(self, args, env, logger):
self.args = args
self.use_model = True
self.p1_model = None
if args.load_p1_model is '':
self.use_model = False
else:
self.p1_model = init_model(None, args.load_p1_model, args.alg, args, env, logger)

model_path = ''
try:
model_path = args.load_p1_model if args.load_p1_model != '' else args.model_1
except AttributeError:
try:
model_path = args.model_1
except AttributeError:
self.use_model = False
print('No model attribute found')

if model_path and self.use_model:
self.p1_model = init_model(None, model_path, args.alg, args, env, logger)

def predict(self, state, info, deterministic):
if self.use_model:
Expand Down
10 changes: 8 additions & 2 deletions model_vs_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def __init__(self, args, logger, need_display=True):
self.ai_sys = games.wrappers.ai_sys(args, self.p1_env, logger)
if args.model_1 != '' or args.model_2 != '':
models = [args.model_1, args.model_2]
self.ai_sys.SetModels(models)
try:
self.ai_sys.SetModels(models)
except AttributeError:
print("SetModels method not found in ai_sys")

self.need_display = need_display
self.args = args
Expand All @@ -70,7 +73,10 @@ def play(self, continuous=True, need_reset=True):
self.display_env.action_probabilities = []

for i in range(4):
self.display_env.set_ai_sys_info(self.ai_sys)
try:
self.display_env.set_ai_sys_info(self.ai_sys)
except AttributeError:
pass
state, reward, done, info = self.display_env.step(p1_actions)
total_rewards += reward

Expand Down