追踪用户登陆桌面游戏的位置
Tracking where a user has landed in a board game
该程序的思想是,它模拟了一个游戏板,用户可以输入边的数量和每边的单元格。然后,程序需要模拟用户连续滚动两个六面骰子,直到开始方块落在或通过。
我遇到的问题是有一个必要的功能,记录用户登陆最多的地方,游戏板的每一面(像大富翁板有4面)。例如,一个有4面的大富翁棋盘,每面有10个单元格。
第1面有细胞1 - 10
第2面有细胞11 - 20
第3面有细胞21 - 30
第4面有细胞31 - 40
我需要报告我在这四条边中的每一条上降落最多的细胞,或者游戏板上有多少条边。
我不知道如何启动这个函数。我不希望代码是为我写的,只是在正确的方向上轻推一下。至于程序的其余部分,这是我所拥有的:
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
int rollNDice(int nDice, int nSides) {
int diceSum = 0;
for (int i = 0; i < nDice; i++) {
int randnum = 1 + (rand() % (nSides - 1 + 1));
diceSum = diceSum + randnum;
}
return diceSum;
}
int mostLandings(const int boardVector, int startInterval, int endInterval) {
}
int main() {
srand(333);
int boardSides = 0;
int boardSpotsPerSide = 0;
int numberOfSims = 0;
int diceMove = 0;
int startInterval = 0;
int endInterval = 0;
const int boardVector = 0;
cout << "How many sides of the board are there? ";
cin >> boardSides;
cout << "How many spots on each side? ";
cin >> boardSpotsPerSide;
cout << "How many simulations? ";
cin >> numberOfSims;
for (int i = 0; i < boardSides;) {
const int boardVector = boardSides * boardSpotsPerSide;
int spotsPerInterval = boardVector / boardSides;
startInterval = spotsPerInterval / spotsPerInterval + (10 * i);
endInterval = spotsPerInterval * (i + 1);
mostLandings(boardVector, startInterval, endInterval)
i++;
}
}
一种可能的方法是从计算棋盘上方块的总数开始。平方q的个数可以由
给出q = 2s + (s-1)(n-1) = sn + s- n + 1
其中s是每条边的正方形数量,n是每条边的数量。接下来,存储每个滚动值并循环滚动值和玩家之前的位置,并将这些值存储在一个单独的数组中。将该数组中的每个元素取q模,并存储在单独的数组中。该数组应该是在每个后续回合之后降落的每个正方形的索引,您可以根据自己的喜好操作和读取。
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 在C++游戏中与库存系统作斗争
- 无法获取webot::PositionSensor对象中位置传感器的值
- 非常量变量只读位置的赋值
- 换位表导致测试失败(但在游戏中运行良好)
- 如何定义更改car类中car位置的方法
- 使用迭代器时如何访问对象在向量中的位置?
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 求最大元素位置的分治算法
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 在重新居中之前获取游戏中的光标位置
- 访问冲突写入位置0x00000000.C++/SFML游戏
- 在游戏对象定义中放置的位置
- 人生游戏——印版到同一位置
- 追踪用户登陆桌面游戏的位置