may the flake do it's job
This commit is contained in:
parent
7e1aaf7eee
commit
7b506195cc
6 changed files with 248 additions and 70 deletions
59
blokus.py
59
blokus.py
|
|
@ -2,9 +2,14 @@
|
|||
import random
|
||||
import game
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
###############
|
||||
# Utilities #
|
||||
###############
|
||||
|
||||
BOARD_SIZE = 14
|
||||
|
||||
|
||||
tiles = game.game_tiles()
|
||||
|
||||
|
||||
|
|
@ -32,12 +37,62 @@ def print_game_state(game_state: tuple[game.Board, list[int], list[int]]):
|
|||
print(f"Player 2 tiles left: {p2tiles}")
|
||||
|
||||
|
||||
###################
|
||||
# Game state init #
|
||||
###################
|
||||
|
||||
game_state = (
|
||||
game.Board(),
|
||||
[i for i in range(21)],
|
||||
[i for i in range(21)],
|
||||
)
|
||||
|
||||
###################
|
||||
# RL Utils #
|
||||
###################
|
||||
|
||||
|
||||
class Saver:
|
||||
def __init__(self, results_path, experiment_seed):
|
||||
self.stats_file = {"train": {}, "test": {}}
|
||||
self.exp_seed = experiment_seed
|
||||
self.rpath = results_path
|
||||
|
||||
def get_new_episode(self, mode, episode_no):
|
||||
if mode == "train":
|
||||
self.stats_file[mode][episode_no] = {
|
||||
"loss": [],
|
||||
"actions": [],
|
||||
"errors": [],
|
||||
"errors_noiseless": [],
|
||||
"done_threshold": 0,
|
||||
"bond_distance": 0,
|
||||
"nfev": [],
|
||||
"opt_ang": [],
|
||||
"time": [],
|
||||
"save_circ": [],
|
||||
"reward": [],
|
||||
}
|
||||
elif mode == "test":
|
||||
self.stats_file[mode][episode_no] = {
|
||||
"actions": [],
|
||||
"errors": [],
|
||||
"errors_noiseless": [],
|
||||
"done_threshold": 0,
|
||||
"bond_distance": 0,
|
||||
"nfev": [],
|
||||
"opt_ang": [],
|
||||
"time": [],
|
||||
}
|
||||
|
||||
def save_file(self):
|
||||
np.save(f"{self.rpath}/summary_{self.exp_seed}.npy", self.stats_file)
|
||||
|
||||
def validate_stats(self, episode, mode):
|
||||
assert len(self.stats_file[mode][episode]["actions"]) == len(
|
||||
self.stats_file[mode][episode]["errors"]
|
||||
)
|
||||
|
||||
|
||||
playing = True
|
||||
player = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue