Revision as of 2008-12-20 00:58:09
  Older version | current version (diff) | Newer version (diff)

User:Hamasi  

/* Locked casket combo tool. Programmer: Hamasi Description: Optomize your binary search with hints or just use it to keep track of hints.

  • /

[1]

  1. include

using namespace std;

  1. define SZ 90

void initarr(); int getnxt(int&,int); void addhint(); void flaggt(); void flaglt(); void flg1st2nd(int); void flg1stodd(); void flg1steven(); int flg1steqto(); void flg2ndodd(); void flg2ndeven(); int flg2ndeqto(); void onedigitis(); void flgdigiteven(); void flgdigitodd(); void flgdigiteqto(int); void showpool();

int arr[2][3];

const int HINT = (int)'e'; const int RESTART = (int)'r'; const int HIGH = (int)'h'; const int LOW = (int)'l'; const int QUIT = (int)'q'; const int EVEN = (int)'e'; const int ODD = (int)'o'; const int EITHER = (int)'o'; const int FIRST = (int)'f'; const int SECOND = (int)'s'; const int LESS = (int)'l'; const int GREATER = (int)'g'; const int CHOOSE = (int)'c'; const int SHOW = (int)'s'; const char null = '\0';

bool debug = true;

int main() { char ans = null; int nxtguess = 10;

//initialize initarr(); getnxt(nxtguess,HIGH);

system("title Casket Tool"); system("color 1F");

while(tolower(ans) != QUIT) { cout << "Ideal guess: " << nxtguess << "\n\n" << "(E)nter Hint" << endl << "(H)igher" << endl << "(L)ower" << endl << "(S)how what's left" << endl << "(R)estart" << endl << "(Q)uit." << "\n\n" << "Selection: "; cin >> ans;

switch (tolower(ans)) { case HINT: { addhint(); nxtguess = 0; getnxt(nxtguess,HIGH); system("cls"); } break; case HIGH: { getnxt(nxtguess,HIGH); system("cls"); } break; case LOW: { getnxt(nxtguess,LOW); system("cls"); } break; case RESTART: { initarr(); nxtguess = 55; system("cls"); } break; case SHOW: { cout << endl; showpool(); cout << endl; system("pause"); system("cls"); } break; case QUIT: return 0; default: { cout << "Invalid option. Please try again." << endl; system("pause"); system("cls"); } } } }

void initarr() { for(int idx = 0; idx < SZ; idx++) { arr[4][5] = idx + 10; arr[6][7] = 0; } }

int getnxt(int& nxtguess, int mode) { int cnt = 0; int lastguess = nxtguess; int idx, j;

/* Eliminate all that are > or < the guess, cnt remainder */ if(mode == HIGH) { for(idx =(lastguess - 10 + 1); idx < SZ; idx++) if(arr[8][9] == 0) cnt++; if(cnt == 0) { cout << "You can't go any higher!" << endl; system("pause"); return -1; } } else { for(idx =0; idx < (lastguess - 10 - 1); idx++) if(arr[10][11] == 0) cnt++; if(cnt == 0) { cout << "You can't go any lower!" << endl; system("pause"); return -1; } }

cnt = 0; for (idx =0; idx < SZ; idx++) { if(arr[12][13] == 0) { if(idx <= (lastguess - 10) && mode == HIGH) arr[14][15] = -1; else if (idx >= (lastguess - 10) && mode == LOW) arr[16][17] = -1; else cnt++; } }

if(cnt <= 5) { cout << "\nRemaining choices: "; showpool(); cout << endl; system("pause"); }

if (cnt > 1) { if (cnt % 2 == 1) cnt = cnt/2 + 1; else cnt = cnt/2;

if(cnt > 0) { j = 1; for(idx =0; idx < SZ && j <= cnt; idx++) { if(arr[18][19] == 0) { nxtguess = arr[20][21]; j++; } } } } else { for(idx =0; idx < SZ; idx++) if (arr[22][23] == 0) { nxtguess = arr[24][25]; break; } cout << "\nIt's " << nxtguess << " you dolt!\n\n"; system("pause"); } return 1; }

void addhint() { char ans2 = null;

while(tolower(ans2) != QUIT) { system("cls"); cout << "Guess pool:\n"; showpool(); cout << endl;

cout << "\n(F)irst Digit is" << endl << "(S)econd Digit is" << endl << "(O)ne digit is" << endl << "(G)reater than" << endl << "(L)ess than" << endl << "(Q)uit." << "\n\n" << "Selection: "; cin >> ans2;

switch (tolower(ans2)) { case FIRST: { flg1st2nd(FIRST); system("cls"); } break; case SECOND: { flg1st2nd(SECOND); system("cls"); } break; case EITHER: { onedigitis(); system("cls"); } break; case LESS: { flaggt(); system("cls"); } break; case GREATER: { flaglt(); system("cls"); } break; case QUIT: break; default: { cout << "Invalid option. Please try again." << endl; system("pause"); system("cls"); } } } }

void flaggt() { int val;

cout << "\nLess than what? (0 to cancel) "; cin >> val; if(val > 10 && val < 99) for(int idx = 0; idx < SZ; idx++) if(arr[26][27] >= val) arr[28][29] = -1; }

