int worstDigraphs(Keyboard *k, int damagingp) { int i; for (i = 0; i < FINGER_COUNT; ++i) k->fingerUsage[i] = 0; char keys[diLen][2]; memcpy(keys, diKeys, sizeof(char) * diLen * 2); int64_t values[diLen]; for (i = 0; i < diLen; ++i) { k->distance = 0; k->inRoll = 0; k->outRoll = 0; k->sameHand = 0; k->sameFinger = 0; k->rowChange = 0; k->homeJump = 0; k->toCenter = 0; k->toOutside = 0; int locs[2]; locs[0] = locWithoutShifted(k, diKeys[i][0]); locs[1] = locWithoutShifted(k, diKeys[i][1]); // These all require that the hand be the same. if (hand[locs[0]] == hand[locs[1]]) { k->inRoll = calcInRoll (locs[0], locs[1]); k->outRoll = calcOutRoll (locs[0], locs[1]); k->sameHand = sameHand ; k->sameFinger = calcSameFinger(locs[0], locs[1]); k->rowChange = calcRowChange (locs[0], locs[1]); k->homeJump = calcHomeJump (locs[0], locs[1]); k->toCenter = calcToCenter (locs[0], locs[1]); k->toOutside = calcToOutside (locs[0], locs[1]); } k->distance = (distanceCosts[locs[0]] + distanceCosts[locs[1]]) * distance; /* Re-assign diValues[i] to the cost of that digraph. */ values[i] = k->distance + k->inRoll + k->outRoll + k->sameHand + k->sameFinger + k->rowChange + k->homeJump + k->toCenter + k->toOutside; /* This function will tell you... * Without this line: Which digraphs have the worst score. * With this line: Which digraphs are the most damaging, based on both score and frequency. */ if (damagingp) values[i] *= diValues[i]; } sortDigraphs(keys, values, 0, diLen - 1); for (i = 0; i < diLen; ++i) { char buf1[5]; char buf2[5]; charToPrintable(buf1, keys[i][0], FALSE); charToPrintable(buf2, keys[i][1], FALSE); printf("%s%s = %lld\n", buf1, buf2, values[i]); } return 0; }
int worstDigraphs(Keyboard *k, int damagingp) { int i; for (i = 0; i < FINGER_COUNT; ++i) k->fingerUsage[i] = 0; struct Digraph worst[diLen]; memcpy(worst, digraphs, sizeof(worst) * diLen); for (i = 0; i < diLen; ++i) { k->distance = 0; k->inRoll = 0; k->outRoll = 0; k->sameHand = 0; k->sameFinger = 0; k->rowChange = 0; k->homeJump = 0; k->toCenter = 0; k->toOutside = 0; int locs[2]; locs[0] = locIgnoreShifted(k, worst[i].key[0]); locs[1] = locIgnoreShifted(k, worst[i].key[1]); // These all require that the hand be the same. if (hand[locs[0]] == hand[locs[1]]) { k->inRoll = calcInRoll (locs[0], locs[1]); k->outRoll = calcOutRoll (locs[0], locs[1]); k->sameHand = sameHand ; k->sameFinger = calcSameFinger(locs[0], locs[1]); k->rowChange = calcRowChange (locs[0], locs[1]); k->homeJump = calcHomeJump (locs[0], locs[1]); k->toCenter = calcToCenter (locs[0], locs[1]); k->toOutside = calcToOutside (locs[0], locs[1]); } k->distance = (distanceCosts[locs[0]] + distanceCosts[locs[1]]) * distance; /* Re-assign digraphs[i].value to the cost of that digraph. */ worst[i].value = k->distance + k->inRoll + k->outRoll + k->sameHand + k->sameFinger + k->rowChange + k->homeJump + k->toCenter + k->toOutside; /* This function will tell you... * Without this line: Which digraphs have the worst score. * With this line: Which digraphs are the most damaging, based on both score and frequency. */ if (damagingp) worst[i].value *= digraphs[i].value; } qsort(worst, diLen, sizeof(struct Digraph), &cmpDigraphsByValue); for (i = 0; i < diLen; ++i) { char buf1[5]; char buf2[5]; charToPrintable(buf1, worst[i].key[0], FALSE); charToPrintable(buf2, worst[i].key[1], FALSE); printf("%s%s = %lld\n", buf1, buf2, worst[i].value); } return 0; }