我正在使用 Batch 创建一种“AI”程序。这是非常基本的,我对此很好,但是如果我打开程序并告诉它保存一些东西(文本),有没有办法做到这一点?然后在我下次启动程序时输入特定内容时加载它吗?
问问题
493 次
1 回答
1
好吧,不确定这是否是您想要的……因为您没有指定是否需要“人类 AI”或其他类型的机器人任务的 AI。
这只是我在几分钟内写的一个例子,但也许这可以帮助你开始:
@Echo off
:Ask
Echo+
SET /P "Question=>>[YOU] "
Call :Answer "%Question%"
GOTO:ASK
:Answer
Echo+
For /F "Usebackq Tokens=1,* Delims=;" %%A in ("AI.txt") Do (
For %%@ in (%Question%) DO (
Echo "%%A"| FINDSTR /I "\"%%@\"" 1>NUL && (
Echo: [AI] %%B
GOTO:ASK
)
)
)
Echo: [AI] I don't understand you.
GOTO:EOF
AI.txt 内容:
matrix;Don't talk about it if you don't awake...
pennys;You said pennys? That remembered me I'm so hungry... ;)
dog;I like it!
name;My name is Bachitia, yes it's cool...
第2部分
这是另一种人工智能...
@Echo off
Setlocal enabledelayedexpansion
Set /A "INDEX=1"
REM :Check_Question {INDEX} {Response if answer is not saved} {Response if answer is saved}
Call :Check_Question "_%INDEX%" "Hello, I'm glad to meet you, What's your name? " "Welcome again {Value}"
Call :Check_Question "_%INDEX%" "What are your hobbies? " "Are you {Value} again? "
Pause&Exit
:Check_Question
If not exist "AI.txt" (Echo _0;DUMMY>"AI.txt")
For /F "Usebackq Tokens=1,* Delims=;" %%A in ("AI.txt") Do (
If "%%A" EQU "%~1" (
Set "Answer=%~3"
Set "Answer=!Answer:{Value}=%%B!"
Echo !Answer!
Set /A "INDEX+=1"
Exit /B 0
)
)
Set /P "Question=%~2"
Echo _%INDEX%;%Question%>>"AI.txt"
Set /A "INDEX+=1"
Exit /B 0
第一次运行:
ai.txt 自动生成的内容:
_0;DUMMY
_1;Elektro
_2;programming
第二次运行:
于 2013-04-26T23:29:38.113 回答