/* * MasterMind v1.21 for BBBS, Copyright 1995, Kim Heino. * * You are allowed to use this game in your BBBS and distribute it UNCHANGED * to others. You are NOT allowed to sell it, include it to your program or * distribute it without this source code. You are allowed to modify it to * your personal usage with following restrictions: * - the copyright message must be unchanged * - upper ascii characters are not allowed (IBM graphics, #128-#255) * - you are not allowed to distribute your modified version * * THIS IS NOT PUBLIC DOMAIN OR FREE SOFTWARE! */ #include char make_correct() { int foo; foo=rand() % 4096; return(sprintf("%u%u%u%u",((foo/512)&7)+1,((foo/64)&7)+1,((foo/8)&7)+1,((foo/1)&7)+1)); } char mm_input(int count) { int i; char ret; ret=input(sprintf("\nYour Guess #%u: ",count),4,128); while (strlen(ret)<4) { ret=sprintf("%s1",ret); } while (i=pos(" ",ret)) { ret=sprintf("%s1%s",copy(ret,1,i-1),copy(ret,i+1,4)); } printf("\e[1A\e[K\e[1A"); if (stupcase(copy(ret,1,1))=="Q") exit(0); return(ret); } int play() { int count, tcount, game, i1, i2; char correct, user, foouser, show, cor; tcount=0; for (game=0; bv_carrier && game<5; game=game+1) { printf("\e[1;1H\e[2J"); printf(" MasterMind v1.21 for BBBS, Copyright 1995, Kim Heino.\n"); printf("\nGame #%u.\n\n",game+1); count=0; correct=make_correct(); do { count=count+1; foouser=user=mm_input(count); show=""; cor=correct; for (i1=1; i1<5; i1=i1+1) { if (copy(foouser,i1,1)==copy(cor,i1,1)) { show=sprintf("%sO ",show); cor=sprintf("%s %s",copy(cor,1,i1-1),copy(cor,i1+1,4)); foouser=sprintf("%s-%s",copy(foouser,1,i1-1),copy(foouser,i1+1,4)); } } for (i2=1; i2<5; i2=i2+1) { if (i1=pos(copy(foouser,i2,1),cor)) { show=sprintf("%sX ",show); cor=sprintf("%s %s",copy(cor,1,i1-1),copy(cor,i1+1,4)); } } while (strlen(show)<8) { show=sprintf("%s- ",show); } printf("%2u: %s %s %s %s -> %s\n",count,copy(user,1,1),copy(user,2,1),copy(user,3,1),copy(user,4,1),show); } while (bv_carrier && count<20 && user!=correct); if (user!=correct) printf("\nCorrect numbers were %s.\n",correct); else printf("\nCorrect!\n"); input("\nPress Enter.",1,128); tcount=tcount+count; } return(tcount); } int show_start() { printf("\e[1;1H\e[2J"); printf(" MasterMind v1.21 for BBBS, Copyright 1995, Kim Heino.\n"); printf("\n"); printf("The goal of MasterMind is to guess four numbers from 1 to 8. Game will reply\n"); printf("with 'O' if correct number in correct place, 'X' if matching number but in\n"); printf("wrong place and '-' if the number doesn't match at all. You have 20 tries to\n"); printf("guess all four numbers. The total number of guesses of five games will be\n"); printf("recorded to the TopTen list.\n"); input("\nPress Enter.",1,128); } int better(char s, char r) { char s1, r1; s1=copy(s,1,3); r1=copy(r,1,3); while (copy(s1,1,1)==" ") s1=copy(s1,2,3); while (copy(r1,1,1)==" ") r1=copy(r1,2,3); if (s10; i=i-1) { if (better(r[i],r[i-1])) { s=r[i]; r[i]=r[i-1]; r[i-1]=s; } } f=fopen(sprintf("%smastermind.top",bg_scriptdir),"wt"); for (i=0; i<10; i=i+1) fprintf(f,"%s\n",r[i]); fclose(f); } printf("\e[1;1H\e[2J"); printf(" MasterMind v1.21 for BBBS, Copyright 1995, Kim Heino.\n"); printf("\n"); printf(" Score Name\n"); printf(" ===== =============================\n"); for (i=0; i<10; i=i+1) { printf(" %2u: %s\n",i+1,r[i]); } printf("\n"); printf(" Your score was %u.\n",count); printf("\n"); } int main() { randomize(); show_start(); topten(play()); }