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

如何建设网站地图域名查询服务器ip

如何建设网站地图,域名查询服务器ip,自媒体运营主要做什么,网页qq邮箱登录目录 汉诺塔游戏 完整游戏 后期展望 汉诺塔游戏 汉诺塔#xff08;Tower of Hanoi#xff09;#xff0c;是一个源于印度古老传说的益智玩具。这个传说讲述了大梵天创造世界的时候#xff0c;他做了三根金刚石柱子#xff0c;并在其中一根柱子上从下往上按照大小顺序摞…  目录 汉诺塔游戏 完整游戏 后期展望 汉诺塔游戏 汉诺塔Tower of Hanoi是一个源于印度古老传说的益智玩具。这个传说讲述了大梵天创造世界的时候他做了三根金刚石柱子并在其中一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门将这些圆盘从下面开始按大小顺序重新摆放在另一根柱子上并规定在小圆盘上不能放大圆盘同时在三根柱子之间一次只能移动一个圆盘。当盘子的数量增加时移动步骤的数量会呈指数级增长圆盘数为n时总步骤数steps为2^n - 1。 n 64 steps 2^64 - 1 18446744073709551616 ≈ 1.845 x 10^19 汉诺塔问题是一个递归问题也可以使用非递归法来解决例如使用栈来模拟递归过程。这个问题不仅是一个数学和逻辑问题也是一个很好的教学工具可以用来教授递归、算法和逻辑思考等概念。同时汉诺塔游戏也具有一定的娱乐性人们可以通过解决不同规模的汉诺塔问题来挑战自己的智力和耐心。 本篇接着上期讲下去前2篇的链接地址 Python 一步一步教你用pyglet制作汉诺塔游戏续-CSDN博客 Python 一步一步教你用pyglet制作汉诺塔游戏-CSDN博客 完整游戏 前2期代码的基础上添加了完整的提示功能一个汉诺塔游戏作品终于完工了效果如下 信息提示功能都放在了鼠标事件中 window.event def on_mouse_press(x, y, dx, dy):     global xy, hanns, gamecompleted     if not hanns.success():         pole hanns.on_mouse_over(x, y)         if pole is not None:             xy.append(pole)             if len(xy)1:                 hanns.setdiskcolor(xy[0], (255,0,0))                 if not hanns.array[pole]:                     hanns.setdiskcolor(xy[0])                     xy.pop()                     return         if len(xy)2:             if xy[0]!xy[1]:                 info hanns.move(*xy)                 hanns.setdiskcolor(xy[0])                 if info is False:                     info1.text 起始圆盘大于目标位置的圆盘                 elif info is None:                     info1.text 所选起始位置的塔架不能为空                 else:                     info1.text f{hanns.order-hanns.array[xy[1]][-1]}号圆盘从{xy[0]1}号塔架移动到{xy[1]1}号塔架             hanns.setdiskcolor(xy[0])             xy.clear()             info2.text f当前层数{hanns.order}\t最佳步数{2**hanns.order-1}\t当前步数{hanns.steps}         if hanns.success():             if hanns.order24:                 info1.text f恭喜您完成 {hanns.order} 层汉诺塔任意点击层数加一             else:                 info1.text f太棒了您已完成 {hanns.order} 层汉诺塔游戏结束                 gamecompleted True                 return     elif not gamecompleted:         hanns Hann(window.width/2, 120, hanns.order1)         info1.text f {hanns.order} 层汉诺塔游戏开始         info2.text f当前层数{hanns.order}\t最佳步数{2**hanns.order-1}\t当前步数{hanns.steps} Hann 类中增加一个改色的方法用于标注被点击的要移动的源塔架 def setdiskcolor(self, n, colorColor[0]):         self.disk[n].cir1.color color         self.disk[n].cir2.color color         self.disk[n].rect.color color 完整代码  import pygletwindow pyglet.window.Window(800, 500, caption汉诺塔) pyglet.gl.glClearColor(1, 1, 1, 1) batch pyglet.graphics.Batch()Color (182,128,18),(25,65,160),(56,170,210),(16,188,78),(20,240,20),(240,240,20),(255,128,20),(240,20,20),(245,60,138)class Disk:def __init__(self, x, y, color(0,0,0), width200, height20):self.cir1 pyglet.shapes.Circle(xwidth/2-height/2, y, radiusheight/2, colorcolor, batchbatch)self.cir2 pyglet.shapes.Circle(x-width/2height/2, y, radiusheight/2, colorcolor, batchbatch)self.rect pyglet.shapes.Rectangle(x-width/2height/2, y-height/2, width-height, height, colorcolor, batchbatch)def move(self, dx, dy):self.cir1.x dx; self.cir1.y dyself.cir2.x dx; self.cir2.y dyself.rect.x dx; self.rect.y dyclass Hann:def __init__(self, x, y, order2, space250, thickness20, width200, height300):assert(order1)self.pole [pyglet.shapes.Line(x-i*space, y, x-i*space, yheight, widththickness, colorColor[0], batchbatch) for i in range(-1,2)]self.disk [Disk(xi*space, y, colorColor[0], widthwidththickness, heightthickness) for i in range(-1,2)]self.x, self.y x, yself.order orderself.space spaceself.thickness thicknessself.width widthself.poleheight heightself.beadheight (height-thickness*2)/orderself.step (width-thickness)/(order1)self.steps 0self.macro []coordinates [(self.x-space, self.y(i1)*self.beadheight-(self.beadheight-thickness)/2) for i in range(order)]self.beads [Disk(*xy, Color[i%81], widthself.width-i*self.step, heightself.beadheight) for i,xy in enumerate(coordinates)]self.array [[*range(order)], [], []]def move(self, pole1, pole2):if self.array[pole1]:bead self.array[pole1].pop()if self.array[pole2] and beadself.array[pole2][-1]:self.array[pole1].append(bead)return Falseelse:return Noneself.beads[bead].move((pole2-pole1)*self.space, (len(self.array[pole2])-len(self.array[pole1]))*self.beadheight)self.array[pole2].append(bead)self.steps 1self.macro.append((pole1, pole2))return Truedef setdiskcolor(self, n, colorColor[0]):self.disk[n].cir1.color colorself.disk[n].cir2.color colorself.disk[n].rect.color colordef on_mouse_over(self, x, y):for i in range(-1,2):if hanns.x-hanns.width/2 x-i*hanns.space hanns.xhanns.width/2 and hanns.y-hanns.thickness/2 y hanns.yhanns.poleheight:return i1def success(self):return len(self.array[2]) self.orderwindow.event def on_draw():window.clear()batch.draw()window.event def on_mouse_press(x, y, dx, dy):global xy, hanns, gamecompletedif not hanns.success():pole hanns.on_mouse_over(x, y)if pole is not None:xy.append(pole)if len(xy)1:hanns.setdiskcolor(xy[0], (255,0,0))if not hanns.array[pole]:hanns.setdiskcolor(xy[0])xy.pop()returnif len(xy)2:if xy[0]!xy[1]:info hanns.move(*xy)hanns.setdiskcolor(xy[0])if info is False:info1.text 起始圆盘大于目标位置的圆盘elif info is None:info1.text 所选起始位置的塔架不能为空else:info1.text f{hanns.order-hanns.array[xy[1]][-1]}号圆盘从{xy[0]1}号塔架移动到{xy[1]1}号塔架hanns.setdiskcolor(xy[0])xy.clear()info2.text f当前层数{hanns.order}\t最佳步数{2**hanns.order-1}\t当前步数{hanns.steps}if hanns.success():if hanns.order24:info1.text f恭喜您完成 {hanns.order} 层汉诺塔任意点击层数加一else:info1.text f太棒了您已完成 {hanns.order} 层汉诺塔游戏结束gamecompleted Truereturnelif not gamecompleted:hanns Hann(window.width/2, 120, hanns.order1)info1.text f {hanns.order} 层汉诺塔游戏开始info2.text f当前层数{hanns.order}\t最佳步数{2**hanns.order-1}\t当前步数{hanns.steps}xy [] order 2 hanns Hann(window.width/2, 120, order) info1 pyglet.text.Label(操作方法鼠标先后点击起始和目标位置就能移动圆盘, font_size21, color(0,0,0,255), xwindow.width/2, y50, anchor_xcenter, batchbatch) info2 pyglet.text.Label(f当前层数{order}\t最佳步数{2**order-1}\t当前步数0, font_size18, color(0,0,0,255), x80, y450, batchbatch) gamecompleted Falsepyglet.app.run()后期展望 之后有空再优化一下代码再添加上音效、回放等功能游戏效果会理想些。还能把上期的自动演示功能也加进去就更加完美了。 本文完以下仅为凑字数请忽略 自动演示功能即把以下递归函数的结果展现出来即可 def hanoi(n, start, mid, end, movesNone):     if moves is None:         moves []     if n 1:         moves.append((start, end))     else:         hanoi(n-1, start, end, mid, moves)         moves.append((start, end))         hanoi(n-1, mid, start, end, moves)     return moves   for order in (4,7,8):     moves hanoi(order, 0, 1, 2)     print(len(moves)2**order-1)     print(moves) 运行结果 True [(0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2)] True [(0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (2, 0), (1, 0), (2, 1), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (1, 0), (2, 1), (2, 0), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (2, 0), (1, 0), (2, 1), (0, 2), (0, 1), (2, 1), (2, 0), (1, 0), (1, 2), (0, 2), (1, 0), (2, 1), (2, 0), (1, 0), (2, 1), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (2, 0), (1, 0), (2, 1), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (1, 0), (2, 1), (2, 0), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (1, 0), (2, 1), (2, 0), (1, 0), (2, 1), (0, 2), (0, 1), (2, 1), (2, 0), (1, 0), (1, 2), (0, 2), (1, 0), (2, 1), (2, 0), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (2, 0), (1, 0), (2, 1), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2), (1, 0), (2, 1), (2, 0), (1, 0), (1, 2), (0, 2), (0, 1), (2, 1), (0, 2), (1, 0), (1, 2), (0, 2)] True [(0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (2, 1), (0, 1), (2, 0), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2), (0, 1), (2, 0), (2, 1), (0, 1), (0, 2), (1, 2), (1, 0), (2, 0), (1, 2), (0, 1), (0, 2), (1, 2)]
http://www.zqtcl.cn/news/186032/

