#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
int turn, square;
long game, totalgames;
int seed;
int chutehit[10], ladderhit[9];
float RunningTurnTotal;
float average;
char reply;
void ChuteStats()
{printf("Chute and Ladder Statistics:\n\n");
printf("Chute0: %d Ladder0: %d\n", chutehit[0], ladderhit[0]);
printf("Chute1: %d Ladder1: %d\n", chutehit[1], ladderhit[1]);
printf("Chute2: %d Ladder2: %d\n", chutehit[2], ladderhit[2]);
printf("Chute3: %d Ladder3: %d\n", chutehit[3], ladderhit[3]);
printf("Chute4: %d Ladder4: %d\n", chutehit[4], ladderhit[4]);
printf("Chute5: %d Ladder5: %d\n", chutehit[5], ladderhit[5]);
printf("Chute6: %d Ladder6: %d\n", chutehit[6], ladderhit[6]);
printf("Chute7: %d Ladder7: %d\n", chutehit[7], ladderhit[7]);
printf("Chute8: %d Ladder8: %d\n", chutehit[8], ladderhit[8]);
printf("Chute9: %d \n", chutehit[9]);
}
int main()
{
printf("Welcome to the Chutes and Ladders simulation \n");
printf("...\n");
srand(1);
//printf("How many games would you like me to run? __ ");
//scanf("%i",&totalgames);
///printf("\n You have chosen to run %i games... thank you! \n",
totalgames);
totalgames+=2;
RunningTurnTotal=0.0;
game=1;
do{
turn=0;
square=0; /** Reset game **/
do /** Begin game loop
**/
{
++turn;
RunningTurnTotal = RunningTurnTotal + 1;
square = square + 1 + rand()%6; /** Spin and move
**/
printf("square =%d \n",square);
if (square == 1) {square=23; ++ladderhit[0];} /** Ladders? **/
if (square == 4) {square=14; ++ladderhit[1];}
if (square == 9) {square=31; ++ladderhit[2];}
if (square == 21) {square=42; ++ladderhit[3];}
if (square == 28) {square=84; ++ladderhit[4];}
if (square == 36) {square=44; ++ladderhit[5];}
if (square == 51) {square=67; ++ladderhit[6];}
if (square == 71) {square=91; ++ladderhit[7];}
if (square == 80) {square=100;++ladderhit[8];}/// so when 80
comes raech to our goal exit
if (square == 98) {square=78; ++chutehit[0];} /** Chutes ? **/
if (square == 95) {square=75; ++chutehit[1];}
if (square == 93) {square=73; ++chutehit[2];}
if (square == 87) {square=24; ++chutehit[3];}
if (square == 62) {square=19; ++chutehit[4];}
if (square == 64) {square=60; ++chutehit[5];}
if (square == 56) {square=53; ++chutehit[6];}
if (square == 49) {square=11; ++chutehit[7];}
if (square == 48) {square=26; ++chutehit[8];}
if (square == 16) {square=6; ++chutehit[9];}
} while (square<100);//terminate if random no. is > 100
printf("\n\n Game over after %d turns\n", turn);
printf("\nSimulation complete... beginning statistical
analysis...\n\n");
printf("Total number of games played: %d \n", game);
printf("Total number of turns: %f \n", RunningTurnTotal);
average = RunningTurnTotal / game;
printf("Avg number of turns per game: %f \n", average);
printf("\n");
ChuteStats();
printf("\n");
++game;
printf("\n\n Would you like to run the simulation again?
(1=Yes)...");
scanf("%i",&reply);
if(reply==1)//e.g. reply==1
totalgames+=1;
else
exit(0);// exit
} while (game<totalgames);
getch();
}
///////////////////////////////O(N^2) solution Does solution exits
in O(n) or (nlogn)..????? reply me sum1 git dis..
//i will post analysis of dsi program later i m solving usig OOPS
(Java) to represnt everything as object
//right me if i m wrong or hw we can improve dis alog.
Regards
Shashank Mani " Don't Be Evil u Can Earn While U Learn"
BIT Mesra-2010
09166674831
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.