add blacklisting

This commit is contained in:
2024-08-24 18:11:59 +03:00
parent f012c0536f
commit 473adc64b8
4 changed files with 106 additions and 44 deletions

View File

@ -38,7 +38,8 @@ def get_first_n_from_generator(gen: Generator[Any, None, Any], n: int) -> List[A
try: try:
while len(results) < n: while len(results) < n:
item = next(gen) item = next(gen)
results.append(item) if item not in results:
results.append(item)
except StopIteration: except StopIteration:
pass pass
return results return results
@ -66,12 +67,12 @@ def main():
# TODO: make this function a method of an object that contains a list of finger tricks # TODO: make this function a method of an object that contains a list of finger tricks
score_func = lambda solution: sum(ft.score() for ft in solution.finger_tricks) score_func = lambda solution: sum(ft.score() for ft in solution.finger_tricks)
data = defaultdict(list) data = defaultdict(list)
eolrb_states, n_states = eolrb_states_generator(
list(EOLROrientation), EOLR_PERMUTATIONS
)
# eolrb_states, n_states = eolrb_states_generator( # eolrb_states, n_states = eolrb_states_generator(
# [EOLROrientation.Solved], [EOLRPermutation(UR="UR", UL="UL")] # list(EOLROrientation), EOLR_PERMUTATIONS
# ) # )
eolrb_states, n_states = eolrb_states_generator(
[EOLROrientation.OneOne], EOLR_PERMUTATIONS
)
for i, (eolrb_cube, ori, perm, pre_auf) in enumerate(eolrb_states): for i, (eolrb_cube, ori, perm, pre_auf) in enumerate(eolrb_states):
print( print(
f"generating algs for {ori.name} (UR in {perm.UR}, UL in {perm.UL}, pre AUF {pre_auf}) ({i}/{n_states})" f"generating algs for {ori.name} (UR in {perm.UR}, UL in {perm.UL}, pre AUF {pre_auf}) ({i}/{n_states})"
@ -121,7 +122,7 @@ def main():
} }
) )
with open("output.json", "w") as f: with open("output.json", "w") as f:
f.write(json.dumps(data)) f.write(json.dumps(data, indent=4))
if __name__ == "__main__": if __name__ == "__main__":

25
alg_trainer.py Normal file
View File

@ -0,0 +1,25 @@
import json
def main():
with open("./output.json") as f:
data = json.loads(f.read())
covered_cases = set()
for case, scrambles in data.items():
if not scrambles:
continue
scramble = scrambles[0]
if scramble["raw_alg"] in covered_cases:
continue
if scramble["stm"] > 7:
continue
if case.startswith("Solved"):
continue
if not case.startswith("OneOne"):
continue
print(f'{case}: "{scramble['alg']}"')
covered_cases.add(scramble["raw_alg"])
if __name__ == "__main__":
main()

View File

