Python rubik's cube solver

Overview

py-rubik_solver

Python solver for a rubik's cube

This program makes a 3D representation of a rubiks cube and solves it step by step.

solving the cube image

Usage

To use this program you need to execute the following commands

  • For 3D visualizations:

    python visualizer.py

  • For statistics:

    python stats.py

Requirements

To use this program you need to install python 3.8.10 or later (although it will probably work on python 3.7) You will also need a recent version of numpy and vpython 7 or later, those can be installed with:

pip install numpy vpython

Implementation

This project is separated in different files, each implementing a different functionality. The content and functionality of each of these files is the following:

configs.py

This file contains general configuration parameters mostly related to the visual representation of the cube:

  • The default colors
  • The number of fps
  • The time taken to reproduce each move
  • Time to wait between moves
  • Speed factor

cube.py

This file contains the Cube class, which implements a data structure for storing the pieces of the cube and some functions for rotating the faces of the cube. It also implements the possibility to shuffle the cube on creation and the possibility of recording a list of moves made in the cube, this is used for generating a solution.

The main functions implemented in this class are:

  • move(move, n=1, record=True): where move should be a string representing the face to move and n is the number of 90 degree rotations to perform (2 is half turn and 3 or -1 is a turn to the other side). The codes used for the move are:

    • "U", "F", "R", "B", "L", "D" for individual faces.
    • "UD", "FB", "RL" for the middle faces.
    • "UU", "FF", "RR" for rotations of the whole cube along this axis.
  • rotate(axis, n=1): this has the same effect as using move with "UU", "FF", "RR" but these moves are never recorded.

  • is_solved(): checks whether the cube equals the solved cube. Keep in mind that this function will return False even if the cube is solved but faces a different way.

  • copy(): creates a deep_copy of the cube. The copy is completely independent of the original cube.

cube_3d.py

This file implements the Cube3D class, which directly inherits from the Cube class. This class overrides the __init__ and move functions to first create all the cubes necessary to represent the rubiks cube in 3D and then animate them each time any face is moved.

cube_solver.py

This file implements the CubeSolver class, which acts as an abstract class for all the other solving algorithms. It only takes care of taking some measures for statistics.

simple_solver.py

This is the first solving algorithm implemented, it's the usual beginer algorithm for anyone learning how to solve the rubiks cube. It's implemented on a really naive way, and it's far from optimal in terms of the number of steps of the solution. It was just a proof of concept and my goal is to implement a better, more efficient version of this class in the future.

In my personal computer this algorithm takes 1.78 ms on average to compute a solution, and the solutions have 205.6 steps on average. Again these results are far from good, but this was just a proof of concept.

The process of the algorithm is separated in different steps, which are:

  • solve_first_cross: solves the cross on the UP face
  • solve_first_corners: solves the corners on the UP face
  • solve_second_row: solves the second "crown" or the second row
  • solve_second_cross: creates a cross on the DOWN face
  • orientate_2nd_cross: positions correctly the pieces inside the cross on the DOWN face
  • solve_second_corners: positions correctly the corners in the DOWN face
  • orientate_2nd_corners: rotates correctly the corners in the DOWN face
  • reorient_cube: rotates the whole cube so that the UP face is facing up and the FRONT face if facing front

stats.py

This file is used to compute some statistics of the cube solutions. At this point this file is used to compute:

  • The average time taken to generate a solution
  • The average number of steps of the generated solutions
  • Some data of the solving process

Keep in mind the data computed will probably change in the future.

util.py

In this file we store different lists and dictionaries used in the project such as a solved cube structure, a list of the directions, a function for generating random moves, ...

visualizer.py

This file is used to launch a 3D representation of the solving process of the cube. It also contains a function to check the progress of the solving algorithm.

Notes

In the future I'm planing to make more solving algorithms as well as an implementation for a physical robot that solves a given cube.

Use this code as you wish, just let me know if you do, I'll love to hear what you are up to!

If you have any doubts/comments/suggestions/anything please let my know via email at [email protected] or at the email in my profile.

Owner
Pablo QB
I'm a student of the double degree on Computer Engineering and Mathematics at UAM university. Here I upload some of my personal proyects just for fun.
Pablo QB
Pre-Recognize Library - library with algorithms for improving OCR quality.

PRLib - Pre-Recognition Library. The main aim of the library - prepare image for recogntion. Image processing can really help to improve recognition q

Alex 80 Dec 30, 2022
Detect handwritten words in a text-line (classic image processing method).

Word segmentation Implementation of scale space technique for word segmentation as proposed by R. Manmatha and N. Srimal. Even though the paper is fro

