Newsgroups: alt.religion.roshambo,alt.religion.kibology,alt.religion.secular.atavism,talk.religion.newage,alt.slack Article: 87 of alt.religion.roshambo From: friedman@Xenon.Stanford.EDU (Perry B. Friedman) Subject: Play along at home with your own Roshambot Date: 21 Sep 1995 22:49:05 GMT Organization: Computer Science Department, Stanford University. Save, compile, and play, er worship, along at home. #include #include #include #define RANDOM 0 #define DOMINATE 1 #define LOSE 2 #define BART 3 #define PREDICT 4 #define PREDICT_TRUE 5 #define TRUE 1 #define FALSE 0 #define ROCK 0 char *went[3] = {"rock","paper","scissor"}; main(argc,argv) char argc,**argv; { int strategy,done = FALSE, won, lost, tied, games, machine, opponent; char buff[80]; won = lost = tied = games = 0; if (argc == 2) if (!strcmp(argv[1],"-bart")) strategy = BART; else if (!strcmp(argv[1],"-perry")) strategy = DOMINATE; else if (!strcmp(argv[1],"-bruce")) strategy = LOSE; else if (!strcmp(argv[1],"-perry2")) strategy = PREDICT; else if (!strcmp(argv[1],"-hint")) strategy = PREDICT_TRUE; else done = TRUE; else strategy = RANDOM; if (done || (argc > 2) ) { printf("Usage: %s [-perry|-bruce|-bart|-perry2|-hint|-help]\n\ options:\n\ -perry : Computer plays as good as Perry. You're screwed!\n\ -bruce : You're locked!\n\ -bart : Good old rock. Nothing beats rock.\n\ -perry2 : Computer tells you which way it's going - only it can LIE!\n\ -hint : Computer REALLY tells you which way it's going (sort of a cross\n\ between Bart and Bruce).\n\ -help : Prints this message.\n",argv[0]); exit(0); } srand(time(0)); while (!done) { switch (strategy) { case PREDICT : case PREDICT_TRUE : case RANDOM : machine = rand() % 3; if (strategy == PREDICT) printf("I'm going %s.\n",went[rand() % 3]); else if (strategy == PREDICT_TRUE) printf("I'm going %s.\n",went[machine]); break; case BART : machine = ROCK; break; default : break; } printf("What are you going? (r = rock, p = paper, s = scissors, q = quit) : "); gets(buff); switch (buff[0]) { case 'q' : done = TRUE; continue; case 'r' : opponent = 0; break; case 'p' : opponent = 1; break; case 's' : opponent = 2; break; default: printf("Invalid response\n"); continue; } if (strategy == DOMINATE) machine = (opponent + 1) % 3; else if (strategy == LOSE) machine = (opponent + 2) % 3; games++; printf("\tI went %s - ", went[machine]); if (machine == opponent) { tied++; printf("We tied!\n"); } else { if (((machine + 1) % 3) == opponent) { won++; printf("You win!!\n"); } else { lost++; printf("I win!\n"); } } printf("Results so far :\n\ You have won %d, you have lost %d, and you have tied %d games\n\n", won,lost,tied); } printf("Final results :\n\ You have won %d, you have lost %d, and you have tied %d games\n\n", won,lost,tied); if (games) printf("Stats for %d games :\n\ won : %3.2f\%\n\ lost: %3.2f\%\n\ tied: %3.2f\%\n", games, (float)100*won/games,(float)100*lost/games,(float)100*tied/games); }