相关文章:

  • 海南住房与城乡建设网站大连做网站团队
  • 邯郸最穷的三个县长春纯手工seo
  • 昌黎网站建设贵德县建设局网站
  • 山西网站制作公司兼职做网站安全么
  • 阿里做网站怎么做青岛网站维护
  • 怎么建网站手机版郑州网站建设哪家好
  • 做企业网站有哪些好处安龙网站建设
  • 怎做连接网站wordpress iis设置方法
  • ugc网站开发网站设计常见流程
  • dz论坛可以做招聘网站国内空间没备案可以打开网站吗
  • 建设用地规划证查询网站公司起名字大全免费好听
  • 杭州网站建设公司有哪些瑞诺国际的数字营销模式
  • 宣城网站建设 有限公司高州做网站
  • 做外贸最适合的网站系统有可以做国外支付系统的网站吗
  • 建设执业资格注册中心网站办事大厅ui设计素材库
  • 个人网站免费建站4399电脑版网页链接
  • 重庆开县网站建设公司推荐网站建设与维护高职
  • 关于网站开发的技术博客海口网站设计建设
  • xx市院门户网站建设方案做视频特技的网站
  • 肇庆seo公司咨询23火星seo 网站
  • 天元建设集团有限公司破产新手seo网站做什么类型好
  • spa.net网站开发二次开发需要什么
  • 如何做网站静态页面商丘网签查询
  • 网站建设好学么模版型网站是怎样的
  • 网站维护建设费应计入科目高端营销型网站制作
  • 推荐几个好的网站wordpress 加载数据库表格也卖弄
  • 承德网站开发找人做网站安全吗
  • 百度网站推广电话眼镜网站怎么做竞价
  • 邢台建设银行官方网站为什么建设网站很多公司没有
  • 闵行做网站费用湖南正规网络营销哪家便宜