Extra credit


im trying to get my code to work, but it won't. python reads the y axis as top to down (or at least that is how my code works anyway) so im trying to make it go bottom to top, as how normal crodents would go. but for some reason it dosent work. also, im finding it hard trying to describe my code to anyone playing it(not in real life, I mean what the code is printing out), what better way can I get across how this is going to work? I know the way im doing it is weird as well, can you tell me a way to do what im trying to do better?

shipboard1 = []
guessboard1 = []
P1 = []
guessboard2 = []
shipboard2 = []
P2 = []
x = 1
y = 1

for i in range(10): 
    guessboard1.append(["O"] * 10)
    guessboard2.append(["O"] * 10)
    shipboard1.append(["O"] * 10)
    shipboard2.append(["O"] * 10)

def figure_Y_axis(y):
    if y == 1:
        y = 9
    elif y == 2:
        y = 8
    elif y == 3:
        y = 7
    elif y == 4:
        y = 6
    elif y == 6:
        y = 4

def print_board2(board):
    for row in board:
            print " ".join(row)

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

print "Welcome to battleships! 2 player edition!"

print "This will be a 10X10 grid."

print "Let's start with you, Player 1!"

while x == 1:
        P1_Ship_x = int(raw_input("Choose the x crodent of where you want the head of your first ship, player 1!:"))
        P1_Ship_y = int(raw_input("And now the y crodent!:"))
        P1_Ship_x -= 1
        P1_Ship_y -= 1
        if x == 1:
            x += 1
    except ValueError:
        print "Don't you want to play the game? Let's try again."
shipboard1[P1_Ship_y][P1_Ship_x] = "X"
print "Now that we have figurd out where the ship's head is, tell us what direction of the rest of the ship to go."
print "(If you need to know where the head is, look at the board at the top, scrool up to see the entire board (10X10))"
direction = raw_input("((Capital sensitive)H = Horizontal, V = Vertical, D = Diagonal)")


Your figure_Y_axis function looks like it shouldn't be there in the first place, but if it has to, then it would be better expressed as:

return BOARD_SIZE - y

If you want your boards to be printed with the lowest indexed row at the bottom, then change the order that you print the rows. If you mean to access the first row then that's 0, not 9


when I try it, the y axis measures downwards not up, you know, up the stairs? it seems to go down the stair if you know what I mean. but the problem is that the figure_y_axies doesn't even do anything, why?


How does a function deliver its result to its caller?

There's no y-axis, it's a list with indexes. You can print out the rows any order you want, there's nothing dictating what's up or down so use whatever is more natural.

Your print function is what decides what's "up" and what's "down", because that is what decides the order that the board is printed.

You could also just decide that the 0th row is the one at the top, however it's probably not a good idea to let something like this dictate what your final result looks like - but turning all your logic up-side down is worse than that.


i know there is no y-axis, I was just trying to explain it. there is just so many complicating factors with the way im trying to do it, trying to get around the whole starting at 0 instead of 1, since it starts counting the lists from left to right so it goes top to bottom but when people play the game they would think along the corridor and up the stairs, combining all of that to trying to make the computer put x where I want it and with the way it works it still being confusing to the player even when everything works, there is so much. is the a better way of doing this?


Yeah but you're also saying that you need to store the rows in reverse order. You don't. Just print them in reverse instead.

If the problem is that they show up in the wrong order
then the solution is to show (print) it in a different order

You're still saying it counts left to right! It doesn't! That's just how you print them.
The lists are indexed from 0 and up, there are no directions, you're the one adding that, you're the one saying whether +1 means right or left or up or down or for that matter an increase digonally up/left, that's entirely up to how you print it


how do I print the lists in reverse then? or how to do this whole thing better?


Whenever you have some single action you want to carry out but don't know how to write it in code, try using that description as a search query:



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.