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