-
大小: 7KB文件类型: .zip金币: 2下载: 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
相关资源
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- Python中Numpy库最新教程
- cc2541 BLE DEMO
- Apolipoprotein E4 Impairs in vivo Hippocampal
- railroad铁路CAD生成
- 用python编写的移动彩信的发送程序
- Python全栈学习笔记面向对象大作业:
- 黑白棋(带简单AI)
- python实现的ftp自动上传、下载脚本
- HDD repair.rar
- 利用foxmail模板批量生成邮件
- 简易绘图的制作 (一)WPF
- tsai经典两步法 很不错的
- LSI RAID配置手册(图文)
- Python版的A*寻路算法
- jmail组件 v4.3
- IronPython IDE
-
解决安装vs2012后vs2010 li
nk : fatal er - Anti-biofilm Activity of Resveratrol and Ursol
- In vitro screening of lactobacilli with antago
- libaio-0.3.107-10.el6.x86_64.rpm
- spaceclaim教程
- app inventor小游戏打地鼠.aia
- app inventor 应用街景地图.aia
- pzs_44217116_06.aia
- 四大RAID存储详解
- Symantec Brightmail AntiSpam产品手册
- 昆腾数据备份解决方案增强AIG对萨班
- DataNumen Excel Repair Excel文件修复工具
- HP Kayak高性能PC选择Adaptec RAID解决方案
评论
共有 条评论