小编Giz*_*zmo的帖子

井字游戏检查玩家是否获胜的方法

我还是 OOP 编程和编写紧凑代码的新手,所以我可能忽略了一些东西,我试图找出一种方法来检查井字游戏中的垂直赢和对角赢,我已经有了水平。


如果可能的话,有没有办法将其他两种方式合并到我已经拥有的东西中?

#creates the gameboard that stores if spaces are open or not
game_board = [ [0,0,0], [0, 0, 0], [0, 0, 0,] ]
#0 = open space
#1 = O
#2 = X

#check for winners horizontaly
def find_winner():
    # y represents the y axis
    for y in range(3):
        if game_board[y][0] == game_board[y][1] == game_board[y][2] != 0:
            #returns if the X or 0 has won
            return game_board[y][0] 
    #returns 0 if no-one has won   
    return 0    
Run Code Online (Sandbox Code Playgroud)

python processing tic-tac-toe

1
推荐指数
1
解决办法
162
查看次数

标签 统计

processing ×1

python ×1

tic-tac-toe ×1