这个是vscomputer,还有vsplayer在我的github

'''

@author: redtree

@contact: redtreec@gmail.com

@time: 17-12-28 下午4:09

@desc:  gobang AI base on decision tree method

'''

import tkinter as tk

from tkinter import messagebox

import random

class game_log:

list_black = []  # Black chess pieces positions

list_white = []  # White chess pieces positions

turn = 1  # 1 : Turn to black side / 0 :  Turn to white side

cursetX = 0  # The current mouse click coordinates

cursetY = 0  #

can_down =True

# Whether the rules of victory check

def check_win(check_list):

# First cross calibration (horizontal) (vertical) (oblique side)

for slb in check_list:

horizontal_check = vertical_check = oblique_left = oblique_right = 0

for x in range(1, 5):

if ([slb[0] + x, slb[1]] in check_list) or ([slb[0] - x, slb[1]] in check_list):

horizontal_check = horizontal_check + 1

if ([slb[0], slb[1] + x] in check_list) or ([slb[0], slb[1] - x] in check_list):

vertical_check = vertical_check + 1

if ([slb[0] + x, slb[1] - x] in check_list) or ([slb[0] - x, slb[1] + x] in check_list):

oblique_right = oblique_right + 1

if ([slb[0] - x, slb[1] - x] in check_list) or ([slb[0] + x, slb[1] + x] in check_list):

oblique_left = oblique_left + 1

# When there are five in a row, you win

if oblique_left >= 4 or oblique_right >= 4 or horizontal_check >= 4 or vertical_check >= 4:

if game_log.turn == 1:

messagebox._show('GameOver', 'Black_Win')

break

else:

messagebox._show('GameOver', 'White_Win')

break

# Battlefield build

def create_ground():

# Initialize window and brush

root = tk.Tk()

canvas = tk.Canvas(root, width=500, height=500)

canvas.pack()

# Draw 24 * 24 square checkerboard pen

for x in range(20, 490, 20):

canvas.create_line(20, x, 480, x)

for y in range(20, 490, 20):

canvas.create_line(y, 20, y, 480)

def quit(event):

root.quit()  # exit game

# Click event callback method

def callback(event):

# Get click coordinates to find the approach point

pointX = int(event.x)

pointY = int(event.y)

after_down(pointX, pointY)

pechX =  pointX+(random.randint(-20,20))

pechY =  pointY+(random.randint(-20,20))

after_down(pechX, pechY)

while game_log.can_down==False:

pechX = pointX + (random.randint(-20, 20))

pechY = pointY + (random.randint(-20, 20))

after_down(pechX, pechY)

def after_down(pointX,pointY):

addX = delX = pointX

addY = delY = pointY

while (not (addX % 20) == 0) and (not (delX % 20) == 0):

addX = addX + 1

delX = delX - 1

while (not (addY % 20) == 0) and (not (delY % 20) == 0):

addY = addY + 1

delY = delY - 1

# After getting the approach point, input the game parameters

if (addX % 20) == 0:

game_log.cursetX = addX

else:

game_log.cursetX = delX

if (addY % 20) == 0:

game_log.cursetY = addY

else:

game_log.cursetY = delY

'''

tmp_point [110,110,130,130]  :

For the drop brush marker, respectively,

said the starting point of the circular coordinates and end coordinates

Into the array should be converted to:

tmp_point_2d [6,6]

That means the pawn is in the 6th row, 6th row

'''

# Through the brush drop and record the location, perform a victory rule check every time an action is performed

if game_log.turn == 1:

tmp_point = [game_log.cursetX - 10, game_log.cursetY - 10, game_log.cursetX + 10, game_log.cursetY + 10]

tmp_point_2d = [(tmp_point[0] + tmp_point[2]) / 40, (tmp_point[1] + tmp_point[3]) / 40]

if tmp_point_2d[0] < 1 or tmp_point_2d[0] > 24 or tmp_point_2d[1] < 1 or tmp_point_2d[1] > 24:

print('Lots cross the border')

game_log.can_down=False

elif (not (tmp_point_2d in game_log.list_black)) and (not (tmp_point_2d in game_log.list_white)):

game_log.list_black.append(tmp_point_2d)

canvas.create_arc(game_log.cursetX - 10, game_log.cursetY - 10, game_log.cursetX + 10,

game_log.cursetY + 10, extent=359, fill='black')

check_win(game_log.list_black)  # Whether the victory check

game_log.turn = 0  # Rotation

game_log.can_down=True

print('down success')

else:

print(' hasbean down')

game_log.can_down=False

else:

tmp_point = [game_log.cursetX - 10, game_log.cursetY - 10, game_log.cursetX + 10, game_log.cursetY + 10]

tmp_point_2d = [(tmp_point[0] + tmp_point[2]) / 40, (tmp_point[1] + tmp_point[3]) / 40]

if tmp_point_2d[0] < 1 or tmp_point_2d[0] > 24 or tmp_point_2d[1] < 1 or tmp_point_2d[1] > 24:

print('Lots cross the border')

game_log.can_down=False

elif (not (tmp_point_2d in game_log.list_white)) and (not (tmp_point_2d in game_log.list_black)):

game_log.list_white.append(tmp_point_2d)

canvas.create_arc(game_log.cursetX - 10, game_log.cursetY - 10, game_log.cursetX + 10,

game_log.cursetY + 10, extent=359, fill='white')

