编写环境:windows 10 64x Spyder python3.8
源代码:
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 10 15:21:34 2021
@author: 小良子
"""
import time,random
chess=[' ',' ',' ',' ',' ',' ',' ',' ',' ']
def chess_index(x,y):
n=(x-1)*3+y
return n
def realplayer():
x,y=map(lambda x:int(x),input("输入棋子的行数与列数(以空格分隔):").split())
choice=chess_index(x,y)
chess[choice-1]='X'
def show_chessboard():
n=0
for i in range(3):
for j in range(3):
print("[{0}]".format(chess[n]),end='')
n+=1
print()
def iswinner():
for w1 in range(0,7,3):
if chess[w1]==chess[w1+1] and chess[w1+1]==chess[w1+2]:
if chess[w1]=='X':
return 1
elif chess[w1]=='O':
return 2
for w2 in range(3):
if chess[w2]==chess[w2+3] and chess[w2+3]==chess[w2+6]:
if chess[w2]=='X':
return 1
elif chess[w2]==

在Windows 10环境下,通过Python 3.8进行编程,本文介绍了如何创建一个交互式的井字棋游戏,其中包含了人工智能的元素,让玩家可以与AI对战。文章提供了详细的源代码。
最低0.47元/天 解锁文章
1741

被折叠的 条评论
为什么被折叠?



