Now actually has a bot playing, although randomly, it still works

This commit is contained in:
Alexander Munch-Hansen 2018-02-05 23:50:31 +01:00
parent ddc56680f1
commit ea9b8d3feb
4 changed files with 42 additions and 4 deletions

View File

@ -57,7 +57,7 @@ class Board:
# Rewrite this, it's shit.
idxs_with_thing = self.find_pieces_for_player(sym)
print(idxs_with_thing)
legal_moves = []
if sym == "O":
for index in idxs_with_thing:

34
bot.py Normal file
View File

@ -0,0 +1,34 @@
from cup import Cup
import random
class Bot:
def __init__(self, board, sym):
self.cup = Cup()
self.board = board
self.sym = sym
def roll(self):
print("{} rolled: ".format(self.sym))
roll = self.cup.roll()
print(roll)
return roll
def switch(self,cur):
return "X" if cur == "O" else "O"
def do_move(self, roll):
print(self.board.to_s())
moves_1 = self.board.find_legal_moves(self.sym,roll[0])
move = random.choice(moves_1)
self.board.move_thing(self.sym, int(move[0]), int(move[1]))
print(self.board.to_s())
moves_2 = self.board.find_legal_moves(self.sym,roll[1])
omove = random.choice(moves_2)
self.board.move_thing(self.sym, int(move[0]), int(move[1]))

View File

@ -1,19 +1,20 @@
from hooman import Human
from board import Board
from bot import Bot
class Game:
def __init__(self):
self.board = Board()
self.p1 = Human(self.board, "O")
self.p2 = Human(self.board, "X")
self.p2 = Bot(self.board, "X")
def play(self):
while True:
print(self.board.to_s())
# print(self.board.to_s())
roll = self.p1.roll()
self.p1.do_move(roll)
print(self.board.to_s())
# print(self.board.to_s())
roll = self.p2.roll()
self.p2.do_move(roll)

View File

@ -32,6 +32,9 @@ class Human:
self.board.move_thing(self.sym, int(cmds_1[0]), int(cmds_1[1]))
print(self.board.to_s())
print(self.board.find_legal_moves(self.sym,roll[0]))
print("What to do with the second roll?")
cmds_2 = input().split(",")
while not self.board.check_move(cmds_2, self.sym, roll[1]):