鸽了挺久,更了
1.前情提要
真的很简洁
上篇文章我们用C++做了一个AI但是比较人机,今天我们要填一下坑。
2.代码
上篇最后我们发现有很多重复的语句,我又问了一下DeepSeek,他告诉我可以把说过的组合记下来,输出时看看有没有重复。但是每次输出前面的记录要作废,所以还要特判一下是不是第一个。
新定义一个map
map<string,map<string,map<string,int> > >mp5;//满级嵌套
print函数加一个参数特判是不是第一个。
void print(string c,int t,string c2="",int f=1){
if(f)mp5.clear();//清空
在寻找最可能出现字符时判断是否出现过,最后输出时记录一下。
然后不想说了直接贴代码
void print(string c,int t,string c2="",int f=1){
if(f)mp5.clear();//清空
/*Eglish*/
for(int i = 0; i < c.size();i++){
cout << c[i];Sleep(10);
}
if(mp2[c]==0){
//没有后继了
return;
}
if(t==0){
//结束了
return;
}
cout << " ";
string maxc="";int maxx=-1;
for(int i = 0; i < mp3[c].size(); i++){
if(maxx<mp[c][mp3[c][i]]&&mp5[c2][c][mp3[c][i]]==0){
maxx=mp[c][mp3[c][i]];maxc=mp3[c][i];
}
else if(maxx==mp[c][mp3[c][i]]&&mp5[c2][c][mp3[c][i]]==0){
srand(time(NULL));
if(rand()%2==0){
maxx=mp[c][mp3[c][i]];maxc=mp3[c][i];
}
}
}
mp5[c2][c][maxc]++;
print(maxc,t-1,c,0);
return;
}
其他不用改,修改print就行了。
3.debug*2
但是我们运行后会发现:
The Louvre Museum had horse carriages and a little girl . The surface has volcanoes and I wonder what you are ! Up above the sky . The Louvre
The surface has volcanoes and a little girl . The surface . The subway trains were crowded but fast . The Cassini spacecraft studied Saturn s four largest planet in the sky . The Louvre Museum had horse carriages and a blanket . The playground has volcanoes
还是一样的人机好了一点,不重复了,但太短了。
准么办呢?
又看了看,因为The Louvre 后面只出现了Museum,但三次了,不能说了。
所以我们要搞n次!反正没时限不怕TLE
下一篇吧
都看到这了,关个注吧,实在不行点个赞。
上一篇:C++实现AI智能体