summaryrefslogtreecommitdiff
path: root/lulua/writer.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2020-03-08 08:34:13 +0100
committerLars-Dominik Braun <lars@6xq.net>2020-03-08 08:42:26 +0100
commit59ca079dba6c95948ebbf6442066e9313d330302 (patch)
treec2c608100202c4e7df750331f6382b00fe6bce50 /lulua/writer.py
parentbe5f8fd5ee5ef8d6ece3345ae1c2bbee134be59a (diff)
downloadlulua-59ca079dba6c95948ebbf6442066e9313d330302.tar.gz
lulua-59ca079dba6c95948ebbf6442066e9313d330302.tar.bz2
lulua-59ca079dba6c95948ebbf6442066e9313d330302.zip
writer: Fix bug in chooseCombination
Some combinations had the same score and the “wrong” one was chosen as a result. This affects how key combinations are chosen and thus it significantly affects results (lowering ar-lulua’s asymmetry and increasing it for almost every other layout) and probably optimization of levels > 1.
Diffstat (limited to 'lulua/writer.py')
-rw-r--r--lulua/writer.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/lulua/writer.py b/lulua/writer.py
index 94ad1b4..a186315 100644
--- a/lulua/writer.py
+++ b/lulua/writer.py
@@ -152,29 +152,36 @@ class Writer:
- A key on the right is usually combined with the shift button on the
left and vice versa.
- The spacebar is usually hit by the thumb of the previously unused
- hand or the one on the left if two buttons were pressed at the same
- time.
+ hand. If two hands were used the one pressing the key (not the
+ modifier) is chosen, since it’ll usually be closer.
- The combination with the minimum amount of fingers required is chosen
if multiple options are available
"""
+ if len (combinations) == 1:
+ return combinations[0]
+
dirToScore = {LEFT: 1, RIGHT: -1}
def calcEffort (comb):
prev = self.lastCombination
- if prev is None:
- e = 0
- elif len (prev) > 1:
- # prefer left side
- e = dirToScore[RIGHT]
+
+ if prev is not None:
+ prevBalance = 0
+ for b in chain (prev.modifier or prev.buttons, comb.buttons):
+ pos = self.getHandFinger (b)[0]
+ prevBalance += dirToScore[pos]
else:
- assert len (prev.buttons) == 1
- e = dirToScore[self.getHandFinger (first (prev.buttons))[0]]
+ # prefer the left side (arbitrary decision)
+ prevBalance = dirToScore[RIGHT]
+
+ balance = 0
for b in comb:
pos = self.getHandFinger (b)[0]
- e += dirToScore[pos]
- #print ('score for', buttons, abs (e))
- return abs (e) + len (comb)
+ balance += dirToScore[pos]
+
+ return (len (comb) << 16) | (abs (balance) << 8) | (abs (prevBalance) << 0)
- return min (zip (map (calcEffort, combinations), combinations), key=itemgetter (0))[1]
+ m = min (zip (map (calcEffort, combinations), combinations), key=itemgetter (0))
+ return m[1]
def press (self, comb):
self.lastCombination = comb