diff --git a/bot.py b/bot.py index eda20b1..f1a2c08 100644 --- a/bot.py +++ b/bot.py @@ -30,7 +30,7 @@ class Bot: def restore_model(self): with self.graph.as_default(): self.network.restore_model() - + def get_session(self): return self.session @@ -40,6 +40,10 @@ class Bot: def get_network(self): return self.network + def make_random_move(self, board, sym, roll): + legal_moves = Board.calculate_legal_states(board, sym, roll) + return random.choice(list(legal_moves)) + def make_move(self, board, sym, roll): # print(Board.pretty(board)) legal_moves = Board.calculate_legal_states(board, sym, roll) @@ -49,4 +53,4 @@ class Bot: #print("Found the best state, being:", np.array(move_scores).argmax()) return best_move_pair -# return random.choice(list(legal_moves)) + diff --git a/game.py b/game.py index 25e3fde..3e75f1d 100644 --- a/game.py +++ b/game.py @@ -74,45 +74,53 @@ class Game: print(self.board) print("--------------------------------") - def play(self): - count = 0 - while Board.outcome(self.board) is None: - count += 1 - print("Turn:",count) + def play(self, amount_of_games): + outcomes = [] + for i in range(amount_of_games): + count = 0 + self.board = Board.initial_state + while Board.outcome(self.board) is None: + count += 1 + print("Turn:",count) - roll = self.roll() + roll = self.roll() - print("type of board: ", type(self.board)) - print("Board:",self.board) - print("{} rolled: {}".format(self.p1.get_sym(), roll)) + print("type of board: ", type(self.board)) + print("Board:",self.board) + print("{} rolled: {}".format(self.p1.get_sym(), roll)) - self.board = (self.p1.make_move(self.board, self.p1.get_sym(), roll))[0] + self.board = (self.p1.make_move(self.board, self.p1.get_sym(), roll))[0] + + print(self.board) - print(self.board) - - print() + print() - count += 1 + count += 1 - roll = self.roll() - print("{} rolled: {}".format(self.p2.get_sym(), roll)) - self.board = self.p2.make_move(self.board, self.p2.get_sym(), roll)[0] + roll = self.roll() + print("{} rolled: {}".format(self.p2.get_sym(), roll)) + self.board = Board.flip(self.p2.make_random_move(Board.flip(self.board), self.p2.get_sym(), roll)) - if Board.outcome(self.board)[1] > 0: - print_winner = "1: White, " + str(Board.outcome(self.board)) - else: - print_winner = "-1: Black " + str(Board.outcome(self.board)) - print("The winner is {}!".format(print_winner)) - print("Final board:",Board.pretty(self.board)) - return count + if Board.outcome(self.board)[1] > 0: + print_winner = "1: White, " + str(Board.outcome(self.board)) + else: + print_winner = "-1: Black " + str(Board.outcome(self.board)) + outcomes.append(Board.outcome(self.board)[1]) + print("The winner is {}!".format(print_winner)) + print("Final board:",Board.pretty(self.board)) + return outcomes +# return count highest = 0 #for i in range(100000): # try: g = Game() -g.train_model() +#g.train_model() +outcomes = g.play(2000) +print(outcomes) +print(sum(outcomes)) #count = g.play() # highest = max(highest,count) # except KeyboardInterrupt: