编写环境: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':