From fc97c92b6163eb9e61c368c4f6fe2a264a3a1138 Mon Sep 17 00:00:00 2001 From: Julian Koh Date: Wed, 18 Jul 2018 14:05:34 -0400 Subject: [PATCH 1/2] draws board on each round --- battleship.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/battleship.py b/battleship.py index 053a0c9..8479195 100755 --- a/battleship.py +++ b/battleship.py @@ -121,8 +121,6 @@ def run_round(self): elif self.is_player: # if self.p1_lives_prev - print "This is your board: " - print self.my_coords sub = self.my_coords['Submarine'] cruiser = self.my_coords['Cruiser'] @@ -134,7 +132,18 @@ def run_round(self): for x in cruiser: all_ship_coordinates.append(x) - print all_ship_coordinates + empty_board = [['. ']*10 for _ in range(10)] + for x in all_ship_coordinates: + if len(str(x)) == 1: + empty_board[0][x] = 'o ' + else: + x_string = str(x) + x_coord = int(x_string[0]) + y_coord = int(x_string[1]) + empty_board[x_coord][y_coord] = 'o ' + + print "This is your current board: " + print '\n'.join(''.join(row) for row in empty_board) self.guess = self.obtain_guess() print "Your number attack is %d" % self.guess @@ -230,6 +239,8 @@ def calc_round_results(self, g1, g2): open_two_hit = self.runtime.open(two_hit) return gather_shares([open_one_hit, open_two_hit]) + ### This is not used anymore ### + """ def convert_coordinates(ship, coords): length = len(SHIPS[ship]) coordinates = [None for _ in range(length)] @@ -248,6 +259,7 @@ def convert_coordinates(ship, coords): final_coordinates.append(int(x)) return tuple(final_coordinates) + """ def __init__(self, runtime): # Save the Runtime for later use From 75414fee6f58a2946a6e65a8a43fce9c31ea34c1 Mon Sep 17 00:00:00 2001 From: Julian Koh Date: Wed, 18 Jul 2018 14:26:51 -0400 Subject: [PATCH 2/2] removed prints --- battleship.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/battleship.py b/battleship.py index 8479195..3987448 100755 --- a/battleship.py +++ b/battleship.py @@ -72,10 +72,10 @@ def error(self, res): print res def num_living(self): - print "in num livesing" - print self.lives + # print "in num livesing" + # print self.lives the_living = filter(lambda x: x > 0, self.lives) - print "the living %s " % the_living + # print "the living %s " % the_living return len(the_living) def alive_players(self): @@ -90,11 +90,11 @@ def is_alive(self): def run_round(self): print "Starting another round." - print "Player's lives %s " % self.lives - print "Test" - print "num living %s" % self.num_living() - print "Player naumbers %s " % self.alive_players() - print "is alive %s" % self.is_alive() + # print "Player's lives %s " % self.lives + # print "Test" + # print "num living %s" % self.num_living() + # print "Player naumbers %s " % self.alive_players() + # print "is alive %s" % self.is_alive() if not self.is_alive(): sys.stdout.write(RED) @@ -303,7 +303,7 @@ def __init__(self, runtime): starting = str(coords[1]) + str(coords[2]) coordinates[0] = starting - if coords[0] == 'v': + if coords[0] == 'h': for x in range(1, length): coordinates[x] = str(coords[1]) + str(coords[2] + x) else: