gpt4 book ai didi

c++ - 找到玩家说的话并阻止它

转载 作者:行者123 更新时间:2023-11-30 04:30:46 25 4
gpt4 key购买 nike

我想知道如何让玩家的句子在包含脏话后基本停止。现在,我已经设置好了,但是我需要知道如何使用 tolower 方法以及如何阻止它在使用此 for 循环时连续说同一个词 3 次:

std::size_t found;
std::string word[3] = { "swear", "swear1", "swear2" };
for(int i = 0; i < 3; i++)
{
found = msg.find(word[i]); // needs to have tolower
if(found != std::string::npos)
{
SendNotification("Message blocked. Does it contain swearing?");
return;
}
else
{
GetPlayer()->Say(msg, lang);
}
}

帮助将不胜感激!

最佳答案

它只阻止第一个单词的原因是因为当第一个单词不匹配时,您正在 Say()else 阻止消息.在循环开始之前保留一个变量bool badWordFound = false,并在if(...){ } block 中将其设置为真。然后,在检查所有单词后,如果 badWordFound == true 显示您的警告,else Say()

set found to false
for each swear word
if found in the sentance
set found to true
if found is false
display sentance
else
display warning

HTH

编辑:此外,如果这不仅仅是一个练习,那么关于在内存中缓存过滤器列表的评论值得跟进。

关于c++ - 找到玩家说的话并阻止它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8497696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com