I think we can play against a random bot now
This commit is contained in:
parent
bae1e73692
commit
a33826219d
6
bot.py
6
bot.py
|
@ -40,6 +40,10 @@ class Bot:
|
||||||
def get_network(self):
|
def get_network(self):
|
||||||
return self.network
|
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):
|
def make_move(self, board, sym, roll):
|
||||||
# print(Board.pretty(board))
|
# print(Board.pretty(board))
|
||||||
legal_moves = Board.calculate_legal_states(board, sym, roll)
|
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())
|
#print("Found the best state, being:", np.array(move_scores).argmax())
|
||||||
return best_move_pair
|
return best_move_pair
|
||||||
|
|
||||||
# return random.choice(list(legal_moves))
|
|
||||||
|
|
16
game.py
16
game.py
|
@ -74,8 +74,11 @@ class Game:
|
||||||
print(self.board)
|
print(self.board)
|
||||||
print("--------------------------------")
|
print("--------------------------------")
|
||||||
|
|
||||||
def play(self):
|
def play(self, amount_of_games):
|
||||||
|
outcomes = []
|
||||||
|
for i in range(amount_of_games):
|
||||||
count = 0
|
count = 0
|
||||||
|
self.board = Board.initial_state
|
||||||
while Board.outcome(self.board) is None:
|
while Board.outcome(self.board) is None:
|
||||||
count += 1
|
count += 1
|
||||||
print("Turn:",count)
|
print("Turn:",count)
|
||||||
|
@ -96,23 +99,28 @@ class Game:
|
||||||
|
|
||||||
roll = self.roll()
|
roll = self.roll()
|
||||||
print("{} rolled: {}".format(self.p2.get_sym(), 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:
|
if Board.outcome(self.board)[1] > 0:
|
||||||
print_winner = "1: White, " + str(Board.outcome(self.board))
|
print_winner = "1: White, " + str(Board.outcome(self.board))
|
||||||
else:
|
else:
|
||||||
print_winner = "-1: Black " + str(Board.outcome(self.board))
|
print_winner = "-1: Black " + str(Board.outcome(self.board))
|
||||||
|
outcomes.append(Board.outcome(self.board)[1])
|
||||||
print("The winner is {}!".format(print_winner))
|
print("The winner is {}!".format(print_winner))
|
||||||
print("Final board:",Board.pretty(self.board))
|
print("Final board:",Board.pretty(self.board))
|
||||||
return count
|
return outcomes
|
||||||
|
# return count
|
||||||
|
|
||||||
highest = 0
|
highest = 0
|
||||||
|
|
||||||
#for i in range(100000):
|
#for i in range(100000):
|
||||||
# try:
|
# try:
|
||||||
g = Game()
|
g = Game()
|
||||||
g.train_model()
|
#g.train_model()
|
||||||
|
outcomes = g.play(2000)
|
||||||
|
print(outcomes)
|
||||||
|
print(sum(outcomes))
|
||||||
#count = g.play()
|
#count = g.play()
|
||||||
# highest = max(highest,count)
|
# highest = max(highest,count)
|
||||||
# except KeyboardInterrupt:
|
# except KeyboardInterrupt:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user