# on enlève ce qu'on a déjà testé (sauvegardé) for keys in results[handID]: for key in keys: if key in untested: untested.remove(key) else: print '"' + key + u'" n\'est pas là!!!' print untested print results[handID] random.shuffle(untested) # tant qu'on a pas testé tous les caractères while len(untested) > 0 and run: c = untested[0] # on récupère le premier caractère correspondant C = key_vote_lib.posToString( c, kbd ) if len(results[handID]) == 0: # si le tableau de résultats est vide results[handID].append((c,)) # on ajoute notre caractère else: min = 0 # minimum de la dichotomie max = len(results[handID])-1 # maximum de la dichotomie # après le choix, on aura 0 <= c <= len(...) while min <= max and run: middle = (max+min)/2 # on choisit le milieu (dichotomie) test = results[handID][middle][0] # on va tester c par rapport à ce caractère TEST = key_vote_lib.posToString( test, kbd ) pair = ( c, test )
chars = leftHand.ljust( 100 ) + rightHand rightHomePos = [(11,), (12,), (13,), (14,)] leftHomePos = [(115,), (116,), (117,), (118,)] homePos = rightHomePos + leftHomePos run = True nbOfSearch = 0 while run: for min, max in [ ( 0, len( leftHand ) - 1 ) ] * nbOfVotes + [ ( 100, 100 + len( rightHand ) - 1 ) ] * nbOfVotes: candidate1 = generateCandidate( nbOfChars, min, max ) candidate2 = generateCandidate( nbOfChars, min, max, candidate1 ) pair = tuple( sorted( ( candidate1, candidate2 ) ) ) candidate1, candidate2 = pair s1 = key_vote_lib.posToString( pair[0], hands ) s2 = key_vote_lib.posToString( pair[1], hands ) if pair not in results: nbOfSearch = 0 if candidate1 in homePos and candidate2 not in homePos : results[ pair ] = 1 key_vote_lib.printStdOut( 'Vote automatique: ' + key_vote_lib.posToString( candidate1, hands ) + ' > ' + key_vote_lib.posToString( candidate2, hands ) ) elif candidate2 in homePos and candidate1 not in homePos : results[ pair ] = 2 key_vote_lib.printStdOut( 'Vote automatique: ' + key_vote_lib.posToString( candidate1, hands ) + ' < ' + key_vote_lib.posToString( candidate2, hands ) ) elif candidate2 in homePos and candidate1 in homePos : results[ pair ] = 0 key_vote_lib.printStdOut( 'Vote automatique: ' + key_vote_lib.posToString( candidate1, hands ) + ' = ' + key_vote_lib.posToString( candidate2, hands ) ) else: # not automatic vote key_vote_lib.printKbdLayout(hands, (s1,s2) )