简体   繁体   English

我应该进行哪些更改以使我的 output 根据板上当前的 state 返回 True 或 False?

[英]What changes should I make to make my output return True of False based on the current state on the board?

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因此,我正在尝试创建一个简单的 t2048 版本,因此我尝试首先根据当前板查找是否有可能进行任何移动,并且我有一个 function ispossible(board: Board)返回是否这是对还是错

In case you don't know what 2048 mean, this is what the game is... https://play2048.co/如果您不知道 2048 是什么意思,这就是游戏的含义... 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??我应该改变什么以确保这有效?

As the comments to the question say, you should first pass in a single list of lists as your Board .正如对问题的评论所说,您应该首先将一个列表作为您的Board传递。 Another issue with your example code is that you're not indexing into the board variable.您的示例代码的另一个问题是您没有索引到board变量。 Instead, the code is creating a size 1 list with i as the only element and then accessing the j-1 th index.相反,代码创建一个大小为 1 的列表,其中i作为唯一元素,然后访问第j-1个索引。 You probably meant to do something like board[i][j - 1] instead of [i][j - 1] .您可能打算做类似board[i][j - 1]而不是[i][j - 1]的事情。 The same goes for your other list accesses.您的其他列表访问也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM