估价函数为机器的赢线数-人的赢线数
只能点击确定位置,如果点击其余界面上空白位置则会在控制台显示提示。
*程序有小bug,游戏结果会在控制台显示人赢还是机器赢还是平局,但是赢了之后没有加关闭图形界面的代码,如果需要可以自行加入。 *
而且需要先选形状再选先后顺序,这个会在一开始的控制台有提示
因为对图形界面不熟悉,所以代码相对来说写的比较冗余。
import numpy as np
from pylab import *
from matplotlib.widgets import RadioButtons
import matplotlib.pyplot as plt
mpl.rcParams['font.sans-serif'] = ['SimHei']
fig, ax = plt.subplots()
order='first'
pattern='o型'
pattern1='x'
s=0#判断鼠标位置
eventx=-1#x坐标
evebty=-1#y坐标
def func(label):
global order,s
order=label
s=1
plt.draw()
def func1(label):
global pattern,s
s=1
pattern=label
def judge_winner(a2):
m=0
n=0
for i in range(0, 3):
if (a2[i, 0] == 1) and (a2[i, 1] == 1) and (a2[i, 2] == 1 ):
m += 1
if (m == 1):
return 1
if (a2[i, 0] == -1) and (a2[i, 1] == -1) and (
a2[i, 2] == -1):
n += 1
if(n==1):
return 0
for j in range(0, 3):
if (a2[0, j] == 1) and (a2[1, j] == 1) and (a2[2, j] == 1):
m += 1
if (m == 1):
return 1
if (a2[0, j] == -1) and (a2[1, j] == -1) and (
a2[2, j] == -1):
n += 1
if (n == 1):
return 0
if (a2[0, 0] == 1) and (a2[1, 1] == 1) and (a2[2, 2] == 1):
m += 1
if (m == 1):
return 1