-
大小: 7KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-06-08
- 语言: 其他
- 标签: KnowledgeBas AI Python
资源简介
可以实现按要求开展50-100次游戏,每次游戏中的怪兽、坑、金子均随机出现,且可以调节pits出现的概率。Agent会根据KB理论尽可能地选取最佳路径获得金币,赢得胜利。日志会记录每次的移动信息与在每一个cell所感知到的信息(气味、微风)。
代码片段和文件信息
#
# Propositional and First-Order logic.
#
# Compiled against Python 2.7
import re
“““
define some basic functions used below
“““
def isnumber(x):
return hasattr(x ‘__int__‘)
def num_or_str(x):
if isnumber(x): return x
try:
return int(x)
except ValueError:
try:
return float(x)
except ValueError:
return str(x).strip()
def find_if(predicate seq):
for x in seq:
if predicate(x): return x
return None
#______________________________________________________________________________
class KB:
def __init__(self sentence=None):
abstract
def tell(self sentence):
“Add the sentence to the KB.“
abstract
def ask(self query):
for result in self.ask_generator(query):
return result
return False
def ask_generator(self query):
“Yield all the substitutions that make query true.“
abstract
def retract(self sentence):
“Remove sentence from the KB.“
abstract
class PropKB(KB):
“A KB for propositional logic. Inefficient with no indexing.“
def __init__(self sentence=None):
self.conds = []
if sentence:
self.tell(sentence)
def tell(self sentence):
“Add the sentence‘s conds to the KB.“
self.conds.extend(conjuncts(to_cnf(sentence)))
def ask_generator(self query):
“Yield the empty substitution if KB implies query; else nothing.“
if tt_entails(Expr(‘&‘ *self.conds) query):
yield {}
def retract(self sentence):
“Remove the sentence‘s conds from the KB.“
for c in conjuncts(to_cnf(sentence)):
if c in self.conds:
self.conds.remove(c)
#______________________________________________________________________________
class Expr:
def __init__(self op *args):
“Op is a string or number; args are Exprs (or are coerced to Exprs).“
assert isinstance(op str) or (isnumber(op) and not args)
self.op = num_or_str(op)
self.args = map(expr args)
def __call__(self *args):
assert is_symbol(self.op) and not self.args
return Expr(self.op *args)
def __repr__(self):
“Show something like ‘P‘ or ‘P(x y)‘ or ‘~P‘ or ‘(P | Q | R)‘“
if not self.args:
return str(self.op)
elif is_symbol(self.op):
return ‘%s(%s)‘ % (self.op ‘ ‘.join(map(repr self.args)))
elif len(self.args) == 1:
return self.op + repr(self.args[0])
else:
return ‘(%s)‘ % (‘ ‘+self.op+‘ ‘).join(map(repr self.args))
def __eq__(self other):
return (other is self) or (isinstance(other Expr)
and self.op == other.op and self.args == other.args)
def __ne__(self other):
return not self.__eq__(other)
def __hash__(self):
“Need a hash method so Exprs can live in dicts.“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8970 2018-12-10 10:43 WumpusWorldAI.py
文件 10037 2018-12-10 10:39 logic.py
文件 2909 2018-12-10 10:39 logic_info_KB.py
文件 822 2018-12-10 10:32 README.md
相关资源
- Brain MRI Ssegmentation
- 矩阵连乘问题 给定n个矩阵{A1A2…
- ibm serveRAID M1015 M5015驱动
- ibm serveRAID M1015驱动
- MICCAI历年论文汇总
- MICCAI 2018 accept paper list
- glut搭建glut32bit和64bit
- TMS320C5509A AIC23 音频回放例程
- aidl实现后台播放的音乐播放器
- 超级多线程百度baidu ping.rar
- Houdini低模解算转成高模关键帧动画并
- SurfaceRT 9月越狱脚本
- 油漆桶画板aia
- AndrewBox_LineRender&TrailRender
- 使用Jmail组件发送和接收邮件(含附件
- psd文件修复工具AdvancedPSRepair
- dailyReport-master.zip 工作日报管理工具
- 打字案例.zip
- QT text预加载方式显示大文件文本.zi
- main.zip
- tensorflow实现猫狗识别
- DELL H310MINI RAID 驱动for 2008 64 位.rar
- Air Printer 1.6.6.1破解补丁
- rdo-release-train-1.noarch.rpm
- IBM ThinkPad Hardware Maintenant Diskette(HM
- AI2017破解补丁.zip
- SourceInsight 完美的配色方案 theme_Mon
- 介绍了一种基于DSP芯片TMS320VC5509A 并采
- 万有引力算法GSA-master.zip
- 点云数据ply格式
评论
共有 条评论