且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python 井字游戏

更新时间:2023-02-02 21:18:17

它只是检查当前棋盘,看看是否有任何获胜的单元格组合(如行数组中所列)具有 (a) 相同的值和 (b)该值不是 EMPTY.

It's just checking the current board to see if any winning combination of cells (as listed in the row array) have (a) the same value and (b) that value is not EMPTY.

注意:在 Python 中,如果 a == b == c != d,则检查 a ==b AND b == c AND c != d

Note: in Python, if a == b == c != d, checks that a ==b AND b == c AND c != d

因此,如果单元格 0、1 和 2 都有 X,那么在第一次通过循环时,它将从获胜例程返回 X.

So if cells 0, 1, and 2, all have X, then on the first pass through the loop, it will return X from the winner routine.