From 473adc64b8cf5a12efe60898df832905296f79dd Mon Sep 17 00:00:00 2001 From: omri Date: Sat, 24 Aug 2024 18:11:59 +0300 Subject: [PATCH] add blacklisting --- __main__.py | 13 ++++--- alg_trainer.py | 25 ++++++++++++ moves.yaml | 102 +++++++++++++++++++++++++++++++------------------ scorer.py | 10 ++++- 4 files changed, 106 insertions(+), 44 deletions(-) create mode 100644 alg_trainer.py diff --git a/__main__.py b/__main__.py index 1309361..5b7d3a1 100644 --- a/__main__.py +++ b/__main__.py @@ -38,7 +38,8 @@ def get_first_n_from_generator(gen: Generator[Any, None, Any], n: int) -> List[A try: while len(results) < n: item = next(gen) - results.append(item) + if item not in results: + results.append(item) except StopIteration: pass return results @@ -66,12 +67,12 @@ def main(): # 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) data = defaultdict(list) - eolrb_states, n_states = eolrb_states_generator( - list(EOLROrientation), EOLR_PERMUTATIONS - ) # 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): print( 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: - f.write(json.dumps(data)) + f.write(json.dumps(data, indent=4)) if __name__ == "__main__": diff --git a/alg_trainer.py b/alg_trainer.py new file mode 100644 index 0000000..f06efb9 --- /dev/null +++ b/alg_trainer.py @@ -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() diff --git a/moves.yaml b/moves.yaml index 644f41a..3e6e11c 100644 --- a/moves.yaml +++ b/moves.yaml @@ -3,44 +3,50 @@ finger_tricks: - name: "U push" move: "U" grip_pre: - index: BL + index: LB grip_post: - index: B + index: BR + grip_pre_blacklist: {} score: 5 - name: "U flick" move: "U" grip_pre: index: F grip_post: - index: BL + index: LB + grip_pre_blacklist: {} score: 4 - name: "U' push" move: "U'" grip_pre: - index: FL + index: LF grip_post: index: F + grip_pre_blacklist: {} score: 5 - name: "U' flick" move: "U'" grip_pre: - index: B + index: BL grip_post: - index: FL + index: LF + grip_pre_blacklist: {} score: 3 - name: "U2 feido" move: "U2" grip_pre: - index: B + index: BL grip_post: index: F + grip_pre_blacklist: {} score: 5 - name: "U2 double flick" move: "U2" grip_pre: - index: B + index: BL grip_post: - index: FL + index: LF + grip_pre_blacklist: {} score: 6 - name: "U2' double flick" move: "U2" @@ -48,13 +54,15 @@ finger_tricks: index: F grip_post: index: BL + grip_pre_blacklist: {} score: 9 - name: "U2 beido" move: "U2" grip_pre: index: F grip_post: - index: B + index: BR + grip_pre_blacklist: {} score: 5 - name: "M' ring flick" move: "M'" @@ -62,13 +70,18 @@ finger_tricks: ring: B grip_post: ring: DF + grip_pre_blacklist: {} score: 3 - name: "M' pinky flick" move: "M'" + # I can't do M' after finishing beido grip_pre: pinky: B grip_post: pinky: F floating + grip_pre_blacklist: + index: + - BL score: 6 - name: "M push" move: "M" @@ -76,6 +89,7 @@ finger_tricks: pinky: F grip_post: pinky: DB + grip_pre_blacklist: {} score: 6 - name: "M2 double flick" move: "M2" @@ -85,56 +99,70 @@ finger_tricks: grip_post: pinky: F floating ring: DB + grip_pre_blacklist: {} 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: 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 score: 1 - finger: index - pre: B - post: FL - score: 2 + pre: LB + post: LF + score: 1 - finger: index - pre: B + pre: LB post: F score: 2 - finger: index - pre: BL - post: B - score: 1 - - finger: index - pre: BL - post: FL - score: 1 - - finger: index - pre: BL - post: F + pre: LF + post: BR score: 2 - finger: index - pre: FL - post: B - score: 2 - - finger: index - pre: FL - post: BL + pre: LF + post: LB score: 1 - finger: index - pre: FL + pre: LF post: F score: 1 - - finger: index - pre: F - post: B - score: 2 - finger: index pre: F post: BL score: 2 - finger: index pre: F - post: FL + post: LB + score: 2 + - finger: index + pre: F + post: LF score: 1 - finger: ring pre: B diff --git a/scorer.py b/scorer.py index 91b4cde..ecaa712 100644 --- a/scorer.py +++ b/scorer.py @@ -8,6 +8,7 @@ from dataclasses import dataclass class FingerTrick: name: str move: str + grip_pre_blacklist: Dict[str, List[str]] grip_pre: Dict[str, str] grip_post: Dict[str, str] score: float @@ -66,7 +67,9 @@ def calculate_finger_trick_regrips( for finger in finger_trick.grip_pre.keys(): current_location = grip[finger] desired_location = finger_trick.grip_pre.get(finger) + blacklisted_locations = finger_trick.grip_pre_blacklist.get(finger, []) if current_location != desired_location: + # TODO: check the minimal regrip? regrip = next( ( regrip @@ -74,6 +77,7 @@ def calculate_finger_trick_regrips( if regrip.finger == finger and regrip.pre == current_location and regrip.post == desired_location + and regrip.pre not in blacklisted_locations ), None, ) @@ -86,7 +90,7 @@ def generate_finger_tricks( config: Config, moves: List[str] ) -> List[FingerTrickWithRegrip]: grip = home_grip() - alg = [] + alg: List[FingerTrickWithRegrip] = [] for move in moves: # print("current grip:", grip) # prit("current move:", move) @@ -113,6 +117,10 @@ def generate_finger_tricks( # apply move grip.update(best_finger_trick.finger_trick.grip_post) alg.append(best_finger_trick) + + # TODO: think about this + # don't count the first regrip + alg[0].finger_trick.score = 0 return alg