From fffc8cda850554d9afa614499f1eca41814a267a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Wed, 7 Feb 2018 16:27:03 +0100 Subject: [PATCH] improvements --- board.py | 16 +++++++--------- bot.py | 4 ++-- game.py | 14 +++++++++----- human.py | 20 +++----------------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/board.py b/board.py index 936d947..1664e4d 100644 --- a/board.py +++ b/board.py @@ -91,22 +91,20 @@ class Board: return legal_moves - def to_s(self): + def pretty(self): temp = [] for x in self.state: if x >= 0: temp.append(" {}".format(x)) 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 diff --git a/bot.py b/bot.py index 02e56ed..c853df0 100644 --- a/bot.py +++ b/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) diff --git a/game.py b/game.py index 9a70991..12ebfab 100644 --- a/game.py +++ b/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())) diff --git a/human.py b/human.py index 10df86f..731ebfb 100644 --- a/human.py +++ b/human.py @@ -1,23 +1,9 @@ -from cup import Cup - -class Human: - - global cup - cup = Cup() - +class Human: 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(",")