人工智能实验代码整理.pdfVIP

  • 6
  • 0
  • 约2.14万字
  • 约 10页
  • 2023-06-09 发布于河南
  • 举报
人工智能实验代码整理--第1页 ⼈⼯智能实验代码整理 ⼈⼯智能实验代码整理 ⽂章⽬录 状态空间表⽰——猴⼦摘⾹蕉 # -*- coding: utf-8 -*- # State类,记录当前状态 class State : def __init__ (self, monkey =-1, box=0,banana=1, monbox =-1): self .monkey = monkey # -1:Monkey at A 0: Monkey at B 1:Monkey at C self .box = box # -1:box at A 0:box at B 1:box at C self .banana = banana # Banana at C,Banana=1 self .monbox = monbox # -1: monkey not on the box 1: monkey on the box # 复制前⼀个状态情况给当前状态,注意不是将对象直接复制,⽽是创建新的对象复制原状态的数据 def copyState (state_i): state_iplus1 = State () state_iplus1 .monkey = state_i .monkey state_iplus1 .box = state_i .box state_iplus1 .banana = state_i .banana state_iplus1 .monbox = state_i .monbox return state_iplus1 # function monkeygoto,it makes the monkey goto the other place def monkeygoto (b,i): a =b if (a==-1): States [i+1]=copyState (States[i]) States [i+1].monkey=-1 routesave .insert(i,Monkey go to A ) elif(a==0): States [i+1]=copyState (States[i]) States [i+1].monkey=0 routesave .insert(i,Monkey go to B ) elif(a==1): States [i+1]=copyState (States[i]) States [i+1].monkey=1 routesave .insert(i,Monkey go to C ) else : print(parameter is wrong ) # function movebox,the monkey move the box to the other place def movebox(a,i): B = a if(B==-1): routesave .insert(i,Monkey move box to A ) States [i+1]=copyState (States[i]) States [i+1].monkey=-1 States [i+1].box=-1 elif(B==0): routesave .insert(i,Monkey move box to B ) States [i+1]=copyState (States[i]) States [i+1].monkey=0 States [i+1].box=0 elif(B==1): routesave .insert(i,Monkey move box to C ) States [i+1]=copyState (States[i]) States [i+1].monkey=1 人工智能实验代码整理--第1页

文档评论(0)

1亿VIP精品文档

相关文档