- Cubing Vocabulary Teacher – link to tool in Google Colab
- How I learnt across the duration of this project:
- Across my coding project, I learnt the importance of defining functions so they are easy to re-use later in you code. At the start, I was planning on coding a simple 3×3 (Rubik’s cube) scramble move generator which exist already, and instead shifted to my underlying but exisiting unique feature of teaching HOW to understand and follow cubing vocabulary. This is an innovative solution to a problem beginners face and is not addressed in other tools. I combined my knowledge from Entrepreneurship class with my cubing and coding skills to create this tool that will hopefully help absolute beginners with no prior knowledge learn how to turn a cube with letter directions.
- Flowchart:
- Explanation:
- I had a coding assignment at school, where my goal was to demonstrate my knowledge of python code, and try to create an innovative tool. I decided to combine my knowledge of cubing with python to develop a tool for cubers. Initially it was developing a scrambles for a 3×3 that doesn’t give redundant moves. Then it developed into a tool that teaches beginner cubers HOW to read cubing moves (formally called notation), and provides a tool to practice this fundamental skill further integrated with a simple way to check the user’s learning.
- The tool “Cubing Vocabulary Teacher” is designed to address the challenges of the beginner cubers. It does not require any cubing knowledge prior to using this tool. It starts to teach cubing vocabulary to the beginners in step wise fashion with visual cues. The aim is to get them familiarised with the cubing notations. As a next step, the tool allows the users to practice their cubing notation.
- Once they learn the cubing notations, they can make of use the available cubing resources online to advance their skills. We also provide a way to check if the user can do the moves properly. At the moment, the caveat in the field is that nobody explains the basic vocabulary to beginner cubers. This tool is to bridge the knowledge gap and help new cubers on their journey.
Code summary – how it works and my logic in developing it
import random
I knew from the start that I’d need the random library which is a built in python function that randomly selects something (a cubing move in my case) from a dictionary that the programmer provides.
def get_yes_no(prompt):
while True:
response = input(prompt).strip().lower()
if response in ["yes", "y"]:
return True
elif response in ["no", "n"]:
return False
else:
print("Please enter 'yes' or 'no'.")
In my code, there were many stages where I needed to ask the user for yes or no. It was simple enough to define this function and was worth it for many different parts of my program.
def get_choice(prompt, valid_choices):
while True:
choice = input(prompt).strip().upper()
if choice in valid_choices:
return choice
else:
print(f"Invalid choice. Please choose from: {', '.join(valid_choices)}")
This code looks more complex, but all it does is ask the user for a choice and check if it is valid. If it’s not valid – it will tell the user and keep asking until the computer does. Another part of this function is that it breaks down the users response to lowercase and into lowercase to help interpret all cases of inputs. Regardless if the user input “Yes”, “yEs” or ” yes”, the code will work because before processing the code, the computer will remove all spaces before and after the word and making all of the text lowercase. This lets it check what the user actually meant by simplifying their response to the simple yes or no’s the computer can understand.
def show_orientation():
print("\n🧑🏫 Hold the cube like this:")
print(" - White face is UP")
print(" - Green face is FACING YOU (Front)")
print("\nCube Face Map:")
print(" [U]")
print(" [L] [F] [R] [B]")
print(" [D]")
print("U = Up, D = Down, F = Front, B = Back, L = Left, R = Right")
print()
The explanation for this is very simple. It is simply a function that will be putting the text inside the quotation marks on the user’s screen. The text that will be displayed gives a visual representation of the cube, and explains where each face (side of the cube – top, bottom , etc) is. Furthermore, it tells you the orientation to hold your cube (helpful if doing scrambling from advanced tools).
def show_visual_clue(face, direction):
arrows = {
"clockwise": "↻",
"counterclockwise": "↺",
"180": "⟲⟳"
}
print(f"\n🧩 Visual Clue for Move: {face}{direction}")
if direction == "":
print(f"Turn the {face} face 90° clockwise {arrows['clockwise']}")
elif direction == "'":
print(f"Turn the {face} face 90° counterclockwise {arrows['counterclockwise']}")
elif direction == "2":
print(f"Turn the {face} face 180° {arrows['180']}")
print()
Here I created another function that will visually show the user how to turn the cube depending on the type of move they have to do using arrows. These arrows are either clockwise, anticlockwise, or a double turn which can be done in either direction (clockwise or anticlockwise – same result). So this function will print the specific instructions per the user’s move when it is called upon.
def explain_move(move, variation, move_dict):
base = move
modifier = variation.replace(move, "")
print("\nExplanation:")
if modifier == "":
print(f"{move}: Turn the {move_dict[move]} 90 degrees clockwise.")
elif modifier == "'":
print(f"{move}': Turn the {move_dict[move]} 90 degrees counterclockwise.")
elif modifier == "2":
print(f"{move}2: Turn the {move_dict[move]} 180 degrees in either direction.")
This code simply teaches the user how to do a cubing move. This isn’t the same as the show_orientation function that will print the same thing repeatedly. The function here reads what the user wrote and delivers the moves accordingly depending on 2 factors (letter and modification following it). To eliminate the boring work of typing out the instructions for each move manually and to eliminate the possibility of a human error (eg. typo), I created this function to read what the user wrote and give them instructions based on the letter (R, U, etc) and modification following the letter (inverse, none, double turn).
show_visual_clue(base, modifier)
This line of code calls the function that teaches the user how to hold the cube and showing which face is which. The parameters it checks for are the base move (simple letter), and the modifier (nothing, inverse, double turn).
def learn_moves():
while True:
show_orientation()
move_type = get_choice("Choose move type to learn (basic/advanced): ", ["BASIC", "ADVANCED"])
#defining basic moves
if move_type == "BASIC":
basic_moves = {
"U": "Up face (Top Layer)",
"D": "Down face (Bottom Layer)",
"L": "Left face",
"R": "Right face",
"F": "Front face",
"B": "Back face"
}
This function asks user to choose between learning basic or advanced moves. Interestingly, I also used a previously defined function, “get_choice”, to ask the user which move set they wanted to learn. If the user asks to learn the basic set of moves, I print out a guide for the user which helps them understand which move they would like help learning. They have a choice between advanced and basic. If they know they want to learn the top layer, they can read the list provided, and understand that it is a “U move” they want to learn.
print("\nBasic Moves:")
for key, val in basic_moves.items():
print(f"{key}: {val}")
move = get_choice("Which basic move would you like to learn? (U/D/L/R/F/B): ", basic_moves.keys())
direction = get_choice(
f"Choose the variation of {move} (e.g., {move}, {move}', {move}2): ",
[move, move + "'", move + "2"]
)
explain_move(move, direction, basic_moves)
This code prints the basic move definitions on a new line. The second print function prints the basic letter moves with no modifications, and then prints the value (what it means – defined in the basic move list) after the colon between key and val. Then the computer gets the user choice (using our custom function) on which of the basic moves they would like to learn. After that the next step is to get the user choice on the specific modification of the move they’d like to learn (whether it has an apostrophe after it – is an inverse move, or a 2 after it – a double turn). The next line of code is to call the function explain_move and let it do its work.
elif move_type == "ADVANCED":
advanced_moves = {
"M": "Middle slice (between L and R)",
"E": "Equatorial slice (between U and D)",
"S": "Standing slice (between F and B)"
}
In the case the user asked to learn advanced moves when the program gave it a choice between basic and advanced, a variable is defined where there is a list for where the layers of the advanced moves are.
print("\nAdvanced Slice Moves:")
for key, val in advanced_moves.items():
print(f"{key}: {val}")
move = get_choice("Which advanced move would you like to learn? (M/E/S): ", advanced_moves.keys())
direction = get_choice(
f"Choose the variation of {move} (e.g., {move}, {move}', {move}2): ",
[move, move + "'", move + "2"]
)
explain_move(move, direction, advanced_moves)
again = get_yes_no("\nDo you want to learn another move? (yes/no): ")
if not again:
break
On a new line, we print the advanced moves variable (shows where the advanced layers are). Again, just like the basic moves, we are printing the advanced cubing letter (the key) and then the text that explains it (the val). This is all from the variable we defined for the advanced moves earlier. We then ask the user which advanced move it wants to learn, and once we have that, we ask which modification (e.g. double turn) they want to learn. Then we use the explain_move function that we defined earlier, to explain the move to them based on their input here. Now that they have learn this move, we ask them whether they are interested in learning another move. If they say no, we will break out of the learning cycle.
def practice_scramble():
cubing_moves = ["R", "R'", "R2", "L", "L'", "L2",
"B", "B'", "B2", "F", "F'", "F2",
"U", "U'", "U2", "D", "D'", "D2"]
last_axis = None
scramble = []
n = 1
I know it’s standard practise to define all the variables at the start of the code, but this is the code for a whole new task. This is to help the user practice their cubing moves so it is in this new section of code. Now getting into the code, I defined all the possible cubing moves that could be used in a scramble. It is important to note that although the advanced moves are not used for scrambling, they are used when memorising algorithms (applies to higher level cubers). The reason I have the axis is a bit complicated to explain, but to put it simply, I wanted to avoid redundancy in my scrambles. Having consecutive moves on the same axis could even cause a situation where you do a turn and then the next move asks you to promptly undo that. That’s why I avoided having this situation altogether – credit to gemini for the idea of making axis’s to circumvent this issue. I also have the blank square brackets for the scramble, because I wanted to print the moves one line instead of having a new line for every move generated (discovered through troubleshooting). N is being used as a counter for how many moves are being generated.
while n < 25:
random_move = random.choice(cubing_moves)
#defining the axis's
if random_move[0] in "RL":
axis = "RL"
elif random_move[0] in "BF":
axis = "BF"
else:
axis = "UD"
Once the program generates 25 valid moves, n will hit 25 and then the program will stop. The random_move selects a random letter from my list of cubing moves used in a scramble. After that we look at the first letter(index 0) of the user’s move they want to learn and based on which letter it contains, it will be grouped into an axis. A quick explanation, if two faces of the cube can turn the same direction, they are on the same axis.
if axis != last_axis:
scramble.append(random_move)
last_axis = axis
n += 1
If the axis is not the same as the axis of the last valid move, we can add it to the list of random_move. After that I increased n by 1, because if it passed the axis requirement or parameter, it is a valid move and the counter should increase.
print("\n👉 Step 1: Scramble your cube with this sequence:")
print(" ".join(scramble))
input("\nPress Enter once you finish scrambling...")
#reverse of cube moves for them to check if user followed along correctly
reverse_solution = []
for move in reversed(scramble):
if move.endswith("2"):
reverse_solution.append(move)
elif move.endswith("'"):
reverse_solution.append(move[0])
else:
reverse_solution.append(move[0] + "'")
On a new line we are telling the user to scramble their cube with our sequence (helping them practice). Then the program shows the user the scramble we have made. After that, the user is asked to press enter once they finish scrambling. Now we make a blank list where we will add a move one by one for reversing their scramble to see if they followed their moves correctly. The program checks what modifier or ending the move in the list “scramble” has, then depending on that, the reverse move list is generated. This is what I’m telling the computer to think: If the move ends in a 2, it stays as is and goes into the list, if it has an apostrophe, it needs a clockwise move, and if it is a regular move, it needs an anticlockwise move to create the reverse scramble.
midpoint = len(reverse_solution) // 2
step1 = reverse_solution[:midpoint]
step2 = reverse_solution[midpoint:]
print("\n👉 Step 2: Solve your cube in two phases.")
print("Phase 1 moves:", " ".join(step1))
input("Perform these moves, then press Enter...")
print("Phase 2 moves:", " ".join(step2))
input("Perform these moves, then press Enter...")
print("\n🎉 If you made no mistakes, your cube is solved!")
I decided to print out the reverse solution in two parts, because a list of 25 might be intimidating. I achieved this by finding the “midpoint”, half the length of the moves, and then putting them into two variables. After that it is a bunch of print statements that tells the user, their cube will be solved in 2 phases as they follow the moves and click enter. If they finish all of these with no mistakes, their cube should end up solved.
def main():
print("🧠 Welcome to Cubing Vocabulary & Practice Trainer!")
#checking conditions on what user wants to do with this tool
while True:
print("\nChoose an option:")
option1 = get_yes_no("Option 1: Do you want to learn cubing vocabulary? (yes/no): ")
option2 = get_yes_no("Option 2: Would you like to practice your cubing vocabulary with a scramble? (yes/no): ")
#subfunctions are called "learn_moves" or "practice_scramble"
if option1:
learn_moves()
if option2:
practice_scramble()
if not option1 and not option2:
print("\nThanks for cubing today! Goodbye 👋")
break
if __name__ == "__main__":
main()
This is the final segment of code. This is the main section, and to start off the user interface, I get the computer to print a welcome message that tells the user what this tool does. After this, I use some functions to figure out what exactly the user wants out of this tool. Learn moves and check cubing vocabulary are the two options for the user through the two questions the program asks. Depending on what the user wants, the computer will find the function that defines what it needs to do, and will help the user. If the user answers no to both questions (doesn’t want to learn, or use the tool to practice moves), I get the computer to display a goodbye message and the program ends.
- Demo of the running code:
Transcript of AI interaction:
- Chat:
- Me: I have a school assignment on coding, where I should make a flowchart then code with variables, conditional statements, defined functions, User-centred design – with a user interface that is friendly and easy to navigate (not necessarily a GUI), and good code commenting. So it has to be python, and i have a little prior experience with python. The project I have in mind is developing 3×3 scrambles for cubers.
- Gemini:
That sounds like a great project for your school assignment! Creating a 3×3 scrambler in Python will allow you to demonstrate your understanding of several key programming concepts. Here’s a breakdown of how you can approach this, including the flowchart, code structure, and user-centered design elements.
Flowchart
A flowchart is a visual representation of the steps in your program. Here’s a possible flowchart for your 3×3 scrambler.
Start: The program begins.
Display Welcome Message: Show a friendly message to the user explaining what the program does.
Define Moves: Create a list or a dictionary of all possible moves for a 3×3 cube (e.g., R, L, U, D, F, B).
Prompt User: Ask the user how long they want the scramble to be.
Get User Input: Read the user’s input for the desired scramble length.
Validate Input: Check if the input is a valid number. If not, go back to step 4.
Generate Scramble:
Initialize an empty list to store the scramble.
Loop for the number of times specified by the user’s input.
Inside the loop:
Randomly select a move from your list of moves.
Randomly select a modifier (e.g., ‘ ‘ for a single turn, ”’ for an inverse turn, ‘2’ for a double turn).
Combine the move and the modifier.
Check for invalid consecutive moves (e.g., R R’ or R R2). If an invalid sequence is generated, re-randomize.
Add the valid move to your scramble list.
Display Scramble: Print the generated scramble to the user.
Ask to Repeat: Ask the user if they want to generate another scramble.
Get User Input: Read the user’s response.
Check Response: If the user says ‘yes’ or ‘y’, go back to step 4.
Display Goodbye Message: If the user says ‘no’ or ‘n’, display a friendly farewell message.
End: The program terminates.
Python Code Structure
Here’s a skeleton of the Python code with the required elements.
Python - #——————————————————————————- # File: 3x3_scrambler.py # Author: [Your Name] # Date: [Current Date] # # Description: This program generates random 3×3 cube scrambles of a user- # defined length. It includes a user-friendly interface, # error handling, and well-documented code. #——————————————————————————- import random # — Global Variables and Constants — # Define the possible moves and their modifiers CUBE_MOVES = [“R”, “L”, “U”, “D”, “F”, “B”] MODIFIERS = [“”, “‘”, “2”] # — Functions — def display_welcome_message(): “”” Displays a welcome message and explains the program’s purpose. This is part of the User-Centered Design. “”” print(“————————————————–“) print(“Welcome to the 3×3 Cube Scramble Generator!”) print(“This program creates a random scramble of any length you choose.”) print(“————————————————–\n”) def get_scramble_length(): “”” Prompts the user for the desired scramble length and validates the input. Returns a valid integer. “”” while True: try: length_input = input(“Please enter the desired scramble length (e.g., 20): “) length = int(length_input) if length > 0: return length else: print(“Length must be a positive number. Please try again.”) except ValueError: print(“Invalid input. Please enter a whole number.”) def generate_scramble(length): “”” Generates a list of valid 3×3 scramble moves. Args: length (int): The number of moves in the scramble. Returns: list: A list of strings, where each string is a valid move (e.g., “R’”). “”” scramble = [] last_move_base = “” while len(scramble) < length: # Select a random move from the list move = random.choice(CUBE_MOVES) # Ensure the new move is not the same as the last one’s base move if move == last_move_base: continue # Select a random modifier modifier = random.choice(MODIFIERS) # Combine them and add to the scramble full_move = move + modifier scramble.append(full_move) # Update the last move’s base for the next iteration’s check last_move_base = move return scramble def main(): “”” Main function to run the scrambler program. “”” display_welcome_message() while True: # Get the length from the user length = get_scramble_length() # Generate the scramble scramble_list = generate_scramble(length) # Display the result print(“\nYour scramble is:”) print(” “.join(scramble_list)) # Ask if the user wants to go again print(“\n————————————————–“) repeat = input(“Do you want to generate another scramble? (yes/no): “).lower() if repeat not in [“yes”, “y”]: break print(“\nThanks for using the scrambler. Happy cubing!”) # — Program Entry Point — if __name__ == “__main__”: main()
User-Centered Design and Good Commenting
User-Centered Design (UCD):
Friendly Interface: Useprint()
statements to provide clear instructions and feedback. The welcome message and goodbye message make the program feel more interactive.
Easy Navigation: The program guides the user step-by-step: first, it asks for the length, then it provides the scramble, and finally, it asks if they want to repeat. This simple loop is intuitive.
Error Handling: Theget_scramble_length()
function uses atry-except
block to handle non-integer input and awhile
loop to ensure the user provides a positive number. This prevents the program from crashing and makes it more robust.
Good Code Commenting:
File Header: The comments at the top of the file provide a quick overview of the program’s purpose, author, and date.
Function Docstrings: Each function has a docstring (the triple-quoted string right after the function definition). This explains what the function does, its arguments (Args
), and what it returns (Returns
). This is excellent practice for documenting your code.
Inline Comments: Use comments within the functions to explain complex or non-obvious parts of the logic, like the check to prevent consecutive moves of the same face (e.g.,R R'
).
This structure and these components should help you create a high-quality project that meets all the requirements of your assignment!- Me:
oh, you gave me the coding answer, which I don’t like. I need to learn and improve my coding skills on my own, so I skipped over that part of your response. Can you send me the same thing with prompts to help me think instead of a direct coding answer - Gemini:
That’s an excellent approach to learning! It’s much more effective to build the solution yourself. I can certainly provide the same guidance in a more conceptual way, with prompts to get you thinking about each part of the project.
Flowcharting Your Program
Before you write any code, it’s helpful to map out the process. This is where your flowchart comes in. Think about it like a recipe.
Question to ask yourself: What is the first thing a user sees or does when they run your program?
Prompt: How do you get from the starting point to the final scramble? What are the key decision points and loops in the process? For example, what happens if the user enters something that isn’t a number for the scramble length?
Designing the Code Structure
Now, let’s think about how to organize your Python code. This is a great opportunity to use functions to break down the problem into smaller, manageable parts.
Prompt: What are the major, distinct tasks your program needs to perform? For example, one task is greeting the user, another is generating the scramble, and another is handling the main loop of the program. How can you define separate functions for each of these tasks?
Think about variables: What information do you need to store and use throughout the program? For instance, you’ll need a list of all possible cube moves. What’s a good way to store this information at the beginning of your script?
User-Centered Design and User Interface
Your project needs to be “user-friendly.” This means thinking about the person using your program.
Prompt: How can you make your program welcoming and easy to understand for someone who has never used it before? Think about the messages you’ll display.
Consider the user’s experience: What if a user accidentally types “twenty” instead of “20”? How can you build in a safeguard so your program doesn’t crash? This is called error handling. What Python structure would be good for this?
Generating the Scramble Logic
This is the core of your program. A good scramble isn’t just a random string of letters; there are rules to follow (e.g., you can’t have “R R’” in a row).
Prompt: How can you use Python’srandom
library to select a move and a modifier?
Think about the rules: How can you prevent moves on the same face from happening consecutively (e.g., “R” followed by “R’”)? What information do you need to store from the previous move to check against the current one?
The loop: How do you make sure your scramble has the exact number of moves the user requested? What kind of loop would be best for this?
Code Commenting
Good code commenting helps others (and your future self!) understand your code.
Prompt: Where would it be most helpful to add comments? Think about the top of the file, what each function does, and any particularly tricky lines of code.
By thinking through these questions, you’ll have a solid plan and a much deeper understanding of the concepts required to build your scrambler. Good luck with your project! - Me:
how do i make a user friendly interface - Gemini:
That’s a fantastic question, and a crucial part of any coding project! A user-friendly interface (UI) is what makes your program accessible and enjoyable for others to use. Even if you’re not creating a full graphical user interface (GUI) with windows and buttons, you can still make your text-based interface (TUI) very user-friendly.
Here are some prompts to guide your thinking about creating a user-friendly interface for your 3×3 scrambler:
1. Welcoming the User
Prompt: When a user first runs your program, what should they see? How can you immediately let them know what the program does and how to start using it?
Think about: A clear, concise welcome message.
Example: Instead of just showing a prompt, you could print something like:------------------------------------ Welcome to the Cube Scramble Maker! Let's generate some scrambles for your 3x3 cube. ------------------------------------
2. Guiding the User Step-by-Step
Prompt: How do you clearly tell the user what information you need from them at each stage?
Think about: Using descriptive prompts for input.
Example: Instead of justinput("> ")
, you could use:
Pythonscramble_length_str = input("How many moves should be in your scramble? (e.g., 20): ")
Consider: What happens if the user doesn’t provide the information you expect?
3. Handling Errors Gracefully
Prompt: What are the common mistakes a user might make when interacting with your program? How can you prevent these mistakes from crashing your program or confusing the user?
Think about:
Entering text when a number is expected (like for scramble length).
Entering a negative number or zero for the length.
Typing “yes” or “no” in an unexpected way when asked to repeat.
How can you provide helpful feedback? Instead of just an error message, tell them why it’s an error and what they should do.
Example: If they type “twenty” for length:
Bad:ValueError: invalid literal for int() with base 10: 'twenty'
Good:"Oops! That doesn't look like a number. Please enter a whole number for the scramble length (like 20)."
4. Presenting Information Clearly
Prompt: Once you’ve generated the scramble, how do you show it to the user in the most readable way?
Think about:
Using spaces between moves so they’re distinct.
Perhaps putting the scramble on its own line or within a clear section.
Example:R U' F2 B R2 U
looks much better thanRU'F2BR2U
.
5. Making Choices Easy
Prompt: When you ask the user if they want to do something again (like generate another scramble), how do you make it simple for them to respond?
Think about:
Accepting variations like “yes,” “y,” “YES,” or “Y.”
Making it clear what options are available.
Example: A prompt like:Do you want to generate another scramble? (yes/no):
And then, in your code, checking if the input, converted to lowercase, is “yes” or “y”.
6. Providing a Polite Exit
Prompt: When the user decides to stop using your program, how do you say goodbye?
Think about: A simple, friendly closing message.
Example:Thanks for using the scrambler! Happy cubing!
By thinking about these prompts, you’re essentially designing the conversation between your program and the user. This is the heart of creating a user-friendly interface, even in a text-based environment! - Me: what is the format of using the random library in terms of giving it a set of letters to randomise and then display
- Gemini: To use Python’s
random
library to select and display a random item from a sequence, you’ll primarily use therandom.choice()
function.
How to userandom.choice()
Therandom.choice()
function takes a non-empty sequence (like a list, tuple, or string) as its argument and returns a single, randomly selected element from that sequence.
Here’s the basic format:
Pythonimport random # A list of letters my_letters = ['A', 'B', 'C', 'D', 'E'] # Randomly select one letter from the list random_letter = random.choice(my_letters) # Print the result print(random_letter)
Every time you run this code, it will print one of the letters from themy_letters
list at random.
Applying this to Your Scrambler Project
For your 3×3 scrambler, you can userandom.choice()
in a few places:
Selecting the face: Create a list of all the faces on a 3×3 cube (R
,L
,U
,D
,F
,B
). Then, userandom.choice()
on this list to pick a random face for your move.
Selecting the modifier: Create another list with the modifiers (' '
,'
,2
). Userandom.choice()
on this list to get a random modifier.
Once you have the random face and random modifier, you can combine them to form a single move string, like'R'
. - Me: i have scramble outputs now, how do i make them not have moves that are repetitive or redundant like: “L, L’ “, or “U, D, U2”
- Gemini:
That’s a key part of making a good scrambler. Here’s a conceptual way to approach it.
The Logic of a Good Scramble
A good cube scramble follows specific rules to ensure every move is meaningful and non-redundant. The primary rule is that a move should not be on the same axis as the immediately preceding move.
Axis: Think of the cube’s faces in pairs:(R, L)
are on one axis,(U, D)
on another, and(F, B)
on the third.
Right/Left Axis:R
,R'
,R2
,L
,L'
,L2
Up/Down Axis:U
,U'
,U2
,D
,D'
,D2
Front/Back Axis:F
,F'
,F2
,B
,B'
,B2
How to Implement This in Your Code
To prevent redundant moves, you’ll need to keep track of the last move’s axis.
Map Moves to Axes: Create a way to know which axis each move belongs to. A dictionary or a series of conditional statements would work well for this. For example:'R'
and'L'
belong to the “Right/Left” axis.'U'
and'D'
belong to the “Up/Down” axis.'F'
and'B'
belong to the “Front/Back” axis.
Generate a Move with a Loop: When you generate your scramble, do it one move at a time inside a loop.
Inside the loop:
Randomly select a new move (e.g.,'U'
).
Check the axis: Compare the axis of this new move to the axis of the previous move.
If the axes are the same, you have a potential redundancy. For example, if the last move was'D'
(Up/Down axis) and your new random move is'U'
(also Up/Down axis), you should discard this new move and try again.
If the axes are different, the move is valid. Add it to your scramble list and update the “last axis” variable for the next iteration.
This “check-and-retry” loop ensures you always generate a valid, non-redundant sequence of moves for your scramble.
Leave a Reply