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
Document Layout Analysis Projects

Layout_Analysis Introduction This is an implementation of RLSA and X-Y Cut with OpenCV Dependencies OpenCV 3.0+ How to use Compile with g++ : g++ -std

22 Dec 08, 2022
Markup for note taking

Subtext: markup for note-taking Subtext is a text-based, block-oriented hypertext format. It is designed with note-taking in mind. It has a simple, pe

Gordon Brander 224 Jan 01, 2023
Line based ATR Engine based on OCRopy

OCR Engine based on OCRopy and Kraken using python3. It is designed to both be easy to use from the command line but also be modular to be integrated

948 Dec 23, 2022
Deep LearningImage Captcha 2

滑动验证码深度学习识别 本项目使用深度学习 YOLOV3 模型来识别滑动验证码缺口,基于 https://github.com/eriklindernoren/PyTorch-YOLOv3 修改。 只需要几百张缺口标注图片即可训练出精度高的识别模型,识别效果样例: 克隆项目 运行命令: git cl

Python3WebSpider 117 Dec 28, 2022
Detect textlines in document images

Textline Detection Detect textlines in document images Introduction This tool performs border, region and textline detection from document image data

QURATOR-SPK 70 Jun 30, 2022
nofacedb/faceprocessor is a face recognition engine for NoFaceDB program complex.

faceprocessor nofacedb/faceprocessor is a face recognition engine for NoFaceDB program complex. Tech faceprocessor uses a number of open source projec

NoFaceDB 3 Sep 06, 2021
This repository summarized computer vision theories.

This repository summarized computer vision theories.

3 Feb 04, 2022
Convert PDF/Image to TXT using EasyOcr - the best OCR engine available!

PDFImage2TXT - DOWNLOAD INSTALLER HERE What can you do with it? Convert scanned PDFs to TXT. Convert scanned Documents to TXT. No coding required!! In

Hans Alemão 2 Feb 22, 2022
SCOUTER: Slot Attention-based Classifier for Explainable Image Recognition

SCOUTER: Slot Attention-based Classifier for Explainable Image Recognition PDF Abstract Explainable artificial intelligence has been gaining attention

87 Dec 26, 2022
This is a pytorch re-implementation of EAST: An Efficient and Accurate Scene Text Detector.

EAST: An Efficient and Accurate Scene Text Detector Description: This version will be updated soon, please pay attention to this work. The motivation

Dejia Song 544 Dec 20, 2022
Controlling Volume by Hand Gestures

This program allows the user to control the volume of their device with specific hand gestures involving their thumb and index finger!

Riddhi Bajaj 1 Nov 11, 2021
Open Source Computer Vision Library

OpenCV: Open Source Computer Vision Library Resources Homepage: https://opencv.org Courses: https://opencv.org/courses Docs: https://docs.opencv.org/m

OpenCV 65.7k Jan 03, 2023
Detect textlines in document images

Textline Detection Detect textlines in document images Introduction This tool performs border, region and textline detection from document image data

QURATOR-SPK 70 Jun 30, 2022
Introduction to image processing, most used and popular functions of OpenCV

👀 OpenCV 101 Introduction to image processing, most used and popular functions of OpenCV go here.

Vusal Ismayilov 3 Jul 02, 2022
Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.

EasyOCR Ready-to-use OCR with 80+ languages supported including Chinese, Japanese, Korean and Thai. What's new 1 February 2021 - Version 1.2.3 Add set

Jaided AI 16.7k Jan 03, 2023
Deep Learning Chinese Word Segment

引用 本项目模型BiLSTM+CRF参考论文:http://www.aclweb.org/anthology/N16-1030 ,IDCNN+CRF参考论文:https://arxiv.org/abs/1702.02098 构建 安装好bazel代码构建工具,安装好tensorflow(目前本项目需

2.1k Dec 23, 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
Text modding tools for FF7R (Final Fantasy VII Remake)

FF7R_text_mod_tools Subtitle modding tools for FF7R (Final Fantasy VII Remake) There are 3 tools I made. make_dualsub_mod.exe: Merges (or swaps) subti

10 Dec 19, 2022
This repo contains a script that allows us to find range of colors in images using openCV, and then convert them into geo vectors.

Vectorizing color range This repo contains a script that allows us to find range of colors in images using openCV, and then convert them into geo vect

Development Seed 9 Jul 27, 2022
Go package for OCR (Optical Character Recognition), by using Tesseract C++ library

gosseract OCR Golang OCR package, by using Tesseract C++ library. OCR Server Do you just want OCR server, or see the working example of this package?

Hiromu OCHIAI 1.9k Dec 28, 2022