C++中的石头剪刀布循环方法
Rock Paper Scissors looping method in C++
所以基本上我正在设计一个石头剪刀布游戏。
我有三种方法(移动(可供选择,具体取决于他们的胜率。我们称之为:methodA()
、methodB()
、methodC()
。
现在我需要每 30 轮执行一次检查以检查胜率。
我有一段这样的代码:
Move nextMove(){ //Move is a enum including Rock,Paper,Scissors
Move makeMove;
vector<float> checkWinRate = {winRateA,winRateB,winRateC};
//saving my win rates into a vector and sort it
std::sort(checkWinRate.begin(),checkWinRate.end());
if (checkWinRate.back() == winRateA)
makeMove = methodA();
else if (checkWinRate.back() == winRateB)
makeMove = methodB();
else
makeMove = methodC();
//choose methods according to win rates
return makeMove;
}
我现在正在做的是每次调用此函数时都让它检查。但是,我的最终目标是让它每 30 轮检查一次,在接下来的 30 轮中运行相同的方法并再次检查。这听起来很容易,但无论如何我都想不出这样做。
知道我应该在这里做什么吗?请帮忙。
您可以创建一个整数,每轮递增 1,当它达到 29(30 轮(时,您进行检查并再次将其设为零。您的回合数一开始将是 29,以便能够在开始时输入任何 if。
Move nextMove(static int numOfRounds){
//...
if ((checkWinRate.back() == winRateA) && numOfRounds == 29)
makeMove = methodA();
numOfRounds = 0;
//...
else{
/*You need to choose a method here, my question is, will it
break your original logic? I would choose randomly.*/
numOfRounds++;
}
return makeMove;
}
相关文章:
- 方法内部但循环仍得到预期的不合格id错误C++
- 在 c++ 中实现嵌套循环的更短方法吗?
- 如何在C++中循环访问未知对象方法?
- EnQueue 方法在循环队列中未正确返回C++?
- C++模板方法中的循环依赖关系
- 为什么这种方法会进入无限循环?
- 编写按初始值循环的循环的更好方法是什么
- 循环遍历标准的正确方法::array<char*, N>
- 类方法 - 数据结构中 For 循环的运行时错误
- 循环依赖,在继承类的情况下使用覆盖方法
- 从列表/向量制作嵌套 for 循环的最佳方法是什么?
- 从基于迭代器的for循环转换后,如何在map::find()中调用方法
- 是否可以在基于范围的 for 循环中使用模板化的开始/结束方法
- 还有其他方法可以为乘法表编写循环以获取运行时值吗?
- 如何避免模板方法的循环依赖
- 使用虚拟变量对 std::vector 内部循环进行切片的最佳方法
- 有什么方法可以在 c++ 中组织"cycling"(循环)数字?
- C++中的石头剪刀布循环方法
- 对于循环方法调用
- 循环/方法太慢