请达人帮我写一个 silly board game 的程序

来源:百度知道 编辑:UC知道 时间:2024/09/22 09:46:51
Nancy’s Silly board game is a spectator game and is based on luck.

1. The board has 25 squares numbered 1
to 25.

2. The first of two players to land on square/box number 25 wins the game. The players start off the
board (equivalent to position 0).

3. Each player rolls 2 dice which tells them the number of squares/boxes to move, and flips a coin to determine the direction in which they move: heads player moves forward, tails
player moves backwards.

比如:到了第23格,必须只能投出2点才能到打25,如果大于两点,保持不动,其他情况相同

在0格时,如果硬币投出反面,将保持不动,因为没有负格

程序是这样执行的:

player1 is at box # 7(7) player2 is at box # 0(-12)
player1 is at box # 0(-8) player2 is at box # 0(-10)
player1 is at box # 0(-7) player2 is at box # 8(8)
player1 is at box # 7(7) player2 is at box # 1(-7)
player1 is at box # 0(-7) player2 is at box # 0(-8)
player1 is at box # 10(10) player2 is at box # 0(-4)
p

#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

int GenerateDice();
int GenerateDirect();
int GetNextPos( int curPos, int direct, int dice);

int main()
{
int dice1,dice2,direct1, direct2,squa1=0,squa2=0,d1,d2,pos1,pos2;
srand(time(0));

cout<<time(0)<<endl
<<rand()<<endl
<<rand()<<endl
<<rand()<<endl;
do
{
dice1 = GenerateDice();
dice2 = GenerateDice();

direct1 = GenerateDirect();
direct2 = GenerateDirect();

squa1 = GetNextPos( squa1, direct1, dice1);
squa2 = GetNextPos( squa2, direct2, dice2);
if (25 == squa1 && 25 == squa2)
{
break;
}
cout << "Player1 is at box # " << squa1 << "(" << direct1