numpy
和random
Python库用于构建这个游戏。代码不是要求用户在电路板上放置标记,而是随机选择电路板上的一个位置并放置标记。除非玩家获胜,否则它将在每次转弯后显示棋盘。如果游戏得到平局,则返回-1。
# Checks whether the player has three
# of their marks in a vertical row
def
col_win(board, player):
for
x in
range(len(board)):
win =
True
for
y in
range(len(board)):
if
board[y][x] !=
player:
win =
False
continue
if
win ==
True:
return(win)
return(win)
# Checks whether the player has three
# of their marks in a diagonal row
def
diag_win(board, player):
win =
True
for
x in
range(len(board)):
if
board[x, x] !=
player:
win =
False
return(win)
# Evaluates whether there is
# a winner or a tie
def
evaluate(board):
winner =
0
for
player in
[1, 2]:
if
(row_win(board, player) or
col_win(board,player) or
diag_win(board,player)):
winner =
player








暂无数据