0

I'm creating a Rubiks cube in Python and am running into the problem of checking whether 2 cubes are the same. I'm representing the sides of the cube as north, east, south, west, front, and back. I originally just had my function check if cube1.north = cube2.north, cube1.south = cube2.south, etc and if all where true then they are the same. This leaves out the cubes where cube1.north = cube2.south, cube1.south = cube2.north, etc. and many other scenarios where they are equal but the specific faces don't match up exactly. Does anyone have an idea on how to check if any 2 cubes are equal without tons of if statements for every possibility?

Quinn
  • 89
  • 2
  • 10
  • 1
    Hard to say without knowing the data structures you're using to represent the state of the cube. If you are using, for example, a list of list for each face, then you can just compare those for each face. – kindall Nov 18 '16 at 00:03
  • 2
    Just think about some normalized (predefined ordering) flattening operation which transforms any cube into an 1d-list. Then do a basic list-comparison. – sascha Nov 18 '16 at 00:07
  • @sascha You mean like, 1. `find corner with red/white/blue` 2. `apply flattening operation` 3. `build a wall`? – Mateen Ulhaq Nov 19 '16 at 08:03

1 Answers1

1

Why don't you try indexing the cube's faces according to which color they have at the center? Then you can just check whether the white-centered face on one cube matches the white-centered face on the other cube.

In other words, the north face will always have a white square at the center, the south face will always have a yellow square at the center, etc. Only operations that keep the orientation of the centers are allowed.

Kerrick Staley
  • 1,583
  • 2
  • 20
  • 28