char getwin( int two,int three,int five,int seven ) { if ( w[two][three][five][seven] != -1 ) return w[two][three][five][seven]; // base case long double x=1.0; x*=pow( 2.0, two ); x*=pow( 3.0, three ); x*=pow( 5.0, five ); x*=pow( 7.0, seven ); if ( x+0.00000001 >= (long double)n ) return 0; // recursive case :) int k=0; k+=!getwin(two+1,three,five,seven); // 2 k+=!getwin(two,three+1,five,seven); // 3 k+=!getwin(two+2,three,five,seven); // 4 k+=!getwin(two,three,five+1,seven); // 5 k+=!getwin(two+1,three+1,five,seven); // 6 k+=!getwin(two,three,five,seven+1); // 7 k+=!getwin(two+3,three,five,seven); // 8 k+=!getwin(two,three+2,five,seven); // 9 return w[two][three][five][seven]= k>0; }
NCURSES_SP_NAME(scr_init) (NCURSES_SP_DCLx const char *file) { FILE *fp = 0; int code = ERR; T((T_CALLED("scr_init(%p,%s)"), (void *) SP_PARM, _nc_visbuf(file))); if (SP_PARM != 0 && #ifdef USE_TERM_DRIVER InfoOf(SP_PARM).caninit #else !(exit_ca_mode && non_rev_rmcup) #endif ) { if (_nc_access(file, R_OK) >= 0 && (fp = fopen(file, "rb")) != 0) { delwin(CurScreen(SP_PARM)); CurScreen(SP_PARM) = getwin(fp); #if !USE_REENTRANT curscr = CurScreen(SP_PARM); #endif (void) fclose(fp); if (CurScreen(SP_PARM) != 0) { code = OK; } } } returnCode(code); }
int main(void) { SetConsoleTitle("Number Casino - 1.3.1 RELEASE"); system("COLOR 5C"); srand ( time(NULL) ); //randomize printf("Welcome to the Number Casino!\n"); //introduce the user printf("(C) 2015 Penguin Software, inc.\n"); printf("Programmed in C by Adrian Zhang.\n"); sleep(2); //wait 2 secs MENU:system("cls"); //clear it up and roll printf("1. SHOW PRIZES\n"); printf("2. BEGIN GAME\n"); printf("3. HOW-TO"); printf("\nYour choice: "); scanf("%i",&choice); switch (choice) { case 1: printf("Prizes: $500 for 3 matching, and $1000 for all matching.\n"); printf("Interlocking matches are worth $750, also!\n"); printf("Rolling once will cost $1.\n"); sleep(3); goto MENU; case 2: roll(); printf("\n"); getwin(); //win or lose? break; case 3: printf("The game will generate 4 random numbers.\n"); printf("If they match, you get money!\n"); printf("If they do not match, you gain nothing.\n"); printf("Rolling once will always take away $1.\n"); sleep(3); goto MENU; } }
int main (const int argc, const char * const * argv) { if (argc < 2) { Gtfo (__LINE__, "読み取るパッドが渡されませんでした。"); } initscr (); keypad (stdscr, TRUE); noecho (); start_color (); curs_set (0); int nMaxY, nMaxX; getmaxyx (stdscr, nMaxY, nMaxX); nMaxY--; nMaxX--; FILE * file = fopen (argv[1], "r"); if (file == NULL) { Gtfo (__LINE__, "%sを読み取れませんでした。", argv[1]); } // Load window and store dimensions. WINDOW * pad = getwin (file); int nPadH, nPadW; getmaxyx (pad, nPadH, nPadW); int nPadBegY, nPadBegX; getbegyx (pad, nPadBegY, nPadBegX); nPadH -= nPadBegY; nPadW -= nPadBegX; bool bEnd = false; unsigned uPosY = 0; while (!bEnd) { int n = getch (); switch (n) { case 'j': if (! (uPosY + 1 + nMaxY >= nPadH)) uPosY++; break; case 'k': if (uPosY) uPosY--; break; case 'q': bEnd = true; break; } prefresh (pad, uPosY, 0, 0, 0, nMaxY, nMaxX); } endwin (); }
int main() { int i,j,k; while ( 1==scanf("%u", &n ) ) { memset( w, -1, sizeof(w) ); if ( getwin(0,0,0,0) ) printf( "Stan wins.\n" ); else printf( "Ollie wins.\n" ); } return 0; }
c_debug() { register struct ww *w; if (!terse) wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", cmdwin); wwcurtowin(cmdwin); while (wwpeekc() < 0) wwiomux(); if (!terse) wwputc('\n', cmdwin); switch (wwgetc()) { case 'm': wwdumpsmap(); break; case 'n': wwdumpns(); break; case 'o': wwdumpos(); break; case 's': debug_str(); break; case 'v': if ((w = getwin()) != 0) wwdumpnvis(w); break; case 'w': if ((w = getwin()) != 0) wwdumpwin(w); break; default: wwbell(); } }
scr_restore(const char *file) { FILE *fp = 0; T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); if (_nc_access(file, R_OK) < 0 || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); } else { delwin(newscr); SP->_newscr = newscr = getwin(fp); (void) fclose(fp); returnCode(OK); } }
int scr_restore(const char *file) { FILE *fp; T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); if ((fp = fopen(file, "rb")) == 0) returnCode(ERR); else { delwin(newscr); newscr = getwin(fp); (void) fclose(fp); returnCode(OK); } }
NCURSES_SP_NAME(scr_restore) (NCURSES_SP_DCLx const char *file) { FILE *fp = 0; T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); if (_nc_access(file, R_OK) < 0 || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); } else { delwin(newscr); SP_PARM->_newscr = getwin(fp); #if !USE_REENTRANT newscr = SP_PARM->_newscr; #endif (void) fclose(fp); returnCode(OK); } }
scr_init(const char *file) { FILE *fp = 0; T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); if (exit_ca_mode && non_rev_rmcup) returnCode(ERR); if (_nc_access(file, R_OK) < 0 || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); } else { delwin(curscr); SP->_curscr = curscr = getwin(fp); (void) fclose(fp); returnCode(OK); } }
int scr_restore(const char *filename) { FILE *filep; PDC_LOG(("scr_restore() - called: filename %s\n", filename)); if (filename && (filep = fopen(filename, "rb")) != NULL) { WINDOW *replacement = getwin(filep); fclose(filep); if (replacement) { int result = overwrite(replacement, curscr); delwin(replacement); return result; } } return ERR; }
NCURSES_SP_NAME(scr_restore) (NCURSES_SP_DCLx const char *file) { FILE *fp = 0; int code = ERR; T((T_CALLED("scr_restore(%p,%s)"), (void *) SP_PARM, _nc_visbuf(file))); if (_nc_access(file, R_OK) >= 0 && (fp = fopen(file, "rb")) != 0) { delwin(NewScreen(SP_PARM)); NewScreen(SP_PARM) = getwin(fp); #if !USE_REENTRANT newscr = NewScreen(SP_PARM); #endif (void) fclose(fp); if (NewScreen(SP_PARM) != 0) { code = OK; } } returnCode(code); }
scr_init(const char *file) { FILE *fp = 0; struct stat stb; T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); if (exit_ca_mode && non_rev_rmcup) returnCode(ERR); if (_nc_access(file, R_OK) < 0 || (fp = fopen(file, "rb")) == 0) returnCode(ERR); else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) returnCode(ERR); else { delwin(curscr); curscr = getwin(fp); (void) fclose(fp); returnCode(OK); } }
NCURSES_SP_NAME(scr_init) (NCURSES_SP_DCLx const char *file) { FILE *fp = 0; T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); if (exit_ca_mode && non_rev_rmcup) returnCode(ERR); if (_nc_access(file, R_OK) < 0 || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); } else { delwin(curscr); SP_PARM->_curscr = getwin(fp); #if !USE_REENTRANT curscr = SP_PARM->_curscr; #endif (void) fclose(fp); returnCode(OK); } }
void docmd(void) { int c; struct ww *w; char out = 0; while (!out && !quit) { if ((c = wwgetc()) < 0) { if (terse) wwsetcursor(0, 0); else { wwputs("Command: ", cmdwin); wwcurtowin(cmdwin); } do wwiomux(); while ((c = wwgetc()) < 0); } if (!terse) wwputc('\n', cmdwin); switch (c) { default: if (c != escapec) break; case 'h': case 'j': case 'k': case 'l': case 'y': case 'p': case ctrl('y'): case ctrl('e'): case ctrl('u'): case ctrl('d'): case ctrl('b'): case ctrl('f'): case ctrl('s'): case ctrl('q'): case ctrl('['): if (selwin == 0) { error("No window."); continue; } } switch (c) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if ((w = window[c - '1']) == 0) { error("%c: No such window.", c); break; } setselwin(w); if (checkproc(selwin) >= 0) out = 1; break; case '%': if ((w = getwin()) != 0) setselwin(w); break; case ctrl('^'): if (lastselwin != 0) { setselwin(lastselwin); if (checkproc(selwin) >= 0) out = 1; } else error("No previous window."); break; case 'c': if ((w = getwin()) != 0) closewin(w); break; case 'w': c_window(); break; case 'm': if ((w = getwin()) != 0) c_move(w); break; case 'M': if ((w = getwin()) != 0) movewin(w, w->ww_alt.t, w->ww_alt.l); break; case 's': if ((w = getwin()) != 0) c_size(w); break; case 'S': if ((w = getwin()) != 0) sizewin(w, w->ww_alt.nr, w->ww_alt.nc); break; case 'y': c_yank(); break; case 'p': c_put(); break; case ':': c_colon(); break; case 'h': (void) wwwrite(selwin, "\b", 1); break; case 'j': (void) wwwrite(selwin, "\n", 1); break; case 'k': (void) wwwrite(selwin, "\033A", 2); break; case 'l': (void) wwwrite(selwin, "\033C", 2); break; case ctrl('e'): wwscroll(selwin, 1); break; case ctrl('y'): wwscroll(selwin, -1); break; case ctrl('d'): wwscroll(selwin, selwin->ww_w.nr / 2); break; case ctrl('u'): wwscroll(selwin, - selwin->ww_w.nr / 2); break; case ctrl('f'): wwscroll(selwin, selwin->ww_w.nr); break; case ctrl('b'): wwscroll(selwin, - selwin->ww_w.nr); break; case ctrl('s'): stopwin(selwin); break; case ctrl('q'): startwin(selwin); break; case ctrl('l'): wwredraw(); break; case '?': c_help(); break; case ctrl('['): if (checkproc(selwin) >= 0) out = 1; break; case ctrl('z'): wwsuspend(); break; case 'q': c_quit(); break; /* debugging stuff */ case '&': if (debug) { c_debug(); break; } default: if (c == escapec) { if (checkproc(selwin) >= 0) { (void) write(selwin->ww_pty, &escapec, 1); out = 1; } } else { if (!terse) wwbell(); error("Type ? for help."); } } } if (!quit) setcmd(0); }
int scr_reset(FILE *filep, int type) { WINDOW *win = NULL, *win1 = NULL; int *hash, y; char clearit = FALSE; short magic; struct stat statbuf; time_t ttytime; if (type != 1 && exit_ca_mode && *exit_ca_mode && non_rev_rmcup) { if (type == 0) goto err; else { #ifdef DEBUG if (outf) fprintf(outf, "clear it because of " "exit_ca_mode\n"); #endif /* DEBUG */ clearit = TRUE; } } /* check magic number */ if (fread((char *) &magic, sizeof (short), 1, filep) != 1) goto err; if (magic != SVR3_DUMP_MAGIC_NUMBER) goto err; /* get modification time of image in file */ if (fread((char *) &ttytime, sizeof (time_t), 1, filep) != 1) goto err; if ((type != 1) && ((ttyname(cur_term->Filedes) == NULL) || (fstat(cur_term->Filedes, &statbuf) < 0) || (statbuf.st_mtime != ttytime))) { if (type == 0) goto err; else { #ifdef DEBUG if (outf) fprintf(outf, "Filedes = %hd, " "statbuf.st_mtime = %d, " "ttytime = %d\n", cur_term->Filedes, statbuf.st_mtime, ttytime); #endif /* DEBUG */ clearit = TRUE; } } /* if get here, everything is ok, read the curscr image */ if (((win = getwin(filep)) == NULL) || ((type == 2) && ((win1 = dupwin(win)) == NULL)) || (win->_maxy != curscr->_maxy) || (win->_maxx != curscr->_maxx) || /* soft labels */ (fread((char *) &magic, sizeof (int), 1, filep) != 1)) goto err; /* * if soft labels were dumped, we would like either read them * or advance the file pointer pass them */ if (magic) { short i, labmax, lablen; SLK_MAP *slk = SP->slk; /* * Why doesn't the following line and the two below * that access those variables work ? */ /* * char **labdis = SP->slk->_ldis, **labval = SP->slk->_lval; */ if ((fread((char *) &labmax, sizeof (short), 1, filep) != 1) || (fread((char *) &lablen, sizeof (short), 1, filep) != 1)) { goto err; } if (slk != NULL) { if ((labmax != slk->_num) || (lablen != (slk->_len + 1))) goto err; for (i = 0; i < labmax; i++) { /* * if ((fread(labdis[i], sizeof (char), lablen, * filep) != lablen) || * (fread(labval[i], sizeof (char), lablen, * filep != lablen)) */ if ((fread(slk->_ldis[i], sizeof (char), lablen, filep) != lablen) || (fread(slk->_lval[i], sizeof (char), lablen, filep) != lablen)) { goto err; } } (*_do_slk_tch)(); } else { if (fseek(filep, (long) (2 * labmax * lablen * sizeof (char)), 1) != 0) goto err; } } /* read the color information(if any) from the file */ if (fread((char *) &magic, sizeof (int), 1, filep) != 1) goto err; if (magic) { int colors, color_pairs; bool could_change; int i; /* if the new terminal doesn't support colors, or it supports */ /* less colors (or color_pairs) than the old terminal, or */ /* start_color() has not been called, simply advance the file */ /* pointer pass the color related info. */ /* Note: must to read the first line of color info, even if the */ /* new terminal doesn't support color, in order to know how to */ /* deal with the rest of the file */ if ((fread((char *) &colors, sizeof (int), 1, filep) != 1) || (fread((char *) &color_pairs, sizeof (int), 1, filep) != 1) || (fread((char *) &could_change, sizeof (char), 1, filep) != 1)) goto err; if (max_pairs == -1 || cur_term->_pairs_tbl == NULL || colors > max_colors || color_pairs > max_pairs) { if (fseek(filep, (long) (colors * sizeof (_Color) + color_pairs * sizeof (_Color_pair)), 1) != 0) goto err; } else { _Color_pair *ptp, *save_ptp; /* if both old and new terminals could modify colors, read in */ /* color table, and call init_color for each color */ if (could_change) { if (can_change) { _Color *ctp, *save_ctp; if ((save_ctp = (ctp = (_Color *) malloc(colors * sizeof (_Color)))) == NULL) goto err; if (fread(ctp, sizeof (_Color), colors, filep) != colors) goto err; for (i = 0; i < colors; i++, ctp++) { /* LINTED */ (void) init_color((short)i, ctp->r, ctp->g, ctp->b); } free(save_ctp); } else { /* the old terminal could modify colors, by the new one */ /* cannot skip over color_table info. */ if (fseek(filep, (long) (colors * sizeof (_Color)), 1) != 0) goto err; } } /* read color_pairs info. call init_pair for each pair */ if ((save_ptp = (ptp = (_Color_pair *) malloc(color_pairs * sizeof (_Color_pair)))) == NULL) goto err; if (fread(ptp, sizeof (_Color_pair), color_pairs, filep) != color_pairs) { err: if (win != NULL) (void) delwin(win); if (win1 != NULL) (void) delwin(win1); if (type == 0) curscr->_clear = TRUE; return (ERR); } for (i = 1, ++ptp; i <= color_pairs; i++, ptp++) { if (ptp->init) /* LINTED */ (void) init_pair((short)i, ptp->foreground, ptp->background); } free(save_ptp); } } /* substitute read in window for the curscr */ switch (type) { case 1: case 2: (void) delwin(_virtscr); hash = _VIRTHASH; if (type == 1) { SP->virt_scr = _virtscr = win; _VIRTTOP = 0; _VIRTBOT = curscr->_maxy - 1; break; } SP->virt_scr = _virtscr = win1; _VIRTTOP = curscr->_maxy; _VIRTBOT = -1; /* clear the hash table */ for (y = curscr->_maxy; y > 0; --y) *hash++ = _NOHASH; /* LINTED */ /* Known fall-through on case statement. */ case 0: { int saveflag = curscr->_flags & _CANT_BE_IMMED; (void) delwin(curscr); SP->cur_scr = curscr = win; curscr->_sync = TRUE; curscr->_flags |= saveflag; hash = _CURHASH; } } /* clear the hash table */ for (y = curscr->_maxy; y > 0; --y) *hash++ = _NOHASH; curscr->_clear = clearit; return (OK); }
getwin() { if(a == b && b == c && c == d) { //jackpot! printf("\nCongragulations! You won: $1000!\n"); tot_cash = tot_cash + 1000; showCash(); printf("Acheivement Get: Hit It Big!\n"); again = 'x'; while(again != 'y' || again != 'Y' || again != 'n' || again != 'N') { printf("\nWould you like to re-roll? (Y/N) "); scanf("%c",&again); if(again == 'y' || again == 'Y') { roll(); getwin(); } if(again == 'n' || again == 'N') { sleep(1); exit; } } } if(a == b && b == c || b == c && c == d) { //3-in-row printf("\nCongragulations! You won: $500!\n"); tot_cash = tot_cash + 500; showCash(); again = 'x'; while(again != 'y' || again != 'Y' || again != 'n' || again != 'N') { printf("\nWould you like to re-roll? (Y/N) "); scanf("%c",&again); if(again == 'y' || again == 'Y') { roll(); getwin(); } if(again == 'n' || again == 'N') { exit; } } } if(a == c && b == d) { //1st number = 3rd number and 2nd number = 4th number printf("\nCongragulations! You won: $750!\n"); tot_cash = tot_cash + 750; showCash(); again = 'x'; while(again != 'y' || again != 'Y' || again != 'n' || again != 'N') { printf("\nWould you like to re-roll? (Y/N) "); scanf("%c",&again); if(again == 'y' || again == 'Y') { roll(); getwin(); } if(again == 'n' || again == 'N') { sleep(1); exit; } } } else { //whoops! no matches. printf("\nThe numbers don't match! Try again.\n"); showCash(); again = 'x'; printf("Insert another coin? (Y or N)"); scanf("%c",&choice); again = 'x'; while(again != 'y' || again != 'Y' || again != 'n' || again != 'N') { printf("\nWould you like to re-roll? (Y/N) "); scanf("%c",&again); if(again == 'y' || again == 'Y') { roll(); getwin(); } if(again == 'n' || again == 'N') { sleep(1); exit; } } } }