From 5b972eb737af12bf4458b1b733f5caa0a40d129a Mon Sep 17 00:00:00 2001 From: DomNomNomVR <108088541+DomNomNomVR@users.noreply.github.com> Date: Tue, 15 Apr 2025 08:25:14 +1200 Subject: [PATCH] fix clockwise_twist --- skewb_solver.py | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/skewb_solver.py b/skewb_solver.py index 1d76e4b..4d40faf 100644 --- a/skewb_solver.py +++ b/skewb_solver.py @@ -161,36 +161,43 @@ def test_rotation_permutations(p: CornerRotPermutation): MID_DIR_INCREMENT: dict[MidRotState, MidRotState] = {"Y": "O", "R": "Y", "O": "R"} -def clockwise_twist(s: Skewb, twist: Axis) -> Skewb: - rot_before, rot_after = {"G": (0, 0), "O": (3, 1), "B": (2, 2), "R": (1, 3)}[twist] +def clockwise_twist(s: Skewb, axis: Axis) -> Skewb: + """Applies a clockwise twist to the axis. + + Coordinate frame is define as follows: + - axis goes through the `top` of a solved cube of a given color + - the axis-top is on top and faces away from the observer twisting it, + - clockwise is twisting the bottom when looking up from diagonally-below the skewb + """ + rot_before, rot_after = {"G": (0, 0), "O": (3, 1), "B": (2, 2), "R": (1, 3)}[axis] for _ in range(rot_before): s = rotate_everything_about_W(s) s = Skewb( top=( s.top[0], s.top[1], - Corner((c := s.bot[3]).col, BOT_LEFT_TO_TOP[c.rot]), + Corner((c := s.bot[0]).col, BOT_LEFT_TO_TOP[c.rot]), s.top[3], ), bot=( - s.bot[0], + Corner((c := s.bot[2]).col, BOT_RIGHT_TO_BOT_LEFT[c.rot]), + s.bot[1], Corner((c := s.top[2]).col, TOP_TO_BOT_RIGHT[c.rot]), - Corner((c := s.bot[2]).col, ROTATE_CORNER_CLOCKWISE[c.rot]), - Corner((c := s.bot[1]).col, BOT_RIGHT_TO_BOT_LEFT[c.rot]), + Corner((c := s.bot[3]).col, ROTATE_CORNER_CLOCKWISE[c.rot]), ), mids=( s.mids[0], + s.mids[1], Middle( - (m := s.mids[2]).col, + (m := s.mids[3]).col, "Y" if m.col == "Y" else MID_DIR_INCREMENT[m.rot], ), Middle( (m := s.mids[4]).col, "Y" if m.col == "Y" else MID_DIR_INCREMENT[m.rot], ), - s.mids[3], Middle( - (m := s.mids[1]).col, + (m := s.mids[2]).col, "Y" if m.col == "Y" else ("O" if m.rot == "Y" else "R"), ), ), @@ -200,6 +207,22 @@ def clockwise_twist(s: Skewb, twist: Axis) -> Skewb: return s +@pytest.mark.parametrize( + "axis, want", + [ + ( + "O", + Skewb( + top=(G0, O0, B0, O2), bot=(G1, R2, B0, R2), mids=(YY, OY, BY, GR, RR) + ), + ) + ], +) +def test_clockwise_twist_from_solved(axis: Axis, want: Skewb): + want.assert_valid() + assert clockwise_twist(solved_skewb, axis) == want + + def anticlockwise_twist(s: Skewb, twist: Axis) -> Skewb: return clockwise_twist(clockwise_twist(s, twist), twist)