追踪用户登陆桌面游戏的位置

Tracking where a user has landed in a board game

本文关键字:游戏 位置 桌面 用户 陆桌面 追踪      更新时间:2023-10-16

该程序的思想是,它模拟了一个游戏板,用户可以输入边的数量和每边的单元格。然后,程序需要模拟用户连续滚动两个六面骰子,直到开始方块落在或通过。

我遇到的问题是有一个必要的功能,记录用户登陆最多的地方,游戏板的每一面(像大富翁板有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模,并存储在单独的数组中。该数组应该是在每个后续回合之后降落的每个正方形的索引,您可以根据自己的喜好操作和读取。