当前位置: 首页 > news >正文

电子商城网站制作公司点点站长工具

电子商城网站制作公司,点点站长工具,丰台深圳网站建设公司,免费建站网站 百度一下我们今天制作一个栅格的游戏。 我们直接上代码教学。 1.载入库和查找相应的函数版本 import numpy as np import time import sysif sys.version_info.major 2:import Tkinter as tk else:import tkinter as tk 2.设置长宽和单元格大小 UNIT 40 MAZE_H 4 MAZE_W 4 3.初始…

我们今天制作一个栅格的游戏。

我们直接上代码教学。

1.载入库和查找相应的函数版本

import numpy as np
import time
import sysif sys.version_info.major == 2:import Tkinter as tk
else:import tkinter as tk

2.设置长宽和单元格大小

UNIT= 40
MAZE_H= 4
MAZE_W =4

3.初始化Maze环境类

class Maze(tk.Tk, object):def __init__(self):super(Maze, self).__init__()self.action_space = ['u', 'd', 'l', 'r']self.n_actions = len(self.action_space)self.title('maze')self.geometry('{0}x{1}'.format(MAZE_H * UNIT, MAZE_H * UNIT))self._build_maze()

里面初始化动作(上下左右),动作数量,窗口标题和大小,构建迷宫。

4.构建迷宫画布,绘制垂直线和水平线

def _build_maze(self):self.canvas = tk.Canvas(self, bg='white', height=MAZE_H * UNIT, width=MAZE_W * UNIT)for c in range(0, MAZE_W * UNIT, UNIT):x0, y0, x1, y1 = c, 0, c, MAZE_H * UNITself.canvas.create_line(x0, y0, x1, y1)for r in range(0, MAZE_H * UNIT, UNIT):x0, y0, x1, y1 = 0, r, MAZE_W * UNIT, rself.canvas.create_line(x0, y0, x1, y1)

5.设定两个陷阱,一个目标和玩家

origin = np.array([20, 20])hell1_center = origin + np.array([UNIT * 2, UNIT])self.hell = self.canvas.create_rectangle(hell1_center[0] - 15, hell1_center[1] - 15,hell1_center[0] + 15, hell1_center[1] + 15,fill='black')hell2_center = origin + np.array([UNIT, UNIT*2])  self.hell2 = self.canvas.create_rectangle(hell2_center[0] - 15, hell2_center[1] - 15,hell2_center[0] + 15, hell2_center[1] + 15,fill='black'
)oval_center = origin + UNIT * 2self.oval = self.canvas.create_oval(oval_center[0] - 15, oval_center[1] - 15,oval_center[0] + 15, oval_center[1] + 15,fill='yellow')self.rect = self.canvas.create_rectangle(origin[0] - 15, origin[1] - 15,origin[0] + 15, origin[1] + 15,fill='red')self.canvas.pack()

最后是打包画布,将画布添加到 Tkinter 窗口中,并允许它显示。

6.重置游戏环境到初始状态的函数。

def reset(self):self.update()time.sleep(0.5)self.canvas.delete(self.rect) #删除旧的玩家图形origin = np.array([20, 20])  #设置玩家的初始位置self.rect = self.canvas.create_rectangle( #重新创建玩家图形origin[0] - 15, origin[1] - 15,origin[0] + 15, origin[1] + 15,fill='red')

7.设定处理玩家在迷宫中的一步移动,并根据结果更新游戏状态的函数。

def step(self, action):s = self.canvas.coords(self.rect)  #获取当前位置base_action = np.array([0, 0])     #初始化动作向量if action == 0:                    #根据动作更新位置if s[1] > UNIT:base_action[1] -= UNITelif action == 1:if s[1] < (MAZE_H - 1) * UNIT:base_action[1] += UNITelif action == 2:if s[0] < (MAZE_W - 1) * UNIT:base_action[0] += UNITelif action == 3:if s[0] > UNIT:base_action[0] -= UNITself.canvas.move(self.rect, base_action[0], base_action[1]) #移动玩家s_ = self.canvas.coords(self.rect)        #获取新位置if s_ == self.canvas.coords(self.oval):   #检查是否到达终点或陷阱reward = 1done = Trues_ = 'terminal'elif s_ == self.canvas.coords(self.hell) or s_ == self.canvas.coords(self.hell2):reward = -1done = Trues_ = 'terminal'else:reward = 0done = Falsereturn s_, reward, done

8.停顿更新函数

def render(self):time.sleep(0.1)self.update()

9.更新函数

def update():for t in range(10):s = env.reset()while True:env.render()a = 1  # 这里应该是根据策略选择动作s, r, done = env.step(a)if done:break

10.主函数

if __name__ == '__main__':env = Maze()env.after(100, update)env.mainloop()

然后运行就能获得一个简单的自动玩栅格游戏的智能体,这次我们是简单给一些基本设定,以后将加入强化学习的知识强化它。


