Now actually has a bot playing, although randomly, it still works
This commit is contained in:
parent
ddc56680f1
commit
ea9b8d3feb
2
board.py
2
board.py
|
@ -57,7 +57,7 @@ class Board:
|
||||||
|
|
||||||
# Rewrite this, it's shit.
|
# Rewrite this, it's shit.
|
||||||
idxs_with_thing = self.find_pieces_for_player(sym)
|
idxs_with_thing = self.find_pieces_for_player(sym)
|
||||||
print(idxs_with_thing)
|
|
||||||
legal_moves = []
|
legal_moves = []
|
||||||
if sym == "O":
|
if sym == "O":
|
||||||
for index in idxs_with_thing:
|
for index in idxs_with_thing:
|
||||||
|
|
34
bot.py
Normal file
34
bot.py
Normal 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]))
|
||||||
|
|
||||||
|
|
7
game.py
7
game.py
|
@ -1,19 +1,20 @@
|
||||||
from hooman import Human
|
from hooman import Human
|
||||||
from board import Board
|
from board import Board
|
||||||
|
from bot import Bot
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.board = Board()
|
self.board = Board()
|
||||||
self.p1 = Human(self.board, "O")
|
self.p1 = Human(self.board, "O")
|
||||||
self.p2 = Human(self.board, "X")
|
self.p2 = Bot(self.board, "X")
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
while True:
|
while True:
|
||||||
print(self.board.to_s())
|
# print(self.board.to_s())
|
||||||
roll = self.p1.roll()
|
roll = self.p1.roll()
|
||||||
self.p1.do_move(roll)
|
self.p1.do_move(roll)
|
||||||
print(self.board.to_s())
|
# print(self.board.to_s())
|
||||||
roll = self.p2.roll()
|
roll = self.p2.roll()
|
||||||
self.p2.do_move(roll)
|
self.p2.do_move(roll)
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,11 @@ class Human:
|
||||||
cmds_1 = input().split(",")
|
cmds_1 = input().split(",")
|
||||||
|
|
||||||
self.board.move_thing(self.sym, int(cmds_1[0]), int(cmds_1[1]))
|
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?")
|
print("What to do with the second roll?")
|
||||||
cmds_2 = input().split(",")
|
cmds_2 = input().split(",")
|
||||||
while not self.board.check_move(cmds_2, self.sym, roll[1]):
|
while not self.board.check_move(cmds_2, self.sym, roll[1]):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user