rewrite the config format
This commit is contained in:
@ -13,7 +13,7 @@ from dataclasses import dataclass
|
|||||||
from solver import EOLRBSolution, solve_eolrb, create_eolrb_prune_table
|
from solver import EOLRBSolution, solve_eolrb, create_eolrb_prune_table
|
||||||
from scorer import (
|
from scorer import (
|
||||||
FingerTrickWithRegrip,
|
FingerTrickWithRegrip,
|
||||||
load_config,
|
load_definitions,
|
||||||
generate_finger_tricks,
|
generate_finger_tricks,
|
||||||
build_pretty_string_from_finger_tricks_with_regrips,
|
build_pretty_string_from_finger_tricks_with_regrips,
|
||||||
)
|
)
|
||||||
@ -60,7 +60,7 @@ def load_or_generate_prune_table(file_path: str, prune_size: int) -> Dict:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = load_config("./moves.yaml")
|
definitions = load_definitions("./moves.yaml")
|
||||||
prune_table = load_or_generate_prune_table("prune_table.pkl", PRUNE)
|
prune_table = load_or_generate_prune_table("prune_table.pkl", PRUNE)
|
||||||
print("prune table size:", humanize.naturalsize(sys.getsizeof(prune_table)))
|
print("prune table size:", humanize.naturalsize(sys.getsizeof(prune_table)))
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ def main():
|
|||||||
solutions = get_first_n_from_generator(alg_generator, SOLUTIONS_TO_EVAL)
|
solutions = get_first_n_from_generator(alg_generator, SOLUTIONS_TO_EVAL)
|
||||||
solutions_with_finger_tricks = [
|
solutions_with_finger_tricks = [
|
||||||
EOLRBSolutionWithFingertricks(
|
EOLRBSolutionWithFingertricks(
|
||||||
solution, generate_finger_tricks(config, solution.alg)
|
solution, generate_finger_tricks(definitions, solution.alg)
|
||||||
)
|
)
|
||||||
for solution in solutions
|
for solution in solutions
|
||||||
]
|
]
|
||||||
|
|||||||
235
moves.yaml
235
moves.yaml
@ -1,11 +1,63 @@
|
|||||||
# TODO: do a lot of random MU algs and find out which moves are statistically faster
|
fingers:
|
||||||
|
- name: index
|
||||||
|
default_score: 1
|
||||||
|
home_grips:
|
||||||
|
- BL
|
||||||
|
- LB
|
||||||
|
# TODO: change to grip_set
|
||||||
|
grips:
|
||||||
|
side:
|
||||||
|
- B
|
||||||
|
- BL
|
||||||
|
- LB
|
||||||
|
- LF
|
||||||
|
- FL
|
||||||
|
- F
|
||||||
|
top:
|
||||||
|
- UF
|
||||||
|
regrips:
|
||||||
|
- start: UF
|
||||||
|
end: BL
|
||||||
|
score: 3
|
||||||
|
# TODO: this doesn't need to be here
|
||||||
|
finger: index
|
||||||
|
- start: UF
|
||||||
|
end: LB
|
||||||
|
score: 3
|
||||||
|
# TODO: this doesn't need to be here
|
||||||
|
finger: index
|
||||||
|
- name: ring
|
||||||
|
default_score: 1
|
||||||
|
home_grips:
|
||||||
|
- B
|
||||||
|
- DB
|
||||||
|
grips:
|
||||||
|
slice:
|
||||||
|
- B
|
||||||
|
- DB
|
||||||
|
- DF
|
||||||
|
- F
|
||||||
|
regrips: []
|
||||||
|
- name: pinky
|
||||||
|
default_score: 1
|
||||||
|
home_grips:
|
||||||
|
- DB
|
||||||
|
- DF
|
||||||
|
grips:
|
||||||
|
slice:
|
||||||
|
- B
|
||||||
|
- DB
|
||||||
|
- DF
|
||||||
|
- F
|
||||||
|
- F floating
|
||||||
|
regrips: []
|
||||||
finger_tricks:
|
finger_tricks:
|
||||||
- name: "U push"
|
- name: "U push"
|
||||||
move: "U"
|
move: "U"
|
||||||
grip_pre:
|
grip_pre:
|
||||||
index: LB
|
index: LB
|
||||||
grip_post:
|
grip_post:
|
||||||
index: BR
|
index: B
|
||||||
grip_pre_blacklist: {}
|
grip_pre_blacklist: {}
|
||||||
score: 5
|
score: 5
|
||||||
- name: "U flick"
|
- name: "U flick"
|
||||||
@ -13,6 +65,7 @@ finger_tricks:
|
|||||||
grip_pre:
|
grip_pre:
|
||||||
index: F
|
index: F
|
||||||
grip_post:
|
grip_post:
|
||||||
|
# TODO: rethink this parameter
|
||||||
index: LB
|
index: LB
|
||||||
grip_pre_blacklist: {}
|
grip_pre_blacklist: {}
|
||||||
score: 4
|
score: 4
|
||||||
@ -61,7 +114,7 @@ finger_tricks:
|
|||||||
grip_pre:
|
grip_pre:
|
||||||
index: F
|
index: F
|
||||||
grip_post:
|
grip_post:
|
||||||
index: BR
|
index: B
|
||||||
grip_pre_blacklist: {}
|
grip_pre_blacklist: {}
|
||||||
score: 5
|
score: 5
|
||||||
- name: "M' ring flick"
|
- name: "M' ring flick"
|
||||||
@ -82,6 +135,7 @@ finger_tricks:
|
|||||||
grip_pre_blacklist:
|
grip_pre_blacklist:
|
||||||
index:
|
index:
|
||||||
- BL
|
- BL
|
||||||
|
- UF
|
||||||
score: 6
|
score: 6
|
||||||
- name: "M push"
|
- name: "M push"
|
||||||
move: "M"
|
move: "M"
|
||||||
@ -90,6 +144,14 @@ finger_tricks:
|
|||||||
grip_post:
|
grip_post:
|
||||||
pinky: DB
|
pinky: DB
|
||||||
grip_pre_blacklist: {}
|
grip_pre_blacklist: {}
|
||||||
|
score: 5
|
||||||
|
- name: "M index push"
|
||||||
|
move: "M"
|
||||||
|
grip_pre:
|
||||||
|
index: B
|
||||||
|
grip_post:
|
||||||
|
index: UF
|
||||||
|
grip_pre_blacklist: {}
|
||||||
score: 6
|
score: 6
|
||||||
- name: "M2 double flick"
|
- name: "M2 double flick"
|
||||||
move: "M2"
|
move: "M2"
|
||||||
@ -101,170 +163,3 @@ finger_tricks:
|
|||||||
ring: DB
|
ring: DB
|
||||||
grip_pre_blacklist: {}
|
grip_pre_blacklist: {}
|
||||||
score: 7
|
score: 7
|
||||||
regrips:
|
|
||||||
# TODO: rethink this format?
|
|
||||||
# TODO: be able to write all possible grips for a finger and score JUST adj regrips
|
|
||||||
- finger: index
|
|
||||||
pre: BR
|
|
||||||
post: LB
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: BL
|
|
||||||
post: LB
|
|
||||||
score: 1
|
|
||||||
- finger: index
|
|
||||||
pre: BR
|
|
||||||
post: LF
|
|
||||||
score: 3
|
|
||||||
- finger: index
|
|
||||||
pre: BL
|
|
||||||
post: LF
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: BR
|
|
||||||
post: F
|
|
||||||
score: 3
|
|
||||||
- finger: index
|
|
||||||
pre: BL
|
|
||||||
post: F
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: LB
|
|
||||||
post: BL
|
|
||||||
score: 1
|
|
||||||
- finger: index
|
|
||||||
pre: LB
|
|
||||||
post: LF
|
|
||||||
score: 1
|
|
||||||
- finger: index
|
|
||||||
pre: LB
|
|
||||||
post: F
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: LF
|
|
||||||
post: BR
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: LF
|
|
||||||
post: LB
|
|
||||||
score: 1
|
|
||||||
- finger: index
|
|
||||||
pre: LF
|
|
||||||
post: F
|
|
||||||
score: 1
|
|
||||||
- finger: index
|
|
||||||
pre: F
|
|
||||||
post: BL
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: F
|
|
||||||
post: LB
|
|
||||||
score: 2
|
|
||||||
- finger: index
|
|
||||||
pre: F
|
|
||||||
post: LF
|
|
||||||
score: 1
|
|
||||||
- finger: ring
|
|
||||||
pre: B
|
|
||||||
post: DB
|
|
||||||
score: 1
|
|
||||||
- finger: ring
|
|
||||||
pre: B
|
|
||||||
post: DF
|
|
||||||
score: 2
|
|
||||||
- finger: ring
|
|
||||||
pre: DB
|
|
||||||
post: B
|
|
||||||
score: 2
|
|
||||||
- finger: ring
|
|
||||||
pre: DB
|
|
||||||
post: DF
|
|
||||||
score: 1
|
|
||||||
- finger: ring
|
|
||||||
pre: DF
|
|
||||||
post: B
|
|
||||||
score: 2
|
|
||||||
- finger: ring
|
|
||||||
pre: DF
|
|
||||||
post: DB
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: B
|
|
||||||
post: DB
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: B
|
|
||||||
post: DF
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: B
|
|
||||||
post: F
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: B
|
|
||||||
post: F floating
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: DB
|
|
||||||
post: B
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: DB
|
|
||||||
post: DF
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: DB
|
|
||||||
post: F
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: DB
|
|
||||||
post: F floating
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: DF
|
|
||||||
post: B
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: DF
|
|
||||||
post: DB
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: DF
|
|
||||||
post: F
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: DF
|
|
||||||
post: F floating
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: F
|
|
||||||
post: B
|
|
||||||
score: 3
|
|
||||||
- finger: pinky
|
|
||||||
pre: F
|
|
||||||
post: DB
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: F
|
|
||||||
post: DF
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: F
|
|
||||||
post: F floating
|
|
||||||
score: 1
|
|
||||||
- finger: pinky
|
|
||||||
pre: F floating
|
|
||||||
post: B
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: F floating
|
|
||||||
post: DB
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: F floating
|
|
||||||
post: DF
|
|
||||||
score: 2
|
|
||||||
- finger: pinky
|
|
||||||
pre: F floating
|
|
||||||
post: F
|
|
||||||
score: 2
|
|
||||||
|
|||||||
122
scorer.py
122
scorer.py
@ -15,7 +15,7 @@ class FingerTrick:
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Regrip:
|
class Grip:
|
||||||
finger: str
|
finger: str
|
||||||
pre: str
|
pre: str
|
||||||
post: str
|
post: str
|
||||||
@ -23,23 +23,66 @@ class Regrip:
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Config:
|
class Regrip:
|
||||||
finger_tricks: List[FingerTrick]
|
finger: str
|
||||||
|
start: str
|
||||||
|
end: str
|
||||||
|
score: float
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Finger:
|
||||||
|
name: str
|
||||||
|
default_score: int
|
||||||
|
home_grips: List[str]
|
||||||
|
grips: Dict[str, List[str]]
|
||||||
regrips: List[Regrip]
|
regrips: List[Regrip]
|
||||||
|
|
||||||
|
|
||||||
def home_grip() -> Dict[str, str]:
|
@dataclass
|
||||||
return {
|
class Config:
|
||||||
"index": "B", # this could also be BL
|
fingers: List[Finger]
|
||||||
"ring": "B",
|
finger_tricks: List[FingerTrick]
|
||||||
"pinky": "BD",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def load_config(file_path: str) -> Config:
|
@dataclass
|
||||||
|
class Definitions:
|
||||||
|
fingers: List[Finger]
|
||||||
|
finger_tricks: List[FingerTrick]
|
||||||
|
finger_regrips: List[Regrip]
|
||||||
|
|
||||||
|
|
||||||
|
def build_regrips_from_fingers(fingers: List[Finger]) -> List[Regrip]:
|
||||||
|
regrips = []
|
||||||
|
for finger in fingers:
|
||||||
|
finger_regrips = {}
|
||||||
|
for grip_set in finger.grips.values():
|
||||||
|
# reate a dict with distances of every two elements in a list
|
||||||
|
for i in range(len(grip_set)):
|
||||||
|
for j in range(len(grip_set)):
|
||||||
|
if i != j:
|
||||||
|
finger_regrips[(grip_set[i], grip_set[j])] = Regrip(
|
||||||
|
start=grip_set[i],
|
||||||
|
end=grip_set[j],
|
||||||
|
score=abs(j - i) * finger.default_score,
|
||||||
|
finger=finger.name,
|
||||||
|
)
|
||||||
|
for regrip in finger.regrips:
|
||||||
|
finger_regrips[(regrip.start, regrip.end)] = regrip
|
||||||
|
regrips.extend(finger_regrips.values())
|
||||||
|
|
||||||
|
return regrips
|
||||||
|
|
||||||
|
|
||||||
|
def load_definitions(file_path: str) -> Definitions:
|
||||||
with open(file_path, "r") as f:
|
with open(file_path, "r") as f:
|
||||||
data_dict = yaml.safe_load(f.read())
|
data_dict = yaml.safe_load(f.read())
|
||||||
return dacite.from_dict(data_class=Config, data=data_dict)
|
config = dacite.from_dict(data_class=Config, data=data_dict)
|
||||||
|
return Definitions(
|
||||||
|
fingers=config.fingers,
|
||||||
|
finger_tricks=config.finger_tricks,
|
||||||
|
finger_regrips=build_regrips_from_fingers(config.fingers),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def grip_correct(current_grip: Dict[str, str], required_grip: Dict[str, str]):
|
def grip_correct(current_grip: Dict[str, str], required_grip: Dict[str, str]):
|
||||||
@ -60,50 +103,69 @@ class FingerTrickWithRegrip:
|
|||||||
return score
|
return score
|
||||||
|
|
||||||
|
|
||||||
def calculate_finger_trick_regrips(
|
@dataclass
|
||||||
config: Config, finger_trick: FingerTrick, grip: Dict[str, str]
|
class Algorithm:
|
||||||
|
score: float
|
||||||
|
finger_tricks_with_regrips: List[FingerTrickWithRegrip]
|
||||||
|
|
||||||
|
|
||||||
|
def find_finger_trick_regrips(
|
||||||
|
regrips: List[Regrip], finger_trick: FingerTrick, grip: Dict[str, str]
|
||||||
) -> List[Regrip]:
|
) -> List[Regrip]:
|
||||||
regrips = []
|
alg_regrips = []
|
||||||
for finger in finger_trick.grip_pre.keys():
|
for finger in finger_trick.grip_pre.keys():
|
||||||
current_location = grip[finger]
|
current_location = grip[finger]
|
||||||
desired_location = finger_trick.grip_pre.get(finger)
|
desired_location = finger_trick.grip_pre.get(finger)
|
||||||
blacklisted_locations = finger_trick.grip_pre_blacklist.get(finger, [])
|
blacklisted_locations = finger_trick.grip_pre_blacklist.get(finger, [])
|
||||||
if current_location != desired_location:
|
if current_location != desired_location:
|
||||||
# TODO: check the minimal regrip?
|
# print("FINGA", finger)
|
||||||
regrip = next(
|
# print("CURRENT", current_location)
|
||||||
|
# print("DESIRED", desired_location)
|
||||||
|
# print("BLACK", blacklisted_locations)
|
||||||
|
# __import__("pprint").pprint(regrips)
|
||||||
|
alg_regrip = next(
|
||||||
(
|
(
|
||||||
regrip
|
regrip
|
||||||
for regrip in config.regrips
|
for regrip in regrips
|
||||||
if regrip.finger == finger
|
if regrip.finger == finger
|
||||||
and regrip.pre == current_location
|
and regrip.start == current_location
|
||||||
and regrip.post == desired_location
|
and regrip.end == desired_location
|
||||||
and regrip.pre not in blacklisted_locations
|
and regrip.start not in blacklisted_locations
|
||||||
),
|
),
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
if regrip:
|
if alg_regrip:
|
||||||
regrips.append(regrip)
|
alg_regrips.append(alg_regrip)
|
||||||
return regrips
|
return alg_regrips
|
||||||
|
|
||||||
|
|
||||||
|
def generate_home_grip(fingers: List[Finger]) -> Dict[str, str]:
|
||||||
|
# TODO: make this smarter
|
||||||
|
home_grip = {}
|
||||||
|
for finger in fingers:
|
||||||
|
home_grip[finger.name] = finger.home_grips[0]
|
||||||
|
return home_grip
|
||||||
|
|
||||||
|
|
||||||
def generate_finger_tricks(
|
def generate_finger_tricks(
|
||||||
config: Config, moves: List[str]
|
definitions: Definitions, moves: List[str]
|
||||||
) -> List[FingerTrickWithRegrip]:
|
) -> List[FingerTrickWithRegrip]:
|
||||||
grip = home_grip()
|
grip = generate_home_grip(definitions.fingers)
|
||||||
alg: List[FingerTrickWithRegrip] = []
|
alg: List[FingerTrickWithRegrip] = []
|
||||||
for move in moves:
|
for move in moves:
|
||||||
# print("current grip:", grip)
|
# print("current grip:", grip)
|
||||||
# prit("current move:", move)
|
# prit("current move:", move)
|
||||||
possible_finger_tricks = [
|
possible_finger_tricks = [
|
||||||
finger_trick
|
finger_trick
|
||||||
for finger_trick in config.finger_tricks
|
for finger_trick in definitions.finger_tricks
|
||||||
if move == finger_trick.move
|
if move == finger_trick.move
|
||||||
]
|
]
|
||||||
# print("possible finger tricks:", possible_finger_tricks)
|
# print("possible finger tricks:", possible_finger_tricks)
|
||||||
finger_tricks_with_regrips = [
|
finger_tricks_with_regrips = [
|
||||||
FingerTrickWithRegrip(
|
FingerTrickWithRegrip(
|
||||||
finger_trick=finger_trick,
|
finger_trick=finger_trick,
|
||||||
regrips=calculate_finger_trick_regrips(config, finger_trick, grip),
|
regrips=find_finger_trick_regrips(
|
||||||
|
definitions.finger_regrips, finger_trick, grip
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for finger_trick in possible_finger_tricks
|
for finger_trick in possible_finger_tricks
|
||||||
]
|
]
|
||||||
@ -113,7 +175,7 @@ def generate_finger_tricks(
|
|||||||
# print("best finger trick:", best_finger_trick)
|
# print("best finger trick:", best_finger_trick)
|
||||||
# apply regrips
|
# apply regrips
|
||||||
for regrip in best_finger_trick.regrips:
|
for regrip in best_finger_trick.regrips:
|
||||||
grip[regrip.finger] = regrip.post
|
grip[regrip.finger] = regrip.end
|
||||||
# apply move
|
# apply move
|
||||||
grip.update(best_finger_trick.finger_trick.grip_post)
|
grip.update(best_finger_trick.finger_trick.grip_post)
|
||||||
alg.append(best_finger_trick)
|
alg.append(best_finger_trick)
|
||||||
@ -131,7 +193,7 @@ def build_pretty_string_from_finger_tricks_with_regrips(
|
|||||||
|
|
||||||
for finger_trick_with_regrips in finger_tricks_with_regrips:
|
for finger_trick_with_regrips in finger_tricks_with_regrips:
|
||||||
for regrip in finger_trick_with_regrips.regrips:
|
for regrip in finger_trick_with_regrips.regrips:
|
||||||
elems.append(f"regrip {regrip.finger} from {regrip.pre} to {regrip.post}")
|
elems.append(f"regrip {regrip.finger} from {regrip.start} to {regrip.end}")
|
||||||
elems.append(finger_trick_with_regrips.finger_trick.name)
|
elems.append(finger_trick_with_regrips.finger_trick.name)
|
||||||
|
|
||||||
return elems
|
return elems
|
||||||
|
|||||||
Reference in New Issue
Block a user