improvements
This commit is contained in:
parent
09a006ae99
commit
fffc8cda85
14
board.py
14
board.py
|
@ -91,7 +91,7 @@ class Board:
|
|||
|
||||
return legal_moves
|
||||
|
||||
def to_s(self):
|
||||
def pretty(self):
|
||||
temp = []
|
||||
for x in self.state:
|
||||
if x >= 0:
|
||||
|
@ -99,14 +99,12 @@ class Board:
|
|||
else:
|
||||
temp.append("{}".format(x))
|
||||
|
||||
|
||||
return """
|
||||
------------------------------------------------------------
|
||||
|{12}|{11}|{10}|{9}|{8}|{7}|bar 1: {26} |{6}|{5}|{4}|{3}|{2}|{1}|end -1: {0}|
|
||||
|--|--|--|--|--|--|--------|--|--|--|--|--|--|
|
||||
|{13}|{14}|{15}|{16}|{17}|{18}|bar -1: {27} |{19}|{20}|{21}|{22}|{23}|{24}|end 1: {25}|
|
||||
------------------------------------------------------------
|
||||
""".format(*temp)
|
||||
+--------------------------------------------------------------+
|
||||
|{13}|{14}|{15}|{16}|{17}|{18}| bar -1: {27} |{19}|{20}|{21}|{22}|{23}|{24}| home 1: {25} |
|
||||
|--|--|--|--|--|--|------------|--|--|--|--|--|--| |
|
||||
|{12}|{11}|{10}|{9}|{8}|{7}| bar 1: {26} |{6}|{5}|{4}|{3}|{2}|{1}| home -1: {0} |
|
||||
+--------------------------------------------------------------+""".format(*temp)
|
||||
|
||||
def move_to_bar(self, to_idx):
|
||||
# Find the owner of the hit checker
|
||||
|
|
4
bot.py
4
bot.py
|
@ -23,14 +23,14 @@ class Bot:
|
|||
return self.sym
|
||||
|
||||
def do_move(self, roll):
|
||||
print(self.board.to_s())
|
||||
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]))
|
||||
|
||||
print(self.board.to_s())
|
||||
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)
|
||||
|
|
14
game.py
14
game.py
|
@ -2,26 +2,30 @@ from human import Human
|
|||
from board import Board
|
||||
from bot import Bot
|
||||
from network import Network
|
||||
from cup import Cup
|
||||
|
||||
class Game:
|
||||
|
||||
def __init__(self):
|
||||
self.board = Board()
|
||||
self.network = Network()
|
||||
self.p1 = Human(self.board, 1, self.network)
|
||||
self.p2 = Bot(self.board, -1, self.network)
|
||||
self.cup = Cup()
|
||||
|
||||
def roll(self):
|
||||
return self.cup.roll()
|
||||
|
||||
def play(self):
|
||||
while True:
|
||||
# print(self.board.to_s())
|
||||
roll = self.p1.roll()
|
||||
roll = self.roll()
|
||||
print("{} rolled: {}".format(self.p1.get_sym(), roll))
|
||||
self.p1.do_move(roll)
|
||||
if self.board.is_winner(self.p1.get_sym()):
|
||||
print("{} won!".format(self.p1.get_sym()))
|
||||
break
|
||||
# print(self.board.to_s())
|
||||
roll = self.p2.roll()
|
||||
|
||||
roll = self.roll()
|
||||
print("{} rolled: {}".format(self.p1.get_sym(), roll))
|
||||
self.p2.do_move(roll)
|
||||
if self.board.is_winner(self.p2.get_sym()):
|
||||
print("{} won!".format(self.p2.get_sym()))
|
||||
|
|
18
human.py
18
human.py
|
@ -1,23 +1,9 @@
|
|||
from cup import Cup
|
||||
|
||||
class Human:
|
||||
|
||||
global cup
|
||||
cup = Cup()
|
||||
|
||||
def __init__(self, board, sym, network):
|
||||
self.cup = Cup()
|
||||
self.network = network
|
||||
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 -1 if cur == 1 else 1
|
||||
|
||||
|
@ -25,7 +11,7 @@ class Human:
|
|||
return self.sym
|
||||
|
||||
def do_move(self, roll):
|
||||
print(self.board.to_s())
|
||||
print(self.board.pretty())
|
||||
print(self.board.find_legal_moves(self.sym,roll[0]))
|
||||
cur_state = self.board.get_state()
|
||||
|
||||
|
@ -39,7 +25,7 @@ class Human:
|
|||
self.board.move_thing(self.sym, int(cmds_1[0]), int(cmds_1[1]))
|
||||
|
||||
|
||||
print(self.board.to_s())
|
||||
print(self.board.pretty())
|
||||
print(self.board.find_legal_moves(self.sym,roll[1]))
|
||||
print("What to do with the second roll?")
|
||||
cmds_2 = input().split(",")
|
||||
|
|
Loading…
Reference in New Issue
Block a user