check_win(game_log.list_white)

game_log.turn = 1

game_log.can_down=True

print('down success')

else:

print(' hasbean down')

game_log.can_down = False

# Bind the left mouse button and right

root.bind("", callback)

root.bind("", quit)

# The main window into the performance cycle

root.mainloop()

create_ground()

python五子棋代码tkinter_python使用tkinter开发一款五子棋游戏相关推荐

  1. python五子棋代码tkinter_python使用tkinter库实现五子棋游戏

    python使用tkinter库实现五子棋游戏 来源:中文源码网    浏览: 次    日期:2019年11月5日 [下载文档:  python使用tkinter库实现五子棋游戏.txt ] (友情 ...

  2. 如何利用HTML5快速开发一款小游戏

    如何利用HTML5开发一款小游戏?Cocos2d-js是一款流行的H5游戏开发框架,介绍Cocos2d-js的核心技术和使用方法,学完以后可以独立开发一款休闲游戏,主要介绍cocos2d-js中的图层 ...

  3. 邹伟:如何开发一款小游戏

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 邹伟,后端高级工程师,对前端也有一定开发经验.2010年于华南理工大学毕业后加入腾讯,参与CDB.TGW等云服务研发,现主要负责微信游戏业务 ...

  4. 邹伟:如何开发一款小游戏 1

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 邹伟,后端高级工程师,对前端也有一定开发经验.2010年于华南理工大学毕业后加入腾讯,参与CDB.TGW等云服务研发,现主要负责微信游戏业务 ...

  5. 如何实战开发一款小游戏

    如何快速开发一款火爆的小游戏?"火爆"是一个偏运营的词,今天介绍的内容可能更倾向于技术方面,即如何利用微信的开放能力开发一款小游戏.小游戏上线120天时发布了几个重要的消息,其中有 ...

  6. 浙大python教材_浙大学霸用这套Python教程自学,8天开发12款游戏,堪称经典课程...

    学习Python的人,总会到处寻找资料,比如这里看点视频,那里看点文章,但最后依然学不好Python.因为 缺乏系统的学习 ,对于基础较差的学习者总是不那么容易的. 我今天介绍的这本书会对刚刚入门的P ...

  7. 如何利用状态同步开发一款联机游戏

    游戏状态同步 1.前言 目前市场上单机游戏占比高,因为相对联机游戏开发周期短.成本低,但联机游戏的社交属性强,玩家粘性高.总体来说,开发联机游戏有一定的技术门槛. 2.帧同步和状态同步 •     帧 ...

  8. java开发一款雷电游戏

    导读:电脑游戏,是指在计算机上能够运转的游戏软件.这种软件具有较强的娱乐性.电脑游戏的创新和发展与硬件.软件的发展紧密相关.它能够给玩家提供一个虚拟的环境,使游戏带给了人们很多的享受和欢乐.雷电游戏因 ...

  9. 游戏开发公司如何开发一款小游戏

    游戏公司开发一款游戏是由几个不同的岗位组成的,策划.原画.设计.3D模型.程序等.这五大模块下还细分不同的小模块. 要成功开发出一款好的游戏,下面的条件缺一不可: 1.能够吸引玩家的IP题材,并有完整 ...

最新文章

  1. 第十五届全国大学生智能车安徽赛区参赛须知和竞赛日程安排
  2. MySQL 5.7.22 二进制安装
  3. asp.net core系列 59 Ocelot 构建基础项目示例
  4. 分享篇--esp32直连天猫精灵
  5. jar包不统一也会报错:Exception in thread main java.lang.NoClassDefFoundError
  6. C++ virtual笔试
  7. 8086/8088内部结构
  8. jersey_教程–带有Jersey和Spring的Java REST API设计和实现
  9. 苹果Mac设备丢失时怎样利用激活锁保护隐私信息?
  10. 第二人生的源码分析(12)天空显示的实现
  11. Qt 模型视图编程之表头设置
  12. html内联框架导航,html基本格式和内联框架
  13. git_error:src refspec dev does not match any
  14. uniapp中使用uview组件u-icon 编辑到微信小程序样式问题
  15. mc服务器ip是网站,我的世界服务器地址大全
  16. 网格设计版式设计_网页设计展示精美的版式
  17. python访问陌生人qq空间_Python爬虫获取QQ空间信息(上)
  18. 网址怎样收藏到我计算机桌面,电脑应该如何收藏网址
  19. tif构建金字塔失败arcgis_arcgis构建金字塔
  20. 炸翻AI和生化环材圈!GPT-4学会自己搞科研,手把手教人类做实验

热门文章

  1. 游戏玩家场景高清桌面壁纸都是什么样的?
  2. 可编辑杂志模板|简单的得到一个完整的杂志预先设计版式
  3. js webpack 解决跨域问题_详解webpack-dev-server使用http-proxy解决跨域问题
  4. LeetCode-----旋转数组的最小数字
  5. REDM库使用教程01(详细入门)
  6. 连接池dbcp跟c3p0
  7. Ubuntu系统下实时监控GPU的温度
  8. System-Level Registers and Data Structures in IA-32e Mode and 4-Level Paging
  9. Uninterruptible Sleep(不可中断的睡眠)
  10. Memory Translation and Segmentation(内存转换与段)