@ -3,44 +3,50 @@ finger_tricks:
- name: "U push" - name: "U push"
move: "U" move: "U"
grip_pre: grip_pre:
index: BL index: LB
grip_post: grip_post:
index: B index: BR
grip_pre_blacklist: {}
score: 5 score: 5
- name: "U flick" - name: "U flick"
move: "U" move: "U"
grip_pre: grip_pre:
index: F index: F
grip_post: grip_post:
index: BL index: LB
grip_pre_blacklist: {}
score: 4 score: 4
- name: "U' push" - name: "U' push"
move: "U'" move: "U'"
grip_pre: grip_pre:
index: FL index: LF
grip_post: grip_post:
index: F index: F
grip_pre_blacklist: {}
score: 5 score: 5
- name: "U' flick" - name: "U' flick"
move: "U'" move: "U'"
grip_pre: grip_pre:
index: B index: BL
grip_post: grip_post:
index: FL index: LF
grip_pre_blacklist: {}
score: 3 score: 3
- name: "U2 feido" - name: "U2 feido"
move: "U2" move: "U2"
grip_pre: grip_pre:
index: B index: BL
grip_post: grip_post:
index: F index: F
grip_pre_blacklist: {}
score: 5 score: 5
- name: "U2 double flick" - name: "U2 double flick"
move: "U2" move: "U2"
grip_pre: grip_pre:
index: B index: BL
grip_post: grip_post:
index: FL index: LF
grip_pre_blacklist: {}
score: 6 score: 6
- name: "U2' double flick" - name: "U2' double flick"
move: "U2" move: "U2"
@ -48,13 +54,15 @@ finger_tricks:
index: F index: F
grip_post: grip_post:
index: BL index: BL
grip_pre_blacklist: {}
score: 9 score: 9
- name: "U2 beido" - name: "U2 beido"
move: "U2" move: "U2"
grip_pre: grip_pre:
index: F index: F
grip_post: grip_post:
index: B index: BR
grip_pre_blacklist: {}
score: 5 score: 5
- name: "M' ring flick" - name: "M' ring flick"
move: "M'" move: "M'"
@ -62,13 +70,18 @@ finger_tricks:
ring: B ring: B
grip_post: grip_post:
ring: DF ring: DF
grip_pre_blacklist: {}
score: 3 score: 3
- name: "M' pinky flick" - name: "M' pinky flick"
move: "M'" move: "M'"
# I can't do M' after finishing beido
grip_pre: grip_pre:
pinky: B pinky: B
grip_post: grip_post:
pinky: F floating pinky: F floating
grip_pre_blacklist:
index:
- BL
score: 6 score: 6
- name: "M push" - name: "M push"
move: "M" move: "M"
@ -76,6 +89,7 @@ finger_tricks:
pinky: F pinky: F
grip_post: grip_post:
pinky: DB pinky: DB
grip_pre_blacklist: {}
score: 6 score: 6
- name: "M2 double flick" - name: "M2 double flick"
move: "M2" move: "M2"
@ -85,56 +99,70 @@ finger_tricks:
grip_post: grip_post:
pinky: F floating pinky: F floating
ring: DB ring: DB
grip_pre_blacklist: {}
score: 7 score: 7
regrips: regrips:
# TODO: rethink this format? # TODO: rethink this format?
# TODO: be able to write all possible grips for a finger and score JUST adj regrips
- finger: index - finger: index
pre: B 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 post: BL
score: 1 score: 1
- finger: index - finger: index
pre: B pre: LB
post: FL post: LF
score: 2 score: 1
- finger: index - finger: index
pre: B pre: LB
post: F post: F
score: 2 score: 2
- finger: index - finger: index
pre: BL pre: LF
post: B post: BR
score: 1
- finger: index
pre: BL
post: FL
score: 1
- finger: index
pre: BL
post: F
score: 2 score: 2
- finger: index - finger: index
pre: FL pre: LF
post: B post: LB
score: 2
- finger: index
pre: FL
post: BL
score: 1 score: 1
- finger: index - finger: index
pre: FL pre: LF
post: F post: F
score: 1 score: 1
- finger: index
pre: F
post: B
score: 2
- finger: index - finger: index
pre: F pre: F
post: BL post: BL
score: 2 score: 2
- finger: index - finger: index
pre: F pre: F
post: FL post: LB
score: 2
- finger: index
pre: F
post: LF
score: 1 score: 1
- finger: ring - finger: ring
pre: B pre: B

View File

@ -8,6 +8,7 @@ from dataclasses import dataclass
class FingerTrick: class FingerTrick:
name: str name: str
move: str move: str
grip_pre_blacklist: Dict[str, List[str]]
grip_pre: Dict[str, str] grip_pre: Dict[str, str]
grip_post: Dict[str, str] grip_post: Dict[str, str]
score: float score: float
@ -66,7 +67,9 @@ def calculate_finger_trick_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, [])
if current_location != desired_location: if current_location != desired_location:
# TODO: check the minimal regrip?
regrip = next( regrip = next(
( (
regrip regrip
@ -74,6 +77,7 @@ def calculate_finger_trick_regrips(
if regrip.finger == finger if regrip.finger == finger
and regrip.pre == current_location and regrip.pre == current_location
and regrip.post == desired_location and regrip.post == desired_location
and regrip.pre not in blacklisted_locations
), ),
None, None,
) )
@ -86,7 +90,7 @@ def generate_finger_tricks(
config: Config, moves: List[str] config: Config, moves: List[str]
) -> List[FingerTrickWithRegrip]: ) -> List[FingerTrickWithRegrip]:
grip = home_grip() grip = home_grip()
alg = [] 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)
@ -113,6 +117,10 @@ def generate_finger_tricks(
# 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)
# TODO: think about this
# don't count the first regrip
alg[0].finger_trick.score = 0
return alg return alg