backgammon/bot.py

43 lines
1.1 KiB
Python
Raw Normal View History

from cup import Cup
import random
class Bot:
2018-02-07 14:31:05 +00:00
def __init__(self, board, sym, network):
self.cup = Cup()
self.board = board
self.sym = sym
2018-02-07 14:31:05 +00:00
self.network = network
def roll(self):
print("{} rolled: ".format(self.sym))
roll = self.cup.roll()
print(roll)
return roll
def switch(self,cur):
return -1 if cur == 1 else 1
def get_sym(self):
return self.sym
def do_move(self, roll):
2018-02-07 15:27:03 +00:00
print(self.board.pretty())
print(self.board.find_legal_moves(self.sym, roll[0]))
moves_1 = self.board.find_legal_moves(self.sym,roll[0])
move = random.choice(moves_1)
print("{} was picked as move".format(move))
self.board.move_thing(self.sym, int(move[0]), int(move[1]))
2018-02-07 15:27:03 +00:00
print(self.board.pretty())
print(self.board.find_legal_moves(self.sym, roll[1]))
moves_2 = self.board.find_legal_moves(self.sym,roll[1])
move = random.choice(moves_2)
print("{} was picked as move".format(move))
self.board.move_thing(self.sym, int(move[0]), int(move[1]))