I think we can play against a random bot now

This commit is contained in:
Alexander Munch-Hansen 2018-03-08 13:32:40 +01:00
parent bae1e73692
commit a33826219d
2 changed files with 39 additions and 27 deletions

6
bot.py
View File

@ -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))

16
game.py
View File

@ -74,8 +74,11 @@ class Game:
print(self.board)
print("--------------------------------")
def play(self):
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)
@ -96,23 +99,28 @@ class Game:
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]
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))
outcomes.append(Board.outcome(self.board)[1])
print("The winner is {}!".format(print_winner))
print("Final board:",Board.pretty(self.board))
return count
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: