19/19 string object not callable?


#1

Ok yeah i'm back again sorry so i have reworked my code allot and have it working for the most part i just wanted to change a few parts so it worked on separate boards instead of one. I'm really confused as to why it says why the string isn't callable. Is there something simple i might have over looked?

Battleship for two

from random import randint

board1 = []
board2 = []
boards = [board1, board2]

for x in range(5):
board1.append("O" * 5)

for x in range(5):
board2.append(["O"] * 5)

print "Lets play battleship!"

player1 = str(raw_input("Enter the name of the first player:"))
player2 = str(raw_input("Enter the name of the second player:"))

next_player = 1
player = str(player1) and str(player2)
player = 0

if next_player == player1:
next_player = (player % 2)
player = next_player + 1

def print_board(boards):
for row in boards:
print " ".join(row)

board1 = boards[0]
board2 = boards[1]

max_games = int(raw_input("Enter the maximum amount of games you want to play:"))
turn = max_games
print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print board1
print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "READY PLAYER ONE ?"

def random_row(boards):
return randint(0, len(boards) - 1)

def random_col(boards):
return randint(0, len(boards[0]) - 1)

ship_row1 = random_row(board1)
ship_col1 = random_col(board1)

ship_row2 = random_row(board2)
ship_col2 = random_col(board2)

for turn in range(max_games):
guess_row = int(raw_input("Please guess a row number:"))
guess_col = int(raw_input("Also guess a column number: "))

if player1(guess_row == ship_row1 and guess_col == ship_col1):
    print "Congratulations! You sank the battleship!"
    break
if player2(guess_row == ship_row2 and guess_col ==ship_col2):
    print "Congatulations! You sank the battleship!"
else:
    if (guess_row > 10 or guess_row < 0) and (guess_col > 10 or guess_col < 0):
        print "Oops your guess is out of bounds"
        print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        print boards
        print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if player1:
    board1[guess_row][guess_col] == "X"
    print "You missed the battleship"
    print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    print board1
    print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
elif player2:
    (board2[guess_row][guess_col] == "X")
    print "You missed the battleship"
    print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    print board2
    print"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    board2[guess_row][guess_col] = "X"
else:
    print "You missed the battleship"
    boards[guess_row][guess_col] = "X"
    if turn == max_games:
        print "Game Over"
        print ship_row
        print ship_col

for turns in range(max_games):
turns = turn + 1
print ("Turn", turn)
print "The battleship was at:"
print ship_row
print ship_col


#2

Well done for thinking further and working hard - that's what makes a good programmer!


#3

Thanks!!! I have been working on it for a week or so!