0

I am trying to get the values as they are input to determine the coordinate on which to change a string. However, instead of happening sequentially from first inner array to the next, both are changing. I cannot seem to catch the bug. Here is the code:

def read_inputs():
    size = input()
    boats = input()
    boards = make_boards(int(size))
    get_boats(int(boats), boards)
    show_boards(int(size), boards)

def make_boards(size):
    board1 = []
    board2 = []
    for i in range(size):
        curr_row = []
        for j in range(size):
            curr_row.append('-')
        board1.append(curr_row)
        board2.append(curr_row)
    return [board1, board2]

def show_boards(size, boards):
    board1 = boards[0]
    board2 = boards[1]
    for i in range(size):
        curr_str1 = ''
        curr_str2 = ''
        for j in range(size):
            curr_str1+=board1[i][j]
            curr_str2+=board2[i][j]
        print(curr_str1+' '+curr_str2)

def get_boats(boats, boards):
    size =len(boards[0][0])
    for i in range(boats*2):
        boat_str = input()
        boat_arr = boat_str.split(' ')
        x=int(boat_arr[0])
        y=int(boat_arr[1])
        n=int(boat_arr[2])
        orient=int(boat_arr[3])
        if y+n>=size:
            n = size
        if orient==0:
            for j in range(n):
                boards[i%2][x][y+j]='B'
        else:
            for j in range(n):
                boards[i%2][x+j][y]='B'
        print(boards)

def main():
    read_inputs()

main()

Given the inputs

4
1
0 0 2 0
1 1 1 1

the output should be

BB-- ----
---- -B--
---- ----
---- ----

But instead getting

BB-- BB--
-B-- -B--
---- ----
---- ----
David Kabii
  • 642
  • 6
  • 17

0 Answers0