Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions battleship.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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']

Expand All @@ -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
Expand Down Expand Up @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -291,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:
Expand Down