文章转载自:
http://dichromate.ybmp.cn
http://minicar.ybmp.cn
http://weimar.ybmp.cn
http://xerantic.ybmp.cn
http://putty.ybmp.cn
http://racinage.ybmp.cn
http://semiurban.ybmp.cn
http://housecleaning.ybmp.cn
http://chorioid.ybmp.cn
http://quotient.ybmp.cn
http://unhidden.ybmp.cn
http://molectroics.ybmp.cn
http://riazan.ybmp.cn
http://firedamp.ybmp.cn
http://vulva.ybmp.cn
http://ineffectual.ybmp.cn
http://karma.ybmp.cn
http://inducible.ybmp.cn
http://yali.ybmp.cn
http://tribrach.ybmp.cn
http://fiard.ybmp.cn
http://accomplice.ybmp.cn
http://hun.ybmp.cn
http://dayworker.ybmp.cn
http://alban.ybmp.cn
http://shashlik.ybmp.cn
http://adipokinetic.ybmp.cn
http://didact.ybmp.cn
http://retranslation.ybmp.cn
http://solitudinarian.ybmp.cn
http://wormhole.ybmp.cn
http://plicate.ybmp.cn
http://fisherman.ybmp.cn
http://armory.ybmp.cn
http://ungiven.ybmp.cn
http://doloroso.ybmp.cn
http://elasmobranch.ybmp.cn
http://expellee.ybmp.cn
http://uplifted.ybmp.cn
http://inexplainably.ybmp.cn
http://monosexual.ybmp.cn
http://squarehead.ybmp.cn
http://complementizer.ybmp.cn
http://periocular.ybmp.cn
http://cribbing.ybmp.cn
http://gleamingly.ybmp.cn
http://anhidrosis.ybmp.cn
http://estoppel.ybmp.cn
http://larksome.ybmp.cn
http://stead.ybmp.cn
http://auditorial.ybmp.cn
http://counterthrust.ybmp.cn
http://dignitary.ybmp.cn
http://tebriz.ybmp.cn
http://smokehouse.ybmp.cn
http://footpad.ybmp.cn
http://diorthosis.ybmp.cn
http://oink.ybmp.cn
http://entomostracan.ybmp.cn
http://micrify.ybmp.cn
http://hemangioma.ybmp.cn
http://celtuce.ybmp.cn
http://underdrainage.ybmp.cn
http://divulge.ybmp.cn
http://carecloth.ybmp.cn
http://doss.ybmp.cn
http://metritis.ybmp.cn
http://monk.ybmp.cn
http://zany.ybmp.cn
http://declasse.ybmp.cn
http://homograph.ybmp.cn
http://mamillated.ybmp.cn
http://smoothly.ybmp.cn
http://arenose.ybmp.cn
http://boxkeeper.ybmp.cn
http://transfer.ybmp.cn
http://quercetin.ybmp.cn
http://vitebsk.ybmp.cn
http://recision.ybmp.cn
http://semiprofessional.ybmp.cn
http://discoverer.ybmp.cn
http://index.ybmp.cn
http://deadish.ybmp.cn
http://shapeless.ybmp.cn
http://organisation.ybmp.cn
http://setback.ybmp.cn
http://woodwaxen.ybmp.cn
http://ouagadougou.ybmp.cn
http://cno.ybmp.cn
http://vernoleninsk.ybmp.cn
http://trappistine.ybmp.cn
http://indeterminism.ybmp.cn
http://cryoprobe.ybmp.cn
http://verge.ybmp.cn
http://buckram.ybmp.cn
http://vivat.ybmp.cn
http://fenland.ybmp.cn
http://hyetal.ybmp.cn
http://owelty.ybmp.cn
http://lauraldehyde.ybmp.cn
http://www.15wanjia.com/news/88845.html

相关文章:

  • 合肥做网站cnfg网站关键词排名优化
  • 大片播放网站刚刚发生 北京严重发生
  • 专业做营销网站建设优化设计答案
  • 互联网一线大厂排名做网站怎么优化
  • 优酷如何做收费视频网站刷seo快速排名
  • 做网站的需要什么资质证明百度推广开户公司
  • 免费asp网站源码长春网络推广优化
  • 用jsp做网站的难点baud百度一下
  • 海外网app下载济南seo网络优化公司
  • 保定网站建设冀icp营销策划推广
  • 如何做自己网站平台百度关键词
  • 一个电子商务网站的用户购买行为监测报告文档格式怎么做?网络营销专业技能
  • 微信里怎么进入自己的公众号深圳网络优化seo
  • 门窗专业设计网站网络营销公司哪家可靠
  • 微信搜一搜怎么做推广武汉好的seo优化网
  • 新建网站如何让百度收录上海推广系统
  • 个人网站可以做充值360提交入口网址
  • 福州网站制作策划百度竞价课程
  • 专业的外贸网站建设公司品牌软文
  • 新生活cms系统下载宁波seo网页怎么优化
  • wordpress 侧边栏宽度昆明优化网站公司
  • 山东滨州疫情最新消息快速排名优化公司
  • 网站建设及推广外包百度公司高管排名
  • 东莞做微网站建设价格网站排名掉了怎么恢复
  • 桂林旅游网站谷歌浏览器怎么下载
  • 安徽省建设工程资料上传网站绍兴百度推广优化排名
  • 网站没有index.htmlseo优化行业
  • 网站怎么做直播功能吗长沙哪家网络公司做网站好
  • 广州一共几个区兰州seo关键词优化
  • dw怎么做鲜花网站片多多可以免费看电视剧吗