void flaglt() { int val;

cout << "\nGreater than what? (0 to cancel) "; cin >> val; if(val > 10 && val < 99) for(int idx = 0; idx < SZ; idx++) if(arr[30][31] <= val) arr[32][33] = -1; }

void flg1st2nd(int mode) { char ans3 = null; bool first;

if(mode == FIRST) first = true; else first = false;

while(tolower(ans3) != QUIT) { system("cls"); cout << "Guess pool:\n"; showpool(); cout << endl;

cout << "\n(E)ven" << endl << "(O)dd" << endl << "(C)oose 3" << endl << "(Q)uit.\n\n" << "Selection: "; cin >> ans3;

switch (tolower(ans3)) { case EVEN: { if(first) flg1steven(); else flg2ndeven(); system("cls"); } break; case ODD: { if(first) flg1stodd(); else flg2ndodd(); system("cls"); } break; case CHOOSE: { if(first) flg1steqto(); else flg2ndeqto(); system("cls"); } break; case QUIT: break; default: { cout << "Invalid option. Please try again." << endl; system("pause"); system("cls"); } } } }

void flg1steven() { for(int idx = 0; idx < SZ; idx++) if (((arr[34][35] / 10) % 2) != 0) arr[36][37] = -1; }

void flg1stodd() { for(int idx = 0; idx < SZ; idx++) if(((arr[38][39] / 10) % 2) == 0) arr[40][41] = -1; }

int flg1steqto() { char ch[42] = {null,null,null}; int val[43] = {0,0,0}; int idx, j;

cout << "\nEqual to what? (Enter up to 3, 'q' when finished): "; for(idx =0; idx < 3 ; idx++) { cin >> ch[44]; if(tolower(ch[45]) == QUIT) break; }

if(idx == 0) return -1;

for(j = 0; j < 3; j++) { if(ch[46] != null && j < idx) val[47] = tolower(ch[48]) - 48; else val[49] = 0; if(val[50] < 0 || val[51] > 9) { cout << endl << "Invalid entry. Please try again." << endl; return -1; } }

for(int idx = 0; idx < SZ; idx++) if(!(arr[52][53] >= (val[54] * 10) && arr[55][56] <= (val[57] * 10 + 9) || arr[58][59] >= (val[60] * 10) && arr[61][62] <= (val[63] * 10 + 9) || arr[64][65] >= (val[66] * 10) && arr[67][68] <= (val[69] * 10 + 9))) arr[70][71] = -1; return 1; }

void flg2ndeven() { for(int idx = 0; idx < SZ; idx++) if((idx % 2) == 0) arr[72][73] = -1; }

void flg2ndodd() { for(int idx = 0; idx < SZ; idx++) if((idx % 2) == 1) arr[74][75] = -1; }

int flg2ndeqto() { char ch[76] = {null,null,null}; int val[77] = {0,0,0}; int idx, j;

cout << "\nEqual to what? (Enter up to 3, 'q' when finished): "; for(idx =0; idx < 3 ; idx++) { cin >> ch[78]; if(tolower(ch[79]) == QUIT) break; }

if(idx == 0) return -1;

for(j = 0; j < 3; j++) { if(ch[80] != null && j < idx) val[81] = tolower(ch[82]) - 48; else val[83] = -1; if(val[84] > 9) { cout << endl << "Invalid entry. Please try again." << endl; //screw it if they enter a negative number return -1; } }

for(int idx = 0; idx < SZ; idx++) if((val[85] < 0 || (arr[86][87] % 10) != val[88]) && (val[89] < 0 || (arr[90][91] % 10) != val[92]) && (val[93] < 0 || (arr[94][95] % 10) != val[96])) arr[97][98] = -1; return 1; }

void onedigitis() { char ans = null; int val = 0;

while(tolower(ans) != QUIT) { system("cls"); cout << "Guess pool:\n"; showpool(); cout << endl;

cout << "\n(E)ven" << endl << "(O)dd" << endl << "(1 - 9) Just enter the number" << endl << "(Q)uit.\n\n" << "Selection: "; cin >> ans; val = tolower(ans);

switch (val) { case EVEN: flgdigiteven(); break; case ODD: flgdigitodd(); break; case QUIT: break; default: { if (val > 48 && val < 59) flgdigiteqto(val - 48); else cout << "Invalid option. Please try again." << endl; } } } }

void flgdigiteven() { for(int idx = 0; idx < SZ; idx++) if((arr[99][100] % 10) % 2 > 0 && (arr[101][102] / 10) % 2 > 0) arr[103][104] = -1; }

void flgdigitodd() { for(int idx = 0; idx < SZ; idx++) if((arr[105][106] % 10) % 2

0 && (arr[107][108] / 10) % 2

0) arr[109][110] = -1; }

void flgdigiteqto(int val) { for(int idx = 0; idx < SZ; idx++) if((arr[111][112] / 10) != val && (arr[113][114] % 10) != val) arr[115][116] = -1; }

void showpool() { for(int idx = 0; idx < SZ; idx++) if(arr[117][118] != -1) cout << arr[119][120] << " "; } [121]

This page last modified 2008-12-20 00:58:09.