// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from // laanwj, "replicating the actual usage patterns of the client is hard though, // many times micro-benchmarks of the database showed completely different // characteristics than e.g. reindex timings. But that's not a requirement of // every benchmark." // (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) static void CCoinsCaching(benchmark::State& state) { CBasicKeyStore keystore; CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins); CMutableTransaction t1; t1.vin.resize(3); t1.vin[0].prevout.hash = dummyTransactions[0].GetHash(); t1.vin[0].prevout.n = 1; t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0); t1.vin[1].prevout.hash = dummyTransactions[1].GetHash(); t1.vin[1].prevout.n = 0; t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4); t1.vin[2].prevout.hash = dummyTransactions[1].GetHash(); t1.vin[2].prevout.n = 1; t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4); t1.vout.resize(2); t1.vout[0].nValue = 90 * CENT; t1.vout[0].scriptPubKey << OP_1; // Benchmark. while (state.KeepRunning()) { bool success = AreInputsStandard(t1, coins); assert(success); CAmount value = coins.GetValueIn(t1); assert(value == (50 + 21 + 22) * CENT); } }
int main(){ int array[]={2}; vector<int>coins(array,array+1); Solution*s=new Solution; cout<<s->coinChange(coins,3)<<endl; return 0; }
void simdt(const double &t, const double &dt, const List &c, NetSim &n) { double Ival = 0; if(Iiter<I.n_elem) { Ival = I(Iiter); } v += dt*(-a % w -v + Ival)/(asD("tau",c)); w += dt*(v-w)/(asD("tau",c)); arma:: vec coins(N, arma::fill::randu); for(size_t ni=0; ni<N; ni++) { if( ((v(ni)*dt)) > coins(ni) ) { n.prop_spike(ni+1, t); } stat_v[ni].push_back(v(ni)); stat_w[ni].push_back(w(ni)); } Iiter++; }
void GAME :: change(int i,int j,int p,int q) { A[p][q].coin=A[i][j].coin; A[p][q].color=A[i][j].color; A[i][j].coin='N'; A[i][j].color=null; board(); coins(); setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); setcolor(RED); outtextxy(10,getmaxy()-15,"Congrats !! You advance to next level !!"); level++; getch(); }
void main() { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); cleardevice(); // char str[1]; str[1]='\0'; file.open("Info.TXT",ios::in|ios::binary); if(!file) cout<<"File couldnt be opened"; x=20; y=getmaxy()-70; settextstyle(2,0,5); setvalues(); board(); coins(); getch(); typeon(); getch(); cleardevice(); x=20; y=200; pic("ch pic"); typeon(); y+=20; typeon(); getch(); cleardevice(); pic("ch pic2"); x=20; y=200; typeon(); getch(); cleardevice(); king(getmaxx()/2-30,30,1); x=20; y=100; typeon(); getch(); cleardevice(); rook(getmaxx()/2-30,30,1); x=20; y=100; typeon(); getch(); cleardevice(); bishop(getmaxx()/2-30,30,1); x=20; y=100; typeon(); getch(); cleardevice(); queen(getmaxx()/2-30,30,1); x=20; y=100; typeon(); getch(); cleardevice(); knight(getmaxx()/2-30,30,1); x=20; y=100; typeon(); getch(); cleardevice(); pawn(getmaxx()/2-30,30,1); x=20; y=100; typeon(); getch(); cleardevice(); pic("ch pic3"); x=20; y=50; typeon(); getch(); file.close(); closegraph(); }
int GAME :: common() { board(); coins(); char s; int i=7,j=0; while(1) { setcolor(RED); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); s=getch(); setcolor(WHITE); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); getpos(i,j,s); redraw(); setcolor(RED); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"White to play and mate in 1 move ..."); if(s=='5') { if(A[i][j].color==null) { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"Select a coin to make a move !!"); } else if(A[i][j].color==black) { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"It is white chance to play !!"); } else if(A[i][j].color==white) { stop=0; setcolor(YELLOW); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); int p=i,q=j; while(stop==0) { s=getch(); setcolor(WHITE); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); setcolor(YELLOW); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); getpos(p,q,s); setcolor(RED); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"White to play and mate in 1 move ..."); if(s=='5') { if(level==1 && i==1 && j==5 && A[i][j].coin=='R' && A[i][j].color==white && p==1&&q==2 ) { change(i,j,p,q); return 0; } else if(level==2 && i==3&&j==7 && A[i][j].coin=='R' && A[i][j].color==white && p==0&&q==7 ) { change(i,j,p,q); return 0; } else if(level==3 && i==6&&j==6 && A[i][j].coin=='B' && A[i][j].color==white && p==3&&q==3 ) { change(i,j,p,q); return 0; } else if(level==4 && i==2&&j==4 && A[i][j].coin=='R' && A[i][j].color==white && p==2&&q==7 ) { change(i,j,p,q); return 0; } else if(level==5 && i==4&&j==4 && A[i][j].coin=='H' && A[i][j].color==white && p==5&&q==6 ) { change(i,j,p,q); return 0; } else if(level==6 && i==0&&j==7 && A[i][j].coin=='Q' && A[i][j].color==white && p==0&&q==4 ) { change(i,j,p,q); return 0; } else if(level==7 && i==1&&j==0 && A[i][j].coin=='Q' && A[i][j].color==white && p==5&&q==0 ) { change(i,j,p,q); return 0; } else if(level==8 && i==6&&j==3 && A[i][j].coin=='B' && A[i][j].color==white && p==3&&q==6 ) { change(i,j,p,q); return 0; } else if(level==9 && i==6&&j==4 && A[i][j].coin=='P' && A[i][j].color==white && p==5&&q==4 ) { change(i,j,p,q); return 0; } else if(level==10 && i==4&&j==4 && A[i][j].coin=='H' && A[i][j].color==white && p==2&&q==3 ) { change(i,j,p,q); return 0; } else if(level==11 && i==2&&j==6 && A[i][j].coin=='Q' && A[i][j].color==white && p==2&&q==5 ) { change(i,j,p,q); return 0; } else if(level==12 && i==3&&j==3 && A[i][j].coin=='H' && A[i][j].color==white && p==1&&q==2 ) { change(i,j,p,q); return 0; } else if(level==13 && i==2&&j==7 && A[i][j].coin=='Q' && A[i][j].color==white && p==1&&q==6 ) { change(i,j,p,q); return 0; } else if(level==14 && i==3&&j==7 && A[i][j].coin=='Q' && A[i][j].color==white && p==1&&q==5 ) { change(i,j,p,q); return 0; } else if(level==15 && i==4&&j==5 && A[i][j].coin=='H' && A[i][j].color==white && p==2&&q==6 ) { change(i,j,p,q); getch(); return 0; } else if(p==i && q==j) { setcolor(RED); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); stop++; } else { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); outtextxy(10,getmaxy()-15,"Nope ... Try again ... "); getch(); setcolor(WHITE); rectangle(A[i][j].x,A[i][j].y,A[i][j].x+43,A[i][j].y+43); rectangle(A[p][q].x,A[p][q].y,A[p][q].x+43,A[p][q].y+43); stop++; lives--; drawextra(level,lives); if(lives==0) { setfillstyle(SOLID_FILL,WHITE); bar(0,getmaxy()-15,getmaxx(),getmaxy()); settextstyle(2,0,4); setcolor(RED); outtextxy(10,getmaxy()-15,"GAME OVER !! "); getch(); spawnl(P_WAIT,"gameovrp.exe",NULL); cleardevice(); exit(0); } i=p; j=q; }}}}}}}
void drawextra(unsigned level,unsigned lives) { cleardevice(); board(); coins(); settextstyle(3,0,1); setcolor(LIGHTGRAY); outtextxy(60,10,"LEVEL : "); outtextxy(350,10,"PASSWORD : "******"LIVES : "); switch(level) { case 1: outtextxy(140,10,"1"); outtextxy(480,10,"krashnaw"); break; case 2: outtextxy(140,10,"2"); outtextxy(480,10,"leastwanted"); break; case 3: outtextxy(140,10,"3"); outtextxy(480,10,"tendlekar"); break; case 4: outtextxy(140,10,"4"); outtextxy(480,10,"thendela"); break; case 5: outtextxy(140,10,"5"); outtextxy(480,10,"tribal"); break; case 6: outtextxy(140,10,"6"); outtextxy(480,10,"chinchan"); break; case 7: outtextxy(140,10,"7"); outtextxy(480,10,"lemonjuice"); break; case 8: outtextxy(140,10,"8"); outtextxy(480,10,"meooow"); break; case 9: outtextxy(140,10,"9"); outtextxy(480,10,"bowie"); break; case 10: outtextxy(140,10,"10"); outtextxy(480,10,"shetre"); break; case 11: outtextxy(140,10,"11"); outtextxy(480,10,"overloaded"); break; case 12: outtextxy(140,10,"12"); outtextxy(480,10,"watboy?"); break; case 13: outtextxy(140,10,"13"); outtextxy(480,10,"theyatheya"); break; case 14: outtextxy(140,10,"14"); outtextxy(480,10,"goymare"); break; case 15: outtextxy(140,10,"15"); outtextxy(480,10,"cummon"); break; } switch(lives) { case 0: outtextxy(270,10,"0"); break; case 1: outtextxy(270,10,"1"); break; case 2: outtextxy(270,10,"2"); break; case 3: outtextxy(270,10,"3"); break; }}
int main() { struct gameState G; FILE *out; int nplayers = 0, ntests=0,i=0,j=0,k[10],redo = 1,seed, currentp=0, actions =0, *played, turn, ncoins=0, buyA = -1; out = fopen("gameResults.out","w"); srand(time(NULL)); nplayers = rand() % 3 + 2; // iterate through multiple tests while(ntests < MAX_TESTS) { turn = 1; seed = rand(); printf("random seed %d ", seed); printf("in tests\n"); fprintf(out, "Initializing game: %d\n", ntests); //pick cards for(i=0;i < 10; i++){ printf("stuck picking cards\n"); //kingdom cards unique no repeats do { redo = 0; k[i] = rand() % 20 + 7; printf("%d ", k[i]); for(j=0; j < i; j++) { if(k[i] == k[j]){ redo = 1; } } } while(redo); } fprintf(out, "Kingdom cards: \n"); for(i=0; i < 10; i++) { fprintf(out,"%s, ", numName(k[i])); } fprintf(out,"\n"); initializeGame(nplayers, k, seed, &G); printf("past init games\n"); //Print player hands /*fprintf(out, "Player hands: \n"); for(i=0; i < nplayers; i++) { fprintf(out,"P%d: {\n",i); for(j=0; j < numHandCards(&G); j++) { //fprintf(out, "\tC%d: %s\n", j, numName(handCard(j, &G))); //debug fprintf(out, "\tC%d: %d\n", j, handCard(j, &G)); } fprintf(out, "}\n"); } */ while(!isGameOver(&G)) { //printf("stuck in game\n"); currentp = whoseTurn(&G); //Print turn player cards and info fprintf(out, "-- P%d turn %d --\n Current hand: {", currentp,turn); for(i=0; i < numHandCards(&G); i++) { fprintf(out, "C%d: %s ", i, numName(handCard(i, &G))); } fprintf(out, "}\n <-- Action Phase -->\n"); //start action phase actions = 0; ncoins = coins(&G); G.coins = ncoins; for(i=0;i < G.numActions;i++) { fprintf(out, "#A: %d\n", G.numActions); played = playing(k, &G); if(played == 0) { fprintf(out, "No playable cards\n"); break; } fprintf(out, "Playing: %s\n Choices: %d, %d, %d\n", numName(played[0]), played[1], played[2], played[3]); if(playCard(played[0], played[1], played[2], played[3], &G) == -1) fprintf(out, "\tFailure to play %s\n", numName(played[0])); } //start buy phase fprintf(out, "<-- Buy Phase --> \n"); for(i=0; i < G.numBuys; i++) { buyA = canBuy(k, &G); fprintf(out, "Buying a %s\n", numName(buyA)); if(buyCard(buyA, &G) == -1) fprintf(out, "\tFailed to buy\n"); G.coins -= getCost(buyA); } //end of turn //fprintf(out, "-- End P%d turn --\n", currentp); endTurn(&G); free(played); turn++; } ntests++; turn = 1; } fclose(out); return 0; }