人工智能-MINIMAX算法+ALPHA-BETA剪枝实现有界面的井字棋游戏

估价函数为机器的赢线数-人的赢线数
只能点击确定位置,如果点击其余界面上空白位置则会在控制台显示提示。
*程序有小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
  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值