Home > Software design >  What changes should I make to make my output return True of False based on the current state on the
What changes should I make to make my output return True of False based on the current state on the

Time:11-25

So I'm trying to create an easy version of t2048, and so I'm trying to start by finding whether any moves are possible or not based on the current board, and I have a function ispossible(board: Board) that returns whether this is True or False

In case you don't know what 2048 mean, this is what the game is... https://play2048.co/

I'm not trying to recreate the entire game, I'm just trying to make a simple version of this that works.

def ispossible(board: Board)
    for i in range(0, board):
        for j in range(1, board):
            if [i][j - 1] == 0 and [i][j] > 0:
                return True
            elif ([i][j - 1] == [i][j]) and [i][j - 1] != 0:
                return True
    return False

However, this doesn't work at all as I get an 'Error' when I put this as an input

print(ispossible([4,3,2,2],[2,2,8,16], [16,4,4,4], [4,4,4,4]))

What should I change to make sure this works??

CodePudding user response:

As the comments to the question say, you should first pass in a single list of lists as your Board. Another issue with your example code is that you're not indexing into the board variable. Instead, the code is creating a size 1 list with i as the only element and then accessing the j-1th index. You probably meant to do something like board[i][j - 1] instead of [i][j - 1]. The same goes for your other list accesses.

  • Related