一开始在win上安装一直出错,后来发现Jericho库安装一直失败,后来在github上看到需要linux环境,本来打算用虚拟机,但我的win内存不够了,在虚拟环境里面安装anconda一直装不上,所以只能放弃win部署。
Jericho是一个轻量级的 Python 库,用于连接学习代理与交互式小说游戏。由微软开发并维护,它提供了一个直观的接口,使人工智能和机器学习模型能够理解、互动,并通过经典的文本冒险游戏进行学习。通过 Jericho,你可以训练智能代理解决复杂的环境问题,体验阅读理解与决策制定的结合。
linux
conda create -n alf python==3.9
conda activate alf
pip install alfworld[full] -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
export ALFWORLD_DATA=/home/user/dz/ALFWorld/data
alfworld-download
alfworld-play-tw #Play a Textworld game
alfworld-play-thor #Play an Embodied-World (THOR) game
win
这个只是记录一下过程,并没有成功,Jericho库需要linux环境,虽然我下面创建虚拟机了,但电脑没内存了,所以放弃。
这个好像不兼容win,所以我上面试错之后打算使用win的WSL(Windows Subsystem for Linux)来跑一遍。
首先安装bash
apk update
apk add bash
bash#启动bash
安装anconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
安装python虚拟环境
conda create -n alf python=3.9
conda activate alf
安装alfworld
安装cmake:choco install cmake(管理员身份,然后添加环境变量C:\Program Files\CMake\bin)
这个cmake版本要大于3.5,不然后面编译报错,所以我重新安装了:
安装nmake:下载安装 Visual Studio Installer (配置环境变量C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\bin\Hostx64\x64)
安装make:choco install make
#pip install alfworld[full]
pip install --upgrade setuptools -i http://mirrors.aliyun.com/pypi/simple/
pip install incremental -i http://mirrors.aliyun.com/pypi/simple/
pip install cffi
技术栈
1.inform创建文字游戏
下载安装inform,然后创建一个项目
"my_first" by Zoe
The living room is a room. "这里是一个普通的房间。"
The table is in the living room. "There are some items on the table."
The chair is in the living room. "The chair is a simple wooden chair, looks heavy."
Instead of taking the table:
say "你不能拿走桌子。"
Instead of taking the chair:
say "椅子太重了,拿不动。"
Instead of examining the living room:
say "你环顾四周,看到了桌子、椅子,还有那幅画。"
点击settings,Story File Format里面选择Z-Code就可以,运行没问题就release出z8文件,然后使用python脚本测试
2.jericho库运行z8游戏文件
from jericho import *
env = FrotzEnv('/home/user/dz/ALFWorld/data/my_first.z8')
# 启动游戏并获取初始状态
initial_observation, info = env.reset()
done = False
while True:
user_input = input("What do you want to do? ")
observation, reward, done, info= env.step(user_input) # 发送玩家输入并获取响应
print(observation, reward, done, info)