Harald Scheidl 190 Jan 03, 2023
A community-supported supercharged version of paperless: scan, index and archive all your physical documents

Paperless-ngx Paperless-ngx is a document management system that transforms your physical documents into a searchable online archive so you can keep,

5.2k Jan 04, 2023
pyntcloud is a Python library for working with 3D point clouds.

pyntcloud is a Python library for working with 3D point clouds.

David de la Iglesia Castro 1.2k Jan 07, 2023
Optical character recognition for Japanese text, with the main focus being Japanese manga

Manga OCR Optical character recognition for Japanese text, with the main focus being Japanese manga. It uses a custom end-to-end model built with Tran

Maciej Budyś 327 Jan 01, 2023
This Repository contain Opencv Projects in python

Python-Opencv OpenCV OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was

Yash Sakre 2 Nov 06, 2021
TextField: Learning A Deep Direction Field for Irregular Scene Text Detection (TIP 2019)

TextField: Learning A Deep Direction Field for Irregular Scene Text Detection Introduction The code and trained models of: TextField: Learning A Deep

Yukang Wang 101 Dec 12, 2022
OCR powered screen-capture tool to capture information instead of images

NormCap OCR powered screen-capture tool to capture information instead of images. Links: Repo | PyPi | Releases | Changelog | FAQs Content: Quickstart

575 Dec 31, 2022
https://arxiv.org/abs/1904.01941

Character-Region-Awareness-for-Text-Detection- https://arxiv.org/abs/1904.01941 Train You can train SynthText data use python source/train_SynthText.p

DayDayUp 120 Dec 28, 2022
Using computer vision method to recognize and calcutate the features of the architecture.

building-feature-recognition In this repository, we accomplished building feature recognition using traditional/dl-assisted computer vision method. Th

4 Aug 11, 2022
Kornia is a open source differentiable computer vision library for PyTorch.

Open Source Differentiable Computer Vision Library

kornia 7.6k Jan 06, 2023
Text to QR-CODE

QR CODE GENERATO USING PYTHON Author : RAFIK BOUDALIA. Installation Use the package manager pip to install foobar. pip install pyqrcode Usage from tki

Rafik Boudalia 2 Oct 13, 2021
End-to-end pipeline for real-time scene text detection and recognition.

Real-time-Scene-Text-Detection-and-Recognition-System End-to-end pipeline for real-time scene text detection and recognition. The detection model use

Fangneng Zhan 89 Aug 04, 2022
PyQT5 app that colorize black & white pictures using CNN(use pre-trained model which was made with OpenCV)

About PyQT5 app that colorize black & white pictures using CNN(use pre-trained model which was made with OpenCV) Colorizor Приложение для проекта Yand

1 Apr 04, 2022
Deskew is a command line tool for deskewing scanned text documents. It uses Hough transform to detect "text lines" in the image. As an output, you get an image rotated so that the lines are horizontal.

Deskew by Marek Mauder https://galfar.vevb.net/deskew https://github.com/galfar/deskew v1.30 2019-06-07 Overview Deskew is a command line tool for des

Marek Mauder 127 Dec 03, 2022
Handwritten Text Recognition (HTR) system implemented with TensorFlow (TF) and trained on the IAM off-line HTR dataset. This Neural Network (NN) model recognizes the text contained in the images of segmented words.

Handwritten-Text-Recognition Handwritten Text Recognition (HTR) system implemented with TensorFlow (TF) and trained on the IAM off-line HTR dataset. T

27 Jan 08, 2023
Character Segmentation using TensorFlow

Character Segmentation Segment characters and spaces in one text line,from this paper Chinese English mixed Character Segmentation as Semantic Segment

26 Aug 25, 2022
Code for CVPR2021 paper "Learning Salient Boundary Feature for Anchor-free Temporal Action Localization"

AFSD: Learning Salient Boundary Feature for Anchor-free Temporal Action Localization This is an official implementation in PyTorch of AFSD. Our paper

Tencent YouTu Research 146 Dec 24, 2022
Autonomous Driving project for Euro Truck Simulator 2

hope-autonomous-driving Autonomous Driving project for Euro Truck Simulator 2 Video: How is it working ? In this video, the program processes the imag

Umut Görkem Kocabaş 36 Nov 06, 2022
An Implementation of the FOTS: Fast Oriented Text Spotting with a Unified Network

FOTS: Fast Oriented Text Spotting with a Unified Network Introduction This is a pytorch re-implementation of FOTS: Fast Oriented Text Spotting with a

GeorgeJoe 171 Aug 04, 2022