Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions mcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ def is_win(game):
return win

def is_tie(game):
tie = False
if not is_win(game):
for row in game:
for cell in row:
if cell == '':
return tie
tie = True
return tie
if is_win(game):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常棒的命名

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tie是什么意思

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tie是什么意思

平局

return False
# 使用 all 函数和列表推导式检查每一行的每个单元格是否都不为空
if all(all(cell!= '' for cell in row) for row in game):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all是什么意思

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all 函数和列表推导式来检查游戏中的每一行。对于每一行,我们使用另一个 all 函数和列表推导式检查该行的每个单元格是否都不为空

return True
return False

def main():
game = [[' ' for _ in range(3)] for _ in range(3)] # Tic-tac-toe board
Expand Down