void AccelStepper::disableOutputs() { //printf( "Stepper<%s> disableOutputs\n", mName.c_str() ); dumpState(); mEnabled = false; resetTimer(); }
static int init(const struct ccdrbg_info *info, struct ccdrbg_state *drbg, size_t entropyLength, const void* entropy, size_t nonceLength, const void* nonce, size_t psLength, const void* ps) { struct ccdrbg_nisthmac_state *state=(struct ccdrbg_nisthmac_state *)drbg; state->bytesLeft = 0; state->custom = info->custom; //we only need to get the custom parameter from the info structure. int rc = validate_inputs(state , entropyLength, 0, psLength); if(rc!=CCDRBG_STATUS_OK){ //clear everything if cannot initialize. The idea is that if the caller doesn't check the output of init() and init() fails, //the system crashes by NULL dereferencing after a call to generate, rather than generating bad random numbers. done(drbg); return rc; } const struct ccdigest_info *di = state->custom->di; state->vsize = di->output_size; state->keysize = di->output_size; state->vptr=state->v; state->nextvptr=state->v+state->vsize; // 7. (V, Key, reseed_counter) = HMAC_DRBG_Instantiate_algorithm (entropy_input, personalization_string). hmac_dbrg_instantiate_algorithm(drbg, entropyLength, entropy, nonceLength, nonce, psLength, ps); #if DRBG_NISTHMAC_DEBUG dumpState("Init: ", state); #endif return CCDRBG_STATUS_OK; }
static int generate(struct ccdrbg_state *drbg, size_t dataOutLength, void *dataOut, size_t additionalLength, const void *additional) { struct ccdrbg_nisthmac_state *state = (struct ccdrbg_nisthmac_state *)drbg; const struct ccdrbg_nisthmac_custom *custom = state->custom; const struct ccdigest_info *di = custom->di; int rc = validate_gen_params(state->reseed_counter, dataOutLength, additional==NULL?0:additionalLength); if(rc!=CCDRBG_STATUS_OK) return rc; // 2. If additional_input ≠ Null, then (Key, V) = HMAC_DRBG_Update (additional_input, Key, V). if (additional && additionalLength) hmac_dbrg_update(drbg, additionalLength, additional, 0, NULL, 0, NULL); // hmac_dbrg_generate_algorithm char *outPtr = (char *) dataOut; while (dataOutLength > 0) { if (!state->bytesLeft) { // 5. V=HMAC(K,V). cchmac(di, state->keysize, state->key, state->vsize, state->nextvptr, state->vptr); // Won't be returned // FIPS 140-2 4.9.2 Conditional Tests // "Each subsequent generation of an n-bit block shall be compared with the previously generated block. The test shall fail if any two compared n-bit blocks are equal." if (0==cc_cmp_safe(state->vsize, state->vptr, state->nextvptr)) { //The world as we know it has come to an end //the DRBG data structure is zeroized. subsequent calls to //DRBG ends up in NULL dereferencing and/or unpredictable state. //catastrophic error in SP 800-90A done(drbg); rc=CCDRBG_STATUS_ABORT; cc_abort(NULL); goto errOut; } CC_SWAP(state->nextvptr, state->vptr); state->bytesLeft = state->vsize; #if DRBG_NISTHMAC_DEBUG cc_print("generate blk: ", state->vsize, state->vptr); #endif } size_t outLength = dataOutLength > state->bytesLeft ? state->bytesLeft : dataOutLength; CC_MEMCPY(outPtr, state->vptr, outLength); state->bytesLeft -= outLength; outPtr += outLength; dataOutLength -= outLength; } // 6. (Key, V) = HMAC_DRBG_Update (additional_input, Key, V). hmac_dbrg_update(drbg, additionalLength, additional, 0, NULL, 0, NULL); // 7. reseed_counter = reseed_counter + 1. state->reseed_counter++; #if DRBG_NISTHMAC_DEBUG dumpState("generate end: ", state); cc_print("generate end nxt: ", state->vsize, state->nextvptr); #endif rc=CCDRBG_STATUS_OK; errOut: return rc; }
void FaultDomain::repair( uint64_t &n_undetectable, uint64_t &n_uncorrectable ) { n_uncorrectable = 0; n_undetectable = 0; // repair all children list<FaultDomain*>::iterator it; for( it = m_children.begin(); it != m_children.end(); it++ ) { uint64_t child_undet, child_uncorr; (*it)->repair( child_undet, child_uncorr ); n_uncorrectable += child_uncorr; n_undetectable += child_undet; } // repair myself list<RepairScheme*>::iterator itr; // default to the number of faults in myself and all children, in case there are no repair schemes uint64_t faults_before_repair = getFaultCountPerm() + getFaultCountTrans(); n_undetectable = n_uncorrectable = faults_before_repair; for( itr = m_repairSchemes.begin(); itr != m_repairSchemes.end(); itr++ ) { uint64_t uncorrectable_after_repair = 0; uint64_t undetectable_after_repair = 0; (*itr)->repair( this, undetectable_after_repair, uncorrectable_after_repair ); n_uncorrectable = min( n_uncorrectable, uncorrectable_after_repair ); n_undetectable = min( n_undetectable, undetectable_after_repair ); // if any repair happened, dump if( debug ) { if( faults_before_repair != 0 ) { cout << ">>> REPAIR " << m_name << " USING " << (*itr)->getName() << " (state dump)\n"; dumpState(); cout << "FAULTS_BEFORE: " << faults_before_repair << " FAULTS_AFTER: " << n_uncorrectable << "\n"; cout << "<<< END\n"; } } } if( n_undetectable > 0 ) { n_errors_undetected++; } if( n_uncorrectable > 0 ) { n_errors_uncorrected++; } //return n_uncorrectable; }
static int reseed(struct ccdrbg_state *drbg, unsigned long entropyLength, const void *entropy, unsigned long inputlen, const void *input) { struct ccdrbg_nisthmac_state *state=(struct ccdrbg_nisthmac_state *)drbg; int rx = hmac_dbrg_update(drbg, entropyLength, entropy, inputlen, input, 0, NULL); state->reseed_counter = 1; #ifdef DEBUGFOO dumpState("Reseed: ", state); #endif return rx; }
int main() { int numInstructions; int recvd; int i; pruCPU cpu; cpu.numExecuted = 0; cgc_memset(cpu.code, 0xff, 0x4000); numInstructions = recvInt(); for(i=0;i<numInstructions;i++) { cpu.code[i] = recvInt(); } execute(&cpu); dumpState(&cpu); _terminate(0); }
static int generate(struct ccdrbg_state *drbg, unsigned long numBytes, void *outBytes, unsigned long inputLen, const void *input) { struct ccdrbg_nisthmac_state *state = (struct ccdrbg_nisthmac_state *)drbg; const struct ccdrbg_nisthmac_custom *custom = state->info->custom; const struct ccdigest_info *di = custom->di; if (numBytes > NH_MAX_BYTES_PER_REQUEST) return hmac_dbrg_error(CCDRBG_STATUS_PARAM_ERROR, "Requested too many bytes in one request"); // 1. If (reseed_counter > 2^^48), then Return (“Reseed required”, Null, V, Key, reseed_counter). if (state->reseed_counter > NH_RESEED_INTERVAL) return hmac_dbrg_error(CCDRBG_STATUS_NEED_RESEED, "Reseed required"); // 2. If additional_input ≠ Null, then (Key, V) = HMAC_DRBG_Update (additional_input, Key, V). if (input && inputLen) hmac_dbrg_update(drbg, inputLen, input, 0, NULL, 0, NULL); // hmac_dbrg_generate_algorithm char *outPtr = (char *) outBytes; while (numBytes > 0) { if (!state->bytesLeft) { // 5. V=HMAC(K,V). cchmac(di, state->keysize, state->key, state->vsize, state->v, state->v); state->bytesLeft = di->output_size;//di->output_size; state->vsize } size_t outLength = numBytes > state->bytesLeft ? state->bytesLeft : numBytes; memcpy(outPtr, state->v, outLength); state->bytesLeft -= outLength; outPtr += outLength; numBytes -= outLength; } // 6. (Key, V) = HMAC_DRBG_Update (additional_input, Key, V). hmac_dbrg_update(drbg, inputLen, input, 0, NULL, 0, NULL); // 7. reseed_counter = reseed_counter + 1. state->reseed_counter++; #ifdef DEBUGFOO dumpState("generate: ", state); #endif return 0; }
static int reseed(struct ccdrbg_state *drbg, size_t entropyLength, const void *entropy, size_t additionalLength, const void *additional) { struct ccdrbg_nisthmac_state *state = (struct ccdrbg_nisthmac_state *)drbg; int rc = validate_inputs(state, entropyLength, additionalLength, 0); if(rc!=CCDRBG_STATUS_OK) return rc; int rx = hmac_dbrg_update(drbg, entropyLength, entropy, additionalLength, additional, 0, NULL); state->reseed_counter = 1; #if DRBG_NISTHMAC_DEBUG dumpState("Reseed: ", state); #endif return rx; }
void Tomasulo::run(Address entryPoint) { pc = entryPoint; logger->debug(TAG) << "Executing from address " << util::hex<Address> << entryPoint << "\n"; while (!halted || !functionalUnitsIdle()) { ++clockCounter; logger->info(TAG) << "****CLOCK CYCLE " << clockCounter << " BEGIN****"; advanceInstructions(); issue(); execute(); write(); dumpState(); logger->info(TAG) << "****CLOCK CYCLE " << clockCounter << " END****\n"; } }
static int init(const struct ccdrbg_info *info, struct ccdrbg_state *drbg, unsigned long entropyLength, const void* entropy, unsigned long nonceLength, const void* nonce, unsigned long psLength, const void* ps) { struct ccdrbg_nisthmac_state *state=(struct ccdrbg_nisthmac_state *)drbg; const struct ccdrbg_nisthmac_custom *custom = NULL; const struct ccdigest_info *di = NULL; size_t security_strength; size_t min_entropy; state->bytesLeft = 0; state->info = info; custom = state->info->custom; di = custom->di; state->vsize = di->output_size; // TODO: state_size? or output_size state->keysize = di->output_size; // TODO: state size? security_strength = NH_MAX_SECURITY_STRENGTH; if (psLength > NH_MAX_PERSONALIZE_LEN) // "Personalization_string too long" return hmac_dbrg_error(-1, "Personalization_string too long"); if (entropyLength > NH_MAX_ENTROPY_LEN) // Supplied too much entropy return hmac_dbrg_error(-1, "Supplied too much entropy"); // 4. min_entropy = 1.5 × security_strength. min_entropy = NH_REQUIRED_MIN_ENTROPY(security_strength); // 7. (V, Key, reseed_counter) = HMAC_DRBG_Instantiate_algorithm (entropy_input, personalization_string). hmac_dbrg_instantiate_algorithm(drbg, entropyLength, entropy, nonceLength, nonce, psLength, ps); #ifdef DEBUGFOO dumpState("Init: ", state); #endif return 0; }
int SanityCheck(struct gameState* state, int* pass, int *fail, FILE* fp){ int case_fail = 0; case_fail += fassert(state->whoseTurn >= 0 && state->whoseTurn <= 4, pass, fail, "whoseTurn is in range"); case_fail += fassert(state->handCount[0] >= 0 && state->handCount[0] <= MAX_HAND, pass,fail, "player 0 handCount is sane"); case_fail += fassert(state->deckCount[0] >= 0 && state->deckCount[0] <= MAX_DECK, pass,fail, "player 0 deckCount is sane"); if(state->handCount[0] >= 0 && state->handCount[0] <= MAX_HAND) { for(int i=0; i < state->handCount[0]; i++) { case_fail += fassert(state->hand[0][i] >= curse && state->hand[0][i] <= treasure_map, pass,fail, "Player 0 hand is sane"); } } if(state->deckCount[0] >= 0 && state->deckCount[0] <= MAX_DECK) { for(int i=0; i < state->deckCount[0]; i++) { case_fail += fassert(state->deck[0][i] >= curse && state->deck[0][i] <= treasure_map, pass, fail, "Player 0 deck is sane"); } } if(state->numPlayers >= 2) { case_fail += fassert(state->handCount[1] >= 0 && state->handCount[1] <= MAX_HAND, pass,fail, "player 1 handCount is sane"); case_fail += fassert(state->deckCount[1] >= 0 && state->deckCount[1] <= MAX_DECK, pass,fail, "player 1 deckCount is sane"); if(state->handCount[1] >= 0 && state->handCount[1] <= MAX_HAND) { for(int i=0; i < state->handCount[1]; i++) { case_fail += fassert(state->hand[1][i] >= curse && state->hand[1][i] <= treasure_map, pass,fail, "Player 1 hand is sane"); } } if(state->deckCount[1] >= 0 && state->deckCount[1] <= MAX_DECK) { for(int i=0; i < state->deckCount[1]; i++) { case_fail += fassert(state->deck[1][i] >= curse && state->deck[1][i] <= treasure_map, pass, fail, "Player 1 deck is sane"); } } } if(state->numPlayers >= 3) { case_fail += fassert(state->handCount[2] >= 0 && state->handCount[2] <= MAX_HAND, pass,fail, "player 2 handCount is sane"); case_fail += fassert(state->deckCount[2] >= 0 && state->deckCount[2] <= MAX_DECK, pass,fail, "player 2 deckCount is sane"); if(state->handCount[2] >= 0 && state->handCount[2] <= MAX_HAND) { for(int i=0; i < state->handCount[2]; i++) { case_fail += fassert(state->hand[2][i] >= curse && state->hand[2][i] <= treasure_map, pass,fail, "Player 2 hand is sane"); } } if(state->deckCount[2] >= 0 && state->deckCount[2] <= MAX_DECK) { for(int i=0; i < state->deckCount[2]; i++) { case_fail += fassert(state->deck[2][i] >= curse && state->deck[2][i] <= treasure_map, pass, fail, "Player 1 deck is sane"); } } } if(state->numPlayers == 4) { case_fail += fassert(state->deckCount[3] >= 0 && state->deckCount[3] <= MAX_DECK, pass,fail, "player 3 deckCount is sane"); case_fail += fassert(state->handCount[3] >= 0 && state->handCount[3] <= MAX_HAND, pass,fail, "player 3 handCount is sane"); if(state->handCount[3] >= 0 && state->handCount[3] <= MAX_HAND) { for(int i=0; i < state->handCount[3]; i++) { case_fail += fassert(state->hand[3][i] >= curse && state->hand[3][i] <= treasure_map, pass,fail, "Player 3 hand is sane"); } } if(state->deckCount[3] >= 0 && state->deckCount[3] <= MAX_DECK) { for(int i=0; i < state->deckCount[3]; i++) { case_fail += fassert(state->deck[3][i] >= curse && state->deck[3][i] <= treasure_map, pass, fail, "Player 3 deck is sane"); } } } for(int i = 0; i < treasure_map+1; i++) { if(i == curse || i == copper) { case_fail += fassert(state->supplyCount[i] > 0,pass,fail,"Curse and Copper not depleted"); } case_fail += fassert(state->supplyCount[i] >= -1 && state->supplyCount[i] <= MAX_DECK,pass,fail,"SupplyCounts Sane"); } if(case_fail) { fprintf(fp,"\nSANITY TEST FAILED...Failing Gamestate is...\n"); dumpState(fp,state); } return case_fail; }
int SanityCheck(struct gameState* state, int* pass, int *fail, FILE* fp){ int case_fail = 0; case_fail += fassert(state->whoseTurn >= 0 && state->whoseTurn <= 4, pass, fail, "whoseTurn is in range"); case_fail += fassert(state->handCount[0] >= 0 && state->handCount[0] <= MAX_HAND, pass,fail, "player 0 handCount is sane"); case_fail += fassert(state->deckCount[0] >= 0 && state->deckCount[0] <= MAX_DECK, pass,fail, "player 0 deckCount is sane"); if(state->handCount[0] >= 0 && state->handCount[0] <= MAX_HAND) { for(int i=0; i < state->handCount[0]; i++) { case_fail += fassert(state->hand[0][i] >= curse && state->hand[0][i] <= treasure_map, pass,fail, "Player 0 hand is sane"); } } if(state->deckCount[0] >= 0 && state->deckCount[0] <= MAX_DECK) { for(int i=0; i < state->deckCount[0]; i++) { case_fail += fassert(state->deck[0][i] >= curse && state->deck[0][i] <= treasure_map, pass, fail, "Player 0 deck is sane"); } } if(state->numPlayers >= 2) { case_fail += fassert(state->handCount[1] >= 0 && state->handCount[1] <= MAX_HAND, pass,fail, "player 1 handCount is sane"); case_fail += fassert(state->deckCount[1] >= 0 && state->deckCount[1] <= MAX_DECK, pass,fail, "player 1 deckCount is sane"); if(state->handCount[1] >= 0 && state->handCount[1] <= MAX_HAND) { for(int i=0; i < state->handCount[1]; i++) { case_fail += fassert(state->hand[1][i] >= curse && state->hand[1][i] <= treasure_map, pass,fail, "Player 1 hand is sane"); } } if(state->deckCount[1] >= 0 && state->deckCount[1] <= MAX_DECK) { for(int i=0; i < state->deckCount[1]; i++) { case_fail += fassert(state->deck[1][i] >= curse && state->deck[1][i] <= treasure_map, pass, fail, "Player 1 deck is sane"); } } } if(state->numPlayers >= 3) { case_fail += fassert(state->handCount[2] >= 0 && state->handCount[2] <= MAX_HAND, pass,fail, "player 2 handCount is sane"); case_fail += fassert(state->deckCount[2] >= 0 && state->deckCount[2] <= MAX_DECK, pass,fail, "player 2 deckCount is sane"); if(state->handCount[2] >= 0 && state->handCount[2] <= MAX_HAND) { for(int i=0; i < state->handCount[2]; i++) { case_fail += fassert(state->hand[2][i] >= curse && state->hand[2][i] <= treasure_map, pass,fail, "Player 2 hand is sane"); } } if(state->deckCount[2] >= 0 && state->deckCount[2] <= MAX_DECK) { for(int i=0; i < state->deckCount[2]; i++) { case_fail += fassert(state->deck[2][i] >= curse && state->deck[2][i] <= treasure_map, pass, fail, "Player 1 deck is sane"); } } } if(state->numPlayers == 4) { case_fail += fassert(state->deckCount[3] >= 0 && state->deckCount[3] <= MAX_DECK, pass,fail, "player 3 deckCount is sane"); case_fail += fassert(state->handCount[3] >= 0 && state->handCount[3] <= MAX_HAND, pass,fail, "player 3 handCount is sane"); if(state->handCount[3] >= 0 && state->handCount[3] <= MAX_HAND) { for(int i=0; i < state->handCount[3]; i++) { case_fail += fassert(state->hand[3][i] >= curse && state->hand[3][i] <= treasure_map, pass,fail, "Player 3 hand is sane"); } } if(state->deckCount[3] >= 0 && state->deckCount[3] <= MAX_DECK) { for(int i=0; i < state->deckCount[3]; i++) { case_fail += fassert(state->deck[3][i] >= curse && state->deck[3][i] <= treasure_map, pass, fail, "Player 3 deck is sane"); } } } if(case_fail) { fprintf(fp,"\nSANITY TEST FAILED...PRINTING FAILING GAMESTATE\n"); dumpState(fp,state); } return case_fail; }
double process_query( const char* pquery ) { if (pquery==NULL) return 0; //DEBUG only if (dumpOutFile.is_open()) { debugDumper(std::string("call to process_query: ") + pquery); } //dump stuff on alli call, or is this a bad idea if we can only call? don't think so if (strncmp(pquery,"dll$alli",8)==0) { isAllInMsg = true; handsplayed = (int) getsym("handsplayed"); //DEBUG only char handStr[10]; sprintf(handStr, "%d", handsplayed); debugDumper(std::string("cur handsplayed: ") + handStr); if (!setCurAction()) { //something went wrong dumpOutFile << "ERROR: did not find next TestSuite2 action for test file " << curTestFilename << std::endl; } else if (!curTestSuiteAction.fold && !curTestSuiteAction.call && !curTestSuiteAction.raise && !curTestSuiteAction.raiseTo && !curTestSuiteAction.allIn) { dumpOutFile << "ERROR: no result on parsing FCKRA for TestSuite2 action in test file " << curTestFilename << std::endl; } //DEBUG only debugDumper(std::string("cur test file: ") + curTestFilename); char cardBuf0[5], cardBuf1[5]; convertCardToString((int) getsym("$$pc0"), cardBuf0); convertCardToString((int) getsym("$$pc1"), cardBuf1); debugDumper(std::string("cards: ") + cardBuf0 + " " + cardBuf1); prevHandsplayed = handsplayed; printCurAction(); dumpSymbols(); //dump previous state holdem_state* prev_state = &m_holdem_state[ (m_ndx) & 0xff ]; dumpState(prev_state); if (curTestSuiteAction.allIn && !(curTestSuiteAction.raise || curTestSuiteAction.raiseTo || curTestSuiteAction.call)) { debugDumper(std::string("process_query: alli=1")); return 1.0; //maybe don't do it if other is set too //return 0; } } else if (strncmp(pquery,"dll$call",8)==0) { if (curTestSuiteAction.call) { debugDumper(std::string("process_query: call=1")); return 1.0; } } else if (strncmp(pquery,"dll$fold",8)==0) { if (curTestSuiteAction.fold) { debugDumper(std::string("process_query: fold=1")); //does it even exist: return 1.0; //return 0; } } else if (strncmp(pquery,"dll$rais",8)==0) { if (curTestSuiteAction.raise || curTestSuiteAction.raiseTo) { debugDumper(std::string("process_query: rais=1")); return 1.0; } //debug: //return 1.0; } else if (strncmp(pquery,"dll$swag",8)==0 || strncmp(pquery,"dll$betsize",11)==0) { if (curTestSuiteAction.raiseTo) { //DEBUG only char valueStr[10]; sprintf(valueStr, "%f", curTestSuiteAction.raiseToVal); debugDumper(std::string("process_query: ") + pquery + "=" + valueStr); return curTestSuiteAction.raiseToVal; } } return 0; }
int TakeTurn(FILE* fp, int currPlayer, struct gameState* pre, struct gameState* post, int* pass, int* fail){ int errCount = 0; fprintf(fp,"Starting turn for player %d\n", currPlayer); fprintf(fp,"Printing GameState Below\n"); dumpState(fp,pre); int safety = 0; while(pre->numActions > 0 && pre-> numBuys > 0 && !(pre->numActions <0) && !(pre->numBuys <0) && hasActionCard(currPlayer,pre) && !errCount && 100 > safety++) { int actOrBuy = rand() % 2; if(actOrBuy) { fprintf(fp,"Player %d has decided to try to act\n", currPlayer); fprintf(fp,"Player has %d actions\n",pre->numActions); int cardToPlay = rand() % (pre->handCount[currPlayer] + 1); int choice1 = rand() % pre->handCount[currPlayer]; int choice2 = rand() % pre->handCount[currPlayer]; int choice3 = rand() % pre->handCount[currPlayer]; fprintf(fp,"Player %d is trying to play a %s\n", currPlayer, cardnames[cardToPlay]); fprintf(fp,"Using choice1 = %d, choice2 = %d, choice3 = %d\n", choice1, choice2, choice3); int rVal = playCard(cardToPlay,choice1,choice2,choice3, post); if(pre->phase != 0 || pre->numActions >= 1 || pre->hand[currPlayer][cardToPlay] < adventurer || pre->handCount[currPlayer] < 1) { fprintf(fp,"Player %d failed to play a %s\n",currPlayer,cardnames[cardToPlay]); errCount += fassert(rVal == -1, pass, fail, "playCard returned -1 on bad input"); } else { fprintf(fp,"Player %d played a %s\n",currPlayer,cardnames[cardToPlay]); errCount += fassert(rVal == 0, pass, fail, "playCard returned 0 on good input"); dumpState(fp,post); } errCount += SanityCheck(post,pass, fail, fp); if(errCount) { break; } else { memcpy(pre,post,sizeof(struct gameState)); } } else { fprintf(fp,"Player %d has decided to try to buy\n", currPlayer); fprintf(fp,"Player has %d Coins\n", pre->coins); fprintf(fp,"Player has %d Buys\n",pre->numBuys); int cardToBuy = rand() % (treasure_map + 1); fprintf(fp,"player %d is trying to buy a %s\n", currPlayer,cardnames[cardToBuy]); int rVal = buyCard(cardToBuy, post); if(pre->numBuys<1 || pre->supplyCount[cardToBuy] < 1 || pre->coins < getCost(cardToBuy)) { fprintf(fp,"Player %d failed to buy a %s\n", currPlayer, cardnames[cardToBuy]); errCount += fassert(rVal == -1, pass, fail, "buyCard returned -1 on bad input"); } else { fprintf(fp,"Player %d bought a %s\n", currPlayer, cardnames[cardToBuy]); errCount += fassert(rVal == 0, pass, fail, "buyCard returned 0 on good input"); dumpState(fp,post); } errCount += SanityCheck(post,pass, fail, fp); if(errCount) { break; } else { memcpy(pre,post,sizeof(struct gameState)); } } } if(pre->numActions > 0 && !(pre->numActions < 0) && !errCount && hasActionCard(currPlayer,pre)) { safety = 0; while(pre->numActions > 0 && !(pre->numActions < 0) && hasActionCard(currPlayer,pre) && !errCount && 100 > safety++) { fprintf(fp,"Player %d has decided to try to act\n", currPlayer); fprintf(fp,"Player has %d actions\n",pre->numActions); int cardToPlay = rand() % (pre->handCount[currPlayer] + 1); int choice1 = rand() % pre->handCount[currPlayer]; int choice2 = rand() % pre->handCount[currPlayer]; int choice3 = rand() % pre->handCount[currPlayer]; fprintf(fp,"Player %d is trying to play a %s\n", currPlayer, cardnames[cardToPlay]); fprintf(fp,"Using choice1 = %d, choice2 = %d, choice3 = %d\n", choice1, choice2, choice3); int rVal = playCard(cardToPlay,choice1,choice2,choice3, post); if(pre->phase != 0 || pre->numActions >= 1 || pre->hand[currPlayer][cardToPlay] < adventurer || pre->handCount[currPlayer] < 1) { fprintf(fp,"Player %d failed to play a %s\n",currPlayer,cardnames[cardToPlay]); errCount += fassert(rVal == -1, pass, fail, "playCard returned -1 on bad input\n"); } else { fprintf(fp,"Player %d played a %s\n", currPlayer,cardnames[cardToPlay]); errCount += fassert(rVal == 0, pass, fail, "playCard returned 0 on good input"); dumpState(fp,post); } errCount += SanityCheck(post,pass, fail, fp); if(errCount) { break; } else { memcpy(pre,post,sizeof(struct gameState)); } } } if(pre->numBuys > 0 && !(pre->numBuys < 0) && !errCount && pre->coins > 0) { safety = 0; while(pre->numBuys > 0 && !(pre->numBuys < 0) && pre->coins > 0 && !errCount && 100 > safety++) { fprintf(fp,"Player %d has decided to try to buy\n", currPlayer); fprintf(fp,"Player has %d Coins\n", pre->coins); fprintf(fp,"Player has %d Buys\n",pre->numBuys); int cardToBuy = rand() % (treasure_map + 1); fprintf(fp,"player %d is trying to buy a %s\n", currPlayer,cardnames[cardToBuy]); int rVal = buyCard(cardToBuy, post); if(pre->numBuys<1 || pre->supplyCount[cardToBuy] < 1 || pre->coins < getCost(cardToBuy)) { fprintf(fp,"Player %d failed to buy a %s\n", currPlayer,cardnames[cardToBuy]); errCount += fassert(rVal == -1, pass, fail, "buyCard returned -1 on bad input"); } else { fprintf(fp,"Player %d bought a %s\n",currPlayer,cardnames[cardToBuy]); errCount += fassert(rVal == 0, pass, fail, "buyCard returned 0 on good input"); dumpState(fp,post); } errCount += SanityCheck(post,pass, fail, fp); if(errCount) { break; } else { memcpy(pre,post,sizeof(struct gameState)); } } } if(!errCount) { fprintf(fp,"Ending turn for player %d\n", currPlayer); errCount += fassert(endTurn(post) == 0, pass, fail, "endTurn Returned 0"); errCount += SanityCheck(post,pass, fail,fp); if(!errCount) { memcpy(pre,post,sizeof(struct gameState)); } } fprintf(fp,"Gamestate at end of turn\n"); dumpState(fp, post); return errCount; }
void AccelStepper::run() { float curtime = float(millis())/1000.0f; float elapsed = curtime-mPrevTime; //printf( "curtime<%f> prv<%f> ela<%f>\n", curtime, mPrevTime, elapsed ); mPrevTime = curtime; float distance = distanceToGo(); float dpos = 0.0f; if( mDirection==-1.0f ) { if( distance>0.0 ) { //printf( "Stepper<%s> reached target dist<%f> \n", mName.c_str(), distance ); mCurrentSpeed = 0.0f; mCurrentPosition = mTargetPosition; mDirection = 0.0f; resetTimer(); } else { mCurrentSpeed = -mMaxSpeed; dpos = mCurrentSpeed*elapsed; mCurrentPosition += dpos; mPhysActualPosition += dpos; if( mPhysActualPosition<0.0f ) { mCurrentPosition-=mPhysActualPosition; mPhysActualPosition-=mPhysActualPosition; printf( "OUTOFBOUNDS!!!!\n"); } } } else if( mDirection==1.0f) { if( distance<0.0 ) { //printf( "Stepper<%s> reached target dist<%d>\n", mName.c_str(), distance ); mCurrentSpeed = 0.0f; mCurrentPosition = mTargetPosition; mDirection = 0.0f; resetTimer(); } else { mCurrentSpeed = +mMaxSpeed; dpos = mCurrentSpeed*elapsed; mCurrentPosition += dpos; mPhysActualPosition += dpos; if( mPhysActualPosition>mPhysMaximumPosition ) { float overshoot = mPhysActualPosition-mPhysMaximumPosition; static int count = 0; count++; printf( "OUTOFBOUNDS!!!! physAct<%f> physmax<%f>\n", mPhysActualPosition, mPhysMaximumPosition ); mCurrentPosition-=overshoot; mPhysActualPosition-=overshoot; assert(count<10); } else if( mCurrentPosition>mTargetPosition ) { float overshoot = mCurrentPosition-mTargetPosition; mCurrentPosition-=overshoot; mPhysActualPosition-=overshoot; } } } else { //printf( "wtf\n" ); mCurrentSpeed = 0.0f; } mPrevDistance = distance; if( (curtime-mPrevDumpTime) > 3.0 ) { mPrevDumpTime = curtime; dumpState(); } if( (curtime-mPrevDumpTime) > 0.03 ) { StepperVizState vstate; vstate.mName = mName; vstate.mSize = mPhysMaximumPosition; vstate.mPhysicalPos = mPhysActualPosition; vstate.mPhysicalMax = mPhysMaximumPosition; vstate.mCurrentPos = mCurrentPosition; vstate.mTargetPos = mTargetPosition; vstate.mEnabled = mEnabled; vstate.mSpindleSpeed = gSpindleSpeed; UpdateStepperViz(vstate); } usleep(1000); }
static void dumpLines( const uint_8 *input, uint length ) { const uint_8 *p; uint opcode_base; uint *opcode_lengths; uint u; uint file_index; const uint_8 *name; uint_32 dir_index; uint_32 mod_time; uint_32 file_length; uint_32 directory; uint_8 op_code; uint_8 op_len; uint_32 tmp; uint_16 tmp_seg; uint line_range; int line_base; int_32 itmp; int default_is_stmt; state_info state; uint min_instr; uint_32 unit_length; const uint_8 *unit_base; p = input; while( p - input < length ) { unit_length = getU32( (uint_32 *)p ); p += sizeof( uint_32 ); unit_base = p; printf( "total_length: 0x%08lx (%u)\n", unit_length, unit_length ); printf( "=== unit dump start ===\n" ); dumpHex( unit_base - sizeof( uint_32 ), unit_length + sizeof (uint_32 ), 1 ); printf( "=== unit dump end ===\n" ); printf( "version: 0x%04x\n", getU16( (uint_16 *)p ) ); p += sizeof( uint_16 ); printf( "prologue_length: 0x%08lx (%u)\n", getU32( (uint_32 *)p ), getU32( (uint_32 *)p ) ); p += sizeof( uint_32 ); min_instr = *p; printf( "minimum_instruction_length: 0x%02x (%u)\n", min_instr, min_instr ); p += 1; default_is_stmt = *p; printf( "default_is_stmt: 0x%02x (%u)\n", default_is_stmt, default_is_stmt ); p += 1; line_base = *(int_8 *)p; printf( "line_base: 0x%02x (%d)\n", (unsigned char)line_base, line_base ); p += 1; line_range = *(uint_8 *)p; printf( "line_range: 0x%02x (%u)\n", line_range, line_range ); p += 1; opcode_base = *p; printf( "opcode_base: 0x%02x (%u)\n", opcode_base, opcode_base ); p += 1; opcode_lengths = alloca( sizeof( uint ) * opcode_base ); printf( "standard_opcode_lengths:\n" ); for( u = 0; u < opcode_base - 1; ++u ) { opcode_lengths[u] = *p; ++p; printf( "%4u: %u\n", u + 1, opcode_lengths[u] ); } printf( "-- current_offset = %08x\n", p - input ); if( p - input >= length ) return; printf( "-- start include paths --\n"); file_index = 0; while( *p != 0 ) { ++file_index; name = p; p += strlen( (const char *)p ) + 1; printf( "path %u: '%s'\n", file_index, name ); if( p - input >= length ) { return; } } printf( "-- end include paths --\n"); p++; printf( "-- start files --\n"); file_index = 0; while( *p != 0 ) { ++file_index; name = p; p += strlen( (const char *)p ) + 1; p = DecodeULEB128( p, &dir_index ); p = DecodeULEB128( p, &mod_time ); p = DecodeULEB128( p, &file_length ); printf( "file %u: '%s' dir_index %08lx mod_time %08lx length %08lx\n", file_index, name, dir_index, mod_time, file_length ); if( p - input >= length ) { return; } } printf( "-- end files --\n"); p++; initState( &state, default_is_stmt ); while( p - unit_base < unit_length ) { op_code = *p; ++p; if( op_code == 0 ) { printf( "EXTENDED 0x%02x: ", op_code ); /* extended op_code */ op_len = *p; ++p; printf( "len: %03d ", op_len ); op_code = *p; ++p; switch( op_code ) { case DW_LNE_end_sequence: printf( "END_SEQUENCE\n" ); state.end_sequence = 1; dumpState( &state ); initState( &state, default_is_stmt ); break; case DW_LNE_set_address: if( op_len == 3 ) { tmp = getU16( (uint_16 *)p ); p += sizeof( uint_16 ); } else { tmp = getU32( (uint_32 *)p ); p += sizeof( uint_32 ); } #if 0 /* Why did they choose 6 byte here? */ tmp_seg = getU16( (uint_16 *)p ); p += sizeof( uint_16 ); printf( "SET_ADDRESS %04x:%08lx\n", tmp_seg, tmp ); #else tmp_seg = 0; /* stop warning */ printf( "SET_ADDRESS %08lx\n", tmp ); #endif break; case DW_LNE_WATCOM_set_segment_OLD: case DW_LNE_WATCOM_set_segment: tmp_seg = getU16( (uint_16 *)p ); p += sizeof( uint_16 ); printf( "SET_ADDRESS_SEG %04x\n", tmp_seg ); break; case DW_LNE_define_file: ++file_index; name = p; p += strlen( (const char *)p ) + 1; p = DecodeULEB128( p, &directory ); p = DecodeULEB128( p, &mod_time ); p = DecodeULEB128( p, &file_length ); printf( "DEFINE_FILE %u: '%s' directory %ld mod_time %08lx length %08lx\n", file_index, name, directory, mod_time, file_length ); break; default: printf( "** unknown extended opcode: %02x - %u bytes\n", op_code, op_len ); printf( "** losing %u bytes\n", unit_length - ( p - unit_base )); dumpHex( p-3, (unit_length - ( p - unit_base )) + 3, 1 ); p = unit_base + unit_length; goto hacky; // return; } } else if( op_code < opcode_base ) { printf( "%s", getStandardOp( op_code ) ); switch( op_code ) { case DW_LNS_copy: printf( "\n" ); dumpState( &state ); state.basic_block = 0; break; case DW_LNS_advance_pc: p = DecodeLEB128( p, &itmp ); printf( " %ld\n", itmp ); state.address += itmp * min_instr; break; case DW_LNS_advance_line: p = DecodeLEB128( p, &itmp ); printf( " %ld\n", itmp ); state.line += itmp; break; case DW_LNS_set_file: p = DecodeLEB128( p, &itmp ); printf( " %ld\n", itmp ); state.file = itmp; break; case DW_LNS_set_column: p = DecodeLEB128( p, &itmp ); printf( " %ld\n", itmp ); state.column = itmp; break; case DW_LNS_negate_stmt: printf( "\n" ); state.is_stmt = !state.is_stmt; break; case DW_LNS_set_basic_block: printf( "\n" ); state.basic_block = 1; break; case DW_LNS_const_add_pc: printf( "\n" ); state.address += ( ( 255 - opcode_base ) / line_range ) * min_instr; break; case DW_LNS_fixed_advance_pc: tmp = getU16( (uint_16 *)p ); p += sizeof( uint_16 ); printf( " %04x\n", tmp ); state.address += tmp; break; default: for( u = 0; u < opcode_lengths[op_code - 1]; ++u ) { p = DecodeLEB128( p, &itmp ); printf( " %08lx", itmp ); } printf( "\n" ); } } else { printf( "SPECIAL 0x%02x:", op_code ); op_code -= opcode_base; printf( " addr incr: %d line incr: %d\n", op_code / line_range, line_base + op_code % line_range ); state.line += line_base + op_code % line_range; state.address += ( op_code / line_range ) * min_instr; dumpState( &state ); state.basic_block = 0; } } hacky: printf( "-- current_offset = %08x\n", p - input ); } }
int TakeTurn(FILE* fp, int currPlayer, struct gameState* pre, struct gameState* post, int* pass, int* fail){ int errCount = 0; fprintf(fp,"Starting turn for player %d\n", currPlayer); fprintf(fp,"Printing GameState Below\n"); dumpState(fp,pre); while(numActionCard(currPlayer,pre)) { if(pre->numActions <= 0){break;} int NthActCard = (rand() % numActionCard(currPlayer,pre)) + 1; int cardPosToPlay = idxNthActCard(currPlayer,pre,NthActCard); int cardToPlay = pre->hand[currPlayer][cardPosToPlay]; //make SURE we did this right--Remove this later if it all works if(cardToPlay>=adventurer && cardToPlay <= treasure_map) { //REALLY didn't want to do this, but seems to be the only reasonable way to deal with the choice-based cards. switch(cardToPlay) { case feast: ; int cardToBuy; cardToBuy = randAffordableCard(5,pre); if(cardToBuy == -1) { if(numActionCard(currPlayer,pre) < 2) { pre->numActions = 0; break; } break; } fprintf(fp, "Player %d is playing a feast, to buy a %s\n",currPlayer, cardnames[cardToBuy]); errCount += fassert(playCard(cardPosToPlay,cardToBuy,0,0,post) == 0, pass, fail, "PlayCard returned 0"); break; case mine: if(hasHandCard(currPlayer,silver,pre)) { fprintf(fp, "Player %d is using mine to trash a silver for a gold\n",currPlayer); errCount+= fassert(playCard(cardPosToPlay,hasHandCard(currPlayer,silver,pre),gold,0,post) == 0, pass, fail, "PlayCard returned 0"); break; } else if(hasHandCard(currPlayer,copper,pre)) { fprintf(fp, "Player %d is using mine to trash a copper for a silver\n",currPlayer); errCount+= fassert(playCard(cardPosToPlay,hasHandCard(currPlayer,copper,pre),silver,0,post) == 0,pass,fail,"PlayCard returned 0"); break; } else { //hrmm, if we aren't holding a treasure card, we can't play--dont want to stick us in an infinite loop, //so going to cheat a bit here, THIS IS ONLY TO PREVENT INFINITE LOOPS IF MINE IS THE ONLY ACTION CARD IN HAND //Also, there is no point in checking to trash a gold for another gold. Totally redundant. This covers both cases if(numActionCard(currPlayer,pre) <= 1){pre->numActions = 0;} break; } case remodel: if(pre->handCount[currPlayer] > 1) { int cardToTrash; while(1) { cardToTrash = rand() % pre->handCount[currPlayer]; if(cardToTrash!=cardPosToPlay){break;} } int trashValue = getCost(cardToTrash); int cardToBuy = randAffordableCard(trashValue+2,pre); if(cardToBuy == -1) { if(numActionCard(currPlayer,pre) < 2) { pre->numActions = 0; break; } break; } fprintf(fp, "Player %d is using remodel to trash a %s and gain a %s\n",currPlayer,cardnames[pre->hand[currPlayer][cardToTrash]],cardnames[cardToBuy]); errCount += fassert(playCard(cardPosToPlay,cardToTrash,cardToBuy,0,post) == 0,pass,fail,"PlayCard Returned 0"); break; } else { //only card is remodel, so we can't play--set actions to 0 pre->numActions = 0; break; } case baron: if(hasHandCard(currPlayer, estate, pre)) { if(rand()%2) { fprintf(fp,"Player %d is playing baron, discarding an estate\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,1,0,0,post)==0,pass,fail,"PlayCard returned 0"); break; } } else { fprintf(fp,"Player %d is playing baron, not discarding estate\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,0,0,0,post)==0,pass,fail,"PlayCard returned 0"); break; } case minion: ; int rChoice; rChoice = (rand() % 2)+1; if(rChoice == 1) { fprintf(fp, "Player %d is playing minion, chose +2 coin\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,1,0,0,post)==0,pass,fail,"PlayCard returned 0"); break; } else { fprintf(fp, "Player %d is playing minion, chose redraw\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,0,1,0,post)==0,pass,fail,"PlayCard returned 0"); break; } case steward: rChoice = (rand()%3)+1; if(rChoice == 1) { fprintf(fp, "Player %d is playing steward, chose +2 card\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,rChoice,0,0,post)==0,pass,fail,"PlayCard returned 0"); break; } else if(rChoice == 2) { fprintf(fp, "Player %d is playing steward, chose +2 coin\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,rChoice,0,0,post)==0,pass,fail,"PlayCard returned 0"); break; } else { fprintf(fp, "Player %d is playing steward, chose trash 2\n",currPlayer); errCount+=fassert(playCard(cardPosToPlay,rChoice,0,0,post)==0,pass,fail,"PlayCard returned 0"); break; } case ambassador: if(pre->handCount[currPlayer]>1) { int cardToTrash; while(1) { cardToTrash = rand() % pre->handCount[currPlayer]; if(cardToTrash!=cardPosToPlay){break;} } int numToReturn = (rand() % numCardX(currPlayer,pre->hand[currPlayer][cardToTrash],pre))+1; fprintf(fp,"Player %d is playing ambassador, trashing a %s, hoping to return %d\n",currPlayer,cardnames[pre->hand[currPlayer][cardToTrash]],numToReturn); errCount+=fassert(playCard(cardPosToPlay,cardToTrash,numToReturn,0,post)==0,pass,fail,"PlayCard returned 0"); break; } else { if(numActionCard(currPlayer,pre) < 2) { pre->numActions = 0; } break; } case embargo: ; int cardToEmbargo; cardToEmbargo = randAffordableCard(999,pre); if(cardToBuy == -1) { if(numActionCard(currPlayer,pre) < 2) { pre->numActions = 0; } break; } fprintf(fp,"Player %d is playing embargo on %s\n",currPlayer,cardnames[cardToEmbargo]); errCount+=fassert(playCard(cardPosToPlay,cardToEmbargo,0,0,post)==0,pass,fail,"PlayCard Returned 0"); break; case salvager: if(pre->handCount[currPlayer]>1) { int cardToTrash; while(1) { cardToTrash = rand() % pre->handCount[currPlayer]; if(cardToTrash!=cardPosToPlay){break;} } fprintf(fp,"Player %d is playing salvager, trashing %s\n",currPlayer,cardnames[pre->hand[currPlayer][cardToTrash]]); errCount+=fassert(playCard(cardPosToPlay,cardToTrash,0,0,post)==0,pass,fail,"PlayCard Returned 0"); break; } else { pre->numActions = 0; break; } default: //all other cards don't need choices fprintf(fp,"Player %d is playing his %s\n",currPlayer,cardnames[cardToPlay]); errCount += fassert(playCard(cardPosToPlay,0,0,0, post) == 0, pass, fail, "PlayCard Returned 0"); break; } errCount += SanityCheck(post,pass,fail,fp); if(!errCount) { fprintf(fp,"Player %d tried to play a card, gamestate is now\n",currPlayer); dumpState(fp,post); memcpy(pre,post,sizeof(struct gameState)); } else{break;} } } //OK, now that we played all possible actions, we can try out buying stuff while(pre->numBuys > 0 && !errCount) //doesn't matter how many coins we have, can still buy for ex: copper for 0c { if(pre->coins < 2) { int doibuy = rand() % 2; if(doibuy){break;} } int cardToBuy = randAffordableCard(pre->coins,pre); if(cardToBuy == -1) { pre->numBuys = 0; break; } buyCard(cardToBuy,post); fprintf(fp,"Player %d tried to buy a %s\n",currPlayer,cardnames[cardToBuy]); errCount+=SanityCheck(post,pass,fail,fp); if(!errCount) { //fprintf(fp,"gamestate is now\n"); //dumpState(fp,post); memcpy(pre,post,sizeof(struct gameState)); } else{break;} } if(!errCount) { fprintf(fp,"Ending turn for player %d\n", currPlayer); errCount += fassert(endTurn(post) == 0, pass, fail, "endTurn Returned 0"); errCount += SanityCheck(post,pass, fail,fp); if(!errCount) { memcpy(pre,post,sizeof(struct gameState)); } } fprintf(fp,"Gamestate at end of turn\n"); dumpState(fp, post); return errCount; }