bool DC_Derivative::GetDerivatives(const DC_XYData& inputXY, DC_XYData& outputXY, SC_SetupErr& errData) { if (PrepareInput(inputXY, 0)) DoCalc(outputXY); errData = processErr; Cleanup(); return !outputXY.IsEmpty(); }
bool ParseLine(char *cs) { if (*cs == ' ') cs++; if (*cs == '%') cs++; char s[BUFSIZE]; strcpy(s, cs); // extended sets if (strstr(s, "INSTRUCTION SET") == s) extended = 0x00; if (strstr(s, "EXTENDED ") == s) { extended = s[9] - '0' + 0xCE; } if ((s[0] != '|') && (s[0] != '+')) return false; int repaired = 0; /* repaired |= strreplace(s, "jc disp8", "jcb disp8"); repaired |= strreplace(s, "jnc disp8", "jncb disp8"); repaired |= strreplace(s, "jz disp8", "jzb disp8"); repaired |= strreplace(s, "jnz disp8", "jnzb disp8"); repaired |= strreplace(s, "jc disp16", "jcw disp16"); repaired |= strreplace(s, "jnc disp16", "jncw disp16"); repaired |= strreplace(s, "jz disp16", "jzw disp16"); repaired |= strreplace(s, "jnz disp16", "jnzw disp16"); repaired |= strreplace(s, "jmp disp16", "jmpw disp16"); repaired |= strreplace(s, "call disp16", "callw disp16"); repaired |= strreplace(s, "callc disp16", "callcw disp16"); repaired |= strreplace(s, "callnc disp16", "callncw disp16"); repaired |= strreplace(s, "callz disp16", "callzw disp16"); repaired |= strreplace(s, "callnz disp16", "callnzw disp16"); repaired |= strreplace(s, "jmp disp8", "jmpb disp8"); repaired |= strreplace(s, "call disp8", "callb disp8"); repaired |= strreplace(s, "callc disp8", "callcb disp8"); repaired |= strreplace(s, "callnc disp8", "callncb disp8"); repaired |= strreplace(s, "callz disp8", "callzb disp8"); repaired |= strreplace(s, "callnz disp8", "callnzb disp8"); */ //repaired |= strreplace(s, "CE:B0+rb", "CF:B0+rb"); //repaired |= strreplace(s, "H| ", "H | "); //repaired |= strreplace(s, "pop rb", "popb rb"); //repaired |= strreplace(s, "ofL:ofH", "ofs16L:ofs16H"); //repaired |= strreplace(s, "of16L:of16H", "ofs16L:ofs16H"); //repaired |= strreplace(s, "dispL:dispH", "disp16L:disp16H"); //repaired |= strreplace(s, "D0+rw", "D0+rw:imm16L:imm16H"); //repaired |= strreplace(s, "D4+rw", "D4+rw:imm16L:imm16H"); //repaired |= strreplace(s, "(???)", ""); //repaired |= strreplace(s, "(BCD xchg)", ""); //repaired |= strreplace(s, "(BCD decode)", ""); //repaired |= strreplace(s, "(BCD encode)", ""); //repaired |= strreplace(s, "???", "NOIDEA imm8"); //repaired |= strreplace(s, ":??", ":imm8"); //repaired |= strreplace(s, "dis8", "disp8"); //repaired |= strreplace(s, "dis16", "disp16"); //repaired |= strreplace(s, "im8", "imm8"); //repaired |= strreplace(s, "im16", "imm16"); //repaired |= strreplace(s, ", ", ","); if (repaired) { fprintf(stderr, "Repaired line %d %s", line, s); } if (extended == 0xCE) strreplace(s, "CE:", ""); if (extended == 0xCF) strreplace(s, "CF:", ""); char a[BUFSIZE],b[BUFSIZE],c[BUFSIZE]; int n = sscanf(s, "| %[^|] | %[^|] | %[^|] |", a,b,c); if (n < 1) return false; if (a[0] == '|') return false; memset(&instruction, 0, sizeof(instruction)); //fprintf(stderr, "%-10s %s\n", a, b); if (extended) { instruction.flags |= FLAG_EXTENDED; instruction.size = 2; instruction.fixed |= extended << 0; } else { instruction.size = 1; } //instruction.extended = extended; //if (extended) instruction.size++; //instruction.argbytes = 0; //instruction.argnum = 0; // disp = relative ! // replace some stuff for (int i=0; i<2; i++) { strreplace(a, "dis8", "disp8"); strreplace(b, "dis8", "disp8"); strreplace(a, "dis16", "disp16"); strreplace(b, "dis16", "disp16"); //strreplace(a, "ofs8", "imm8"); strreplace(b, "ofs8", "imm8"); //strreplace(a, "ofs16", "imm16"); strreplace(b, "ofs16", "imm16"); strreplace(a, "im8", "imm8"); strreplace(b, "im8", "imm8"); strreplace(a, "im16", "imm16"); strreplace(b, "im16", "imm16"); } //fprintf(stderr, "%s | %s\n", a, b); // NOTE: assume disp comes before imm if (strreplace(a, "intNB", "*")) { if (strreplace(b, ":intNB<<1", "")) { instruction.argInfo[instruction.argnum].flags |= ARGFLAG_INT | ARGFLAG_U | ARGFLAG_7; instruction.argInfo[instruction.argnum].shift = instruction.size * 8 + 1; instruction.size++; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } if (strreplace(a, "disp8", "*")) { if (strreplace(b, ":disp8", "")) { instruction.argInfo[instruction.argnum].flags |= ARGFLAG_S | ARGFLAG_REL | ARGFLAG_8; instruction.flags |= FLAG_REL; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size++; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } if (strreplace(a, "disp16", "*")) { if (strreplace(b, ":disp16L:disp16H", "")) { instruction.argInfo[instruction.argnum].flags |= ARGFLAG_S | ARGFLAG_REL | ARGFLAG_16; instruction.flags |= FLAG_REL; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 2; instruction.argnum++; } else if (strreplace(b, ":disp16H", "")) { instruction.argInfo[instruction.argnum].flags |= ARGFLAG_S | ARGFLAG_REL | ARGFLAG_16 | ARGFLAG_HIGH; instruction.flags |= FLAG_REL; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 1; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } if (strreplace(a, "imm8", "*")) { if (strreplace(b, ":imm8", "")) { //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_U | ARGFLAG_IMM; instruction.argInfo[instruction.argnum].flags |= ARGFLAG_U | ARGFLAG_IMM | ARGFLAG_8; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 1; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } if (strreplace(a, "imm16", "*")) { if (strreplace(b, ":imm16L:imm16H", "")) { //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_U | ARGFLAG_IMM | ARGFLAG_16; //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_U | ARGFLAG_IMM | ARGFLAG_16 | ARGFLAG_HIGH; instruction.argInfo[instruction.argnum].flags |= ARGFLAG_U | ARGFLAG_IMM | ARGFLAG_16; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 2; instruction.argnum++; } else if (strreplace(b, ":imm16H", "")) { //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_U | ARGFLAG_IMM | ARGFLAG_16 | ARGFLAG_HIGH; instruction.argInfo[instruction.argnum].flags |= ARGFLAG_U | ARGFLAG_IMM | ARGFLAG_16 | ARGFLAG_HIGH; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 1; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } if (strreplace(a, "ofs8", "*")) { if (strreplace(b, ":ofs8", "")) { //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_OFS; instruction.argInfo[instruction.argnum].flags |= ARGFLAG_OFS | ARGFLAG_8 | ARGFLAG_U; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 1; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } if (strreplace(a, "ofs16", "*")) { if (strreplace(b, ":ofs16L:ofs16H", "")) { //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_OFS | ARGFLAG_16; //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_OFS | ARGFLAG_16 | ARGFLAG_HIGH; instruction.argInfo[instruction.argnum].flags |= ARGFLAG_OFS | ARGFLAG_16 | ARGFLAG_U; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 2; instruction.argnum++; } else if (strreplace(b, ":ofs16H", "")) { //instruction.size++; instruction.argflags[instruction.argbytes++] |= instruction.argnum | ARGFLAG_OFS | ARGFLAG_16 | ARGFLAG_HIGH; instruction.argInfo[instruction.argnum].flags |= ARGFLAG_OFS | ARGFLAG_16 | ARGFLAG_HIGH | ARGFLAG_U; instruction.argInfo[instruction.argnum].shift = instruction.size * 8; instruction.size += 1; instruction.argnum++; } else { printf("Error at line %d: %s", line, s); exit(1); } } DoCalc(a,b); //if (line == 496) { fprintf(stderr, "%s %s\n", a, b); exit(1); } // ****************************** // other syntax // if (strstr(s, " mov")) { strreplace(s, " mov", " ld"); ParseLine(s); } /* if (strstr(s, " subc")) { strreplace(s, " subc", " sbc"); ParseLine(s); } else if (strstr(s, " addc")) { strreplace(s, " addc", " adc"); ParseLine(s); } else if (strstr(s, " int ")) { strreplace(s, " int ", " cint "); ParseLine(s); } else if (strstr(s, " test")) { strreplace(s, " test", " tst"); ParseLine(s); } else if (strstr(s, " jdbnz")) { strreplace(s, " jdbnz", " djnz"); ParseLine(s); } else if (strstr(s, " mov")) { strreplace(s, " mov", " ld"); ParseLine(s); } else if (strstr(s, " xchg")) { strreplace(s, " xchg", " ex"); ParseLine(s); } else if (strstr(s, " call")) { strreplace(s, " call", " calr"); ParseLine(s); } else if (strstr(s, " jmp")) { strreplace(s, " jmp", " jp"); ParseLine(s); } else if (strstr(s, " not")) { strreplace(s, " not", " cpl"); ParseLine(s); } else if (strstr(s, " rol")) { strreplace(s, " rol", " rl"); ParseLine(s); } else if (strstr(s, " ror")) { strreplace(s, " ror", " rr"); ParseLine(s); } else if (strstr(s, " sal")) { strreplace(s, " sal", " sla"); ParseLine(s); } else if (strstr(s, " sar")) { strreplace(s, " sar", " sra"); ParseLine(s); } else if (strstr(s, "FLAGS")) { while (strreplace(s, "FLAGS", "f")) {}; ParseLine(s); } */ return true; }
bool CVersus::GetCounts(void) { if (_versus_fh == k_undefined) return false; int i = 0, j = 0; CardMask plCards, oppCards, deadCards, comCardsScrape, comCardsEnum, comCardsAll, usedCards; unsigned int wintemp = 0, tietemp = 0, lostemp = 0, offset = 0; unsigned int nhiwin = 0, nhitie = 0, nhilos = 0, ntiwin = 0, ntitie = 0, ntilos = 0, nlowin = 0, nlotie = 0, nlolos = 0; unsigned int nhinowwin = 0, nhinowtie = 0, nhinowlos = 0, ntinowwin = 0, ntinowtie = 0, ntinowlos = 0, nlonowwin = 0, nlonowtie = 0, nlonowlos = 0; unsigned int c0rank = 0, c1rank = 0, temprank = 0; BYTE byte[8] = {0}; long pos = 0; int listnum = 0; int card0_offset[52] = { 0, 62475, 123725, 183750, 242550, 300125, 356475, 411600, 465500, 518175, 569625, 619850, 668850, 716625, 763175, 808500, 852600, 895475, 937125, 977550, 1016750, 1054725, 1091475, 1127000, 1161300, 1194375, 1226225, 1256850, 1286250, 1314425, 1341375, 1367100, 1391600, 1414875, 1436925, 1457750, 1477350, 1495725, 1512875, 1528800, 1543500, 1556975, 1569225, 1580250, 1590050, 1598625, 1605975, 1612100, 1617000, 1620675, 1623125, 1624350 }; int betround = p_betround_calculator->betround(); int sym_userchair = (int) p_symbol_engine_userchair->userchair(); unsigned int pcard[2] = {0}; for (i=0; i<=1; i++) pcard[i] = CARD_NOCARD; unsigned int card_player[2] = {0}, card_common[5] = {0}; for (i=0; i<=1; i++) card_player[i] = p_scraper->card_player(sym_userchair, i); for (i=0; i<=4; i++) card_common[i] = p_scraper->card_common(i); // Get the lock CSLock lock(m_critsec); if (!p_symbol_engine_userchair->userchair_confirmed()) return false; if (card_player[0] == CARD_NOCARD || card_player[0] == CARD_BACK || card_player[1] == CARD_NOCARD || card_player[1] == CARD_BACK) { return false; } _nwin = _ntie = _nlos = _nhands = 0; _nhandshi = _nhandsti = _nhandslo = 0; _nhandshinow = _nhandstinow = _nhandslonow = 0; _vsprwinhi = _vsprtiehi = _vsprloshi = 0; _vsprwinti = _vsprtieti = _vsprlosti = 0; _vsprwinlo = _vsprtielo = _vsprloslo = 0; _vsprwinhinow = _vsprtiehinow = _vsprloshinow = 0; _vsprwintinow = _vsprtietinow = _vsprlostinow = 0; _vsprwinlonow = _vsprtielonow = _vsprloslonow = 0; nhiwin = nhitie = nhilos = ntiwin = ntitie = ntilos = nlowin = nlotie = nlolos = 0; // Clear counters for (listnum=0; listnum<MAX_HAND_LISTS; listnum++) _nlistwin[listnum] = _nlisttie[listnum] = _nlistlos[listnum] = 0; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // PREFLOP if (betround == k_betround_preflop) { // order cards properly if (card_player[0] < card_player[1]) { pcard[0] = card_player[0]; pcard[1] = card_player[1]; } else { pcard[0] = card_player[1]; pcard[1] = card_player[0]; } // figure out offset into file offset = 0; //for (i=1; i<pcard[0]; i++) offset += (52-i)*1225; offset += card0_offset[pcard[0]]; offset += (pcard[1]-pcard[0]-1)*1225; offset *= sizeof(byte); // seek to right position in file if ((pos = _lseek(_versus_fh, offset, SEEK_SET)) == long(k_undefined)) { return false; } wintemp = lostemp = 0; for (i=0; i<(k_number_of_cards_per_deck - 1); i++) { for (j=i+1; j<k_number_of_cards_per_deck; j++) { if (i!=pcard[0] && i!=pcard[1] && j!=pcard[0] && j!=pcard[1]) { _read(_versus_fh, &byte, sizeof(byte)); memcpy(&wintemp, &byte[0], sizeof(unsigned int)); memcpy(&lostemp, &byte[4], sizeof(unsigned int)); _nwin += wintemp; _ntie += 1712304 - wintemp - lostemp; _nlos += lostemp; _nhands = _nhands + 1; if (wintemp<lostemp) { _nhandshi = _nhandshi + 1; nhiwin += wintemp; nhitie += 1712304 - wintemp - lostemp; nhilos += lostemp; } else if (wintemp>lostemp) { _nhandslo = _nhandslo + 1; nlowin += wintemp; nlotie += 1712304 - wintemp - lostemp; nlolos += lostemp; } else { _nhandsti = _nhandsti + 1; ntiwin += wintemp; ntitie += 1712304 - wintemp - lostemp; ntilos += lostemp; } // Calculations for vs$xx$prwin, vs$xx$prtie, vs$xx$prlos c0rank = StdDeck_RANK(i); c1rank = StdDeck_RANK(j); if (c0rank < c1rank) { temprank = c0rank; c0rank = c1rank; c1rank = temprank; } for (listnum=0; listnum<MAX_HAND_LISTS; listnum++) { if ((StdDeck_SUIT(i)==StdDeck_SUIT(j) && p_formula->formula()->inlist[listnum][c0rank][c1rank]) || (StdDeck_SUIT(i)!=StdDeck_SUIT(j) && p_formula->formula()->inlist[listnum][c1rank][c0rank])) { _nlistwin[listnum] += wintemp; _nlisttie[listnum] += 1712304 - wintemp - lostemp; _nlistlos[listnum] += lostemp; } } } } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // FLOP, TURN, RIVER else if (betround >= k_betround_flop) { CardMask playerEvalCardsNow, oppEvalCardsNow; HandVal player_hv_now = 0, opp_hv_now = 0; // Common cards CardMask_RESET(comCardsScrape); if (betround >= k_betround_flop) CardMask_SET(comCardsScrape, card_common[0]); if (betround >= k_betround_flop) CardMask_SET(comCardsScrape, card_common[1]); if (betround >= k_betround_flop) CardMask_SET(comCardsScrape, card_common[2]); if (betround >= k_betround_turn) CardMask_SET(comCardsScrape, card_common[3]); if (betround >= k_betround_river) CardMask_SET(comCardsScrape, card_common[4]); // player cards CardMask_RESET(plCards); CardMask_SET(plCards, card_player[0]); CardMask_SET(plCards, card_player[1]); // all used cards CardMask_OR(usedCards, comCardsScrape, plCards); // eval player hand now CardMask_OR(playerEvalCardsNow, plCards, comCardsScrape); player_hv_now = Hand_EVAL_N(playerEvalCardsNow, betround+3); // Enumerate through all possible opponent hands (excludes already used cards) for (i=0; i<=50; i++) { for (j=i+1; j<=51; j++) { if (!CardMask_CARD_IS_SET(usedCards, i) && !CardMask_CARD_IS_SET(usedCards, j)) { CardMask_RESET(oppCards); CardMask_SET(oppCards, i); CardMask_SET(oppCards, j); // Enumerate through all possible river situations (exclude player cards and opponent cards) CardMask_OR(deadCards, usedCards, oppCards); wintemp = tietemp = lostemp = 0; if (betround==k_betround_flop || betround==k_betround_turn) { ENUMERATE_N_CARDS_D(comCardsEnum, betround==k_betround_flop ? 2 : betround==k_betround_turn ? 1 : 0, deadCards, { CardMask_OR(comCardsAll, comCardsScrape, comCardsEnum); DoCalc(plCards, oppCards, comCardsAll, &wintemp, &tietemp, &lostemp); }); }
/* * DoCalc */ void DoCalc(char *a, char *b) { if (strstr(b, "+rw1")) { for (int i=0; i<6; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rw1", rw[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rw1", rwnum[i]); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rw2")) { for (int i=0; i<6; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rw2", rw[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rw2", rwnum[i]); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rw")) { for (int i=0; i<6; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rw", rw[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rw", rwnum[i]); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rb1")) { for (int i=0; i<4; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rb1", rb[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rb1", i); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rb2")) { for (int i=0; i<4; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rb2", rb[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rb2", i); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rb")) { for (int i=0; i<4; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rb", rb[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rb", i); DoCalc(tmp_a, tmp_b); } } else { //fprintf(stderr, "1 %s %s\n", a, b); strshift(b); //fprintf(stderr, "2 %s %s\n", a, b); stradd(b); //fprintf(stderr, "3 %s %s\n", a, b); STRUPR(a); strtrimtrailing(a); strtrimtrailing(b); int numargs = 0; if (strreplace(a, "*", "~0")) numargs++; if (strreplace(a, "*", "~1")) numargs++; if (strreplace(a, "*", "~2")) numargs++; // ..... //strreplace(b, ":", ""); instruction.fmt = a; //instruction.opcode = strtoul(b,0,16); //instruction.fixed |= strtoul(b,0,16) << ((instruction.flags & FLAG_EXTENDED) ? 1 : 0); unsigned int instruction_fixed = instruction.fixed | (strtoul(b,0,16) << ((instruction.flags & FLAG_EXTENDED) ? 8 : 0)); // no continue flag if (!(instruction.flags & FLAG_EXTENDED)) switch (instruction.fixed & 0xFF) { case 0xF1: case 0xF3: case 0xF4: case 0xF8: case 0xF9: break; default: instruction.flags |= FLAG_CONT; } char s[BUFSIZE], *p = s; // NOTE: leading text is added later // see mindx_type.h for structure fields p += sprintf(p, "%s\"", instruction.fmt); //for (int i=0; i<30-(p-s); i++) { p += sprintf(p, " "); } p += sprintf(p, ",0x%02X,0x%02X,%d,%d", instruction.flags, instruction_fixed, instruction.size, instruction.argnum); for (unsigned int i=0; i<instruction.argnum; i++) { p += sprintf(p, ",%d,%d", instruction.argInfo[i].shift, instruction.argInfo[i].flags); } p += sprintf(p, "\t; %d\n", line); /* p += sprintf(p, "%s\",0x%02X,0x%02X,0x%02X,%d,%d,%d,{", instruction.fmt, instruction.flags, instruction.extended, instruction.opcode, instruction.size, instruction.argnum, instruction.argbytes); for (int i=0; i<MAX_ARGS; i++) { p += sprintf(p, "0x%03X,", instruction.argflags[i]); } //%d,%d", flags, numargs, p += sprintf(p, "}},//%d\n", line); */ output[outputs++] = strdup(s); // this is going to be sorted alphabetically } }