solvemind.c
Code calcBestGuess(TurnNode *turnStack) {
    Code code;
    setCodeToZero(&code);
    size_t codeIndex = 0;

    unsigned bestGuessEval = UINT_MAX;
    Code bestGuess;
    setCodeToZero(&bestGuess);

    //create cache of all possible codes
    char *possibleCodeBools = malloc(getCodeCount());
    do {
        possibleCodeBools[codeIndex] = (char) codeFitsTurnStack(code, turnStack);
        codeIndex++;
    } while(nextCode(&code));

    //restart code iteration
    setCodeToZero(&code);
    codeIndex = 0;

    do {
        if(codeIndex % 5 == 0) {
            printf("Checking %d...\r", (int) codeIndex);
            fflush(stdout);
        }

        unsigned eval = evalGuess(code, turnStack, possibleCodeBools);

        //give 0.5 points for being a possible code
        //(normalized by times 2 to be integer)
        eval *= 2;
        eval -= possibleCodeBools[codeIndex];

        //find (arg) min
        if(eval < bestGuessEval) {
            bestGuessEval = eval;
            bestGuess = code;
        }
        codeIndex++;
    } while(nextCode(&code));

    //clean up
    printf("                            \r");
    free(possibleCodeBools);
    printf("%d\n", bestGuessEval / 2);

    return bestGuess;
}
/*
 * Brut-force the best guess (as measuerd by the function above)
 */
Brut-force the best guess (as measuerd by the function above)
Brut - force the best guess ( as measuerd by the function above )
Code calcBestGuess(TurnNode *turnStack) {
    Code code;
    setCodeToZero(&code);
    size_t codeIndex = 0;
    unsigned bestGuessEval = UINT_MAX;
    Code bestGuess;
    setCodeToZero(&bestGuess);
    char *possibleCodeBools = malloc(getCodeCount());
    do {
        possibleCodeBools[codeIndex] = (char) codeFitsTurnStack(code, turnStack);
        codeIndex++;
    } while(nextCode(&code));
    setCodeToZero(&code);
    codeIndex = 0;
    do {
        if(codeIndex % 5 == 0) {
            printf("Checking %d...\r", (int) codeIndex);
            fflush(stdout);
        }
        unsigned eval = evalGuess(code, turnStack, possibleCodeBools);
        eval *= 2;
        eval -= possibleCodeBools[codeIndex];
        if(eval < bestGuessEval) {
            bestGuessEval = eval;
            bestGuess = code;
        }
        codeIndex++;
    } while(nextCode(&code));
    printf("                            \r");
    free(possibleCodeBools);
    printf("%d\n", bestGuessEval / 2);
    return bestGuess;
}
Code calcBestGuess ( TurnNode * turnStack ) { Code code ; setCodeToZero ( & code ) ; size_t codeIndex = 0 ; unsigned bestGuessEval = UINT_MAX ; Code bestGuess ; setCodeToZero ( & bestGuess ) ; char * possibleCodeBools = malloc ( getCodeCount ( ) ) ; do { possibleCodeBools [ codeIndex ] = ( char ) codeFitsTurnStack ( code , turnStack ) ; codeIndex ++ ; } while ( nextCode ( & code ) ) ; setCodeToZero ( & code ) ; codeIndex = 0 ; do { if ( codeIndex % 5 == 0 ) { printf ( " \r " , ( int ) codeIndex ) ; fflush ( stdout ) ; } unsigned eval = evalGuess ( code , turnStack , possibleCodeBools ) ; eval *= 2 ; eval -= possibleCodeBools [ codeIndex ] ; if ( eval < bestGuessEval ) { bestGuessEval = eval ; bestGuess = code ; } codeIndex ++ ; } while ( nextCode ( & code ) ) ; printf ( " \r " ) ; free ( possibleCodeBools ) ; printf ( " \n " , bestGuessEval / 2 ) ; return bestGuess ; }
Brut-force the best guess (as measuerd by the function above)
Brut - force the best guess ( as measuerd by the function above )
//create cache of all possible codes //restart code iteration //give 0.5 points for being a possible code //(normalized by times 2 to be integer) //find (arg) min //clean up