backgammon/bot.py

42 lines
1.1 KiB
Python
Raw Normal View History

from cup import Cup
2018-02-13 13:38:49 +00:00
from board import Board
import random
class Bot:
2018-02-13 13:38:49 +00:00
def __init__(self, sym):
self.cup = Cup()
self.sym = sym
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
2018-02-13 13:38:49 +00:00
def do_move(board, roll):
print(Board.pretty(board))
print(Board.find_legal_moves(board, self.sym, roll[0]))
moves_1 = Board.find_legal_moves(board, self.sym,roll[0])
move = random.choice(moves_1)
print("{} was picked as move".format(move))
2018-02-13 13:38:49 +00:00
new_board = Board.move_thing(self.sym, int(move[0]), int(move[1]))
2018-02-13 13:38:49 +00:00
print(Board.pretty(new_board))
print(Board.find_legal_moves(new_board, self.sym, roll[1]))
moves_2 = Board.find_legal_moves(new_board, self.sym,roll[1])
move = random.choice(moves_2)
print("{} was picked as move".format(move))
2018-02-13 13:38:49 +00:00
return Board.move_thing(new_board, self.sym, int(move[0]), int(move[1]))