Git Product home page Git Product logo

pycuber's Introduction

PyCuber

pip install pycuber

PyCuber is a Rubik's Cube package in Python 2/3

The cube can be revealed as expanded view in the terminal, so it's easy to visualise the cube, just inside the terminal. (Not tested on Windows)

import pycuber as pc

# Create a Cube object
mycube = pc.Cube()

# Do something at the cube.
mycube("R U R' U'")

print(mycube)

alt tag

We also provided some useful tools to deal with Rubik's Cube formulae.

import pycuber as pc

# Create a Formula object
my_formula = pc.Formula("R U R' U' R' F R2 U' R' U' R U R' F'")

# Reversing a Formula
my_formula.reverse()
print(my_formula)

# Mirroring a Formula object
my_formula.mirror("LR")
print(my_formula)
F R U' R' U R U R2 F' R U R U' R'
F' L' U L U' L' U' L2 F L' U' L' U L

I'll add some documentations later.

pycuber's People

Contributors

adrianliaw avatar awwong1 avatar jbwincek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycuber's Issues

New User Help

Can you explain how to input a specific cube instead of a random one?

Array representation of cube?

I have need of an array representation of the cube, either as a flat array or an array of six arrays for each face. I haven't found anything existing to do this, so I've come up with my own hacky method, but this feels like something that should be part of the Cube class. Here's what I did:

def cubeAsArray(cube):
    faces = ["L", "R", "U", "D", "B", "F"]
    cubeArray = []
    for face in faces:
        face = cube.get_face(face)  # get face, iterate over all squares.
        for x in [0,1,2]:
            for y in [0,1,2]:
                cubeArray.append(str(face[x][y]))
    return cubeArray

Option to get string-based output

Escape-sequences for coloring are nice for interactive programming, but not very friendly for automate tasks. Would be nice to have an option to disable color output and just return color strings like "red" or "orange". Or, even better, the ability to pass color mappings into constructor of the Cube class.

If you think it is a good idea, I can actually propose a pull request for this

How do I change the colours displayed?

I want to set:
F= White
U= Red
B= Yellow
R= Green
L= Blue
D = Orange

Also, I'm getting all these colours except Orange which is replaced by purple. How can I change that?

Support for X Y Z?

It would be nice if X, Y, and maybe Z would be supported.

>>> pycuber.Cube()("X")                                                                                                                                                                                                                                                          
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pycuber/cube.py", line 382, in __call__
    return self.perform_algo(algo)
  File "/usr/local/lib/python2.7/dist-packages/pycuber/cube.py", line 571, in perform_algo
    formula = Formula(algo)
  File "/usr/local/lib/python2.7/dist-packages/pycuber/formula.py", line 365, in __init__
    sequence[i] = Step(sequence[i])
  File "/usr/local/lib/python2.7/dist-packages/pycuber/formula.py", line 114, in __init__
    raise ValueError("Invalid action name {0}".format(name))
ValueError: Invalid action name X

Output from CFOPSolver doesn't actually solve a cube

I was messing around with PyCuber and I found something interesting about the CFOPSolver. It doesn't always solve a cube back to its original state when a cube differs greatly from the original state (the faces always end up solved, but sometimes the faces are in a reversed order). Additionally, the output from the solver doesn't actually solve the cube if done manually. Here is the output from CFOPSolver after I made 10,000 randomly generated turns:

Cross: R2 F D F' D R' D'
F2L('green', 'orange'): U F' U F R U R'
F2L('orange', 'blue'): y U R U R' U R U' R'
F2L('blue', 'red'): y R U2 R' F' U2 F U F' U2 F
F2L('red', 'green'): y F' U' F U F' U' F
OLL:  F R U R' U' R U R' U' F'
PLL:  U R' U L' U2 R U' R' U2 L R U'

FULL: R2 F D F' D R' D' U F' U F R U R' U B U B' U B U' B' L U2 L' B' U2 B U B' U2 B L' U' L U L' U' L2 F U F' U' F U F' U' L' U F' U B' U2 F U' F' U2 B F U'
R2 F D F' D R' D' U F' U F R U R' U B U B' U B U' B' L U2 L' B' U2 B U B' U2 B L' U' L U L' U' L2 F U F' U' F U F' U' L' U F' U B' U2 F U' F' U2 B F U'

Specifically the 'FULL:' sequence does not revert the cube its original solved state (and it doesn't get into that kinda-solved state that I mentioned above, either).

I attached files to reproduce this issue. turnsequence.txt is a randomly generated 10,000 turn sequence to get the cube from the solved state to a sufficiently random state (and is the exact sequence I used when I discovered this issue). inversesequence.txt is the inverse of that sequence (it directly undoes the first sequence). Lastly, cfopsolution.txt is the FULL: sequence produced by CFOPSolution.

Two other steps I did to verify:

  • pycuber.Cube()(turn_sequence)(inverse_seqence) produces an unmodified, solved cube
  • pycuber.Cube()(turn_sequence)(cfop_solution) produces an unsolved, and still extensively modified cube

(pycuber 0.2.1)

Running solver.solve() raises a StopIteration error

The code I ran:

import pycuber as pc
c = pc.Cube()
alg = pc.Formula()
random_alg = alg.random()
from pycuber.solver import CFOPSolver
solver = CFOPSolver(c)
solver.solve()

The error message it produced:

Cross:  Cross ......
Solving F2L#0 ......Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pycuber/solver/cfop/__init__.py", line 26, in solve
    f2l = next(f2lall)
StopIteration

I'm running Python 3.5.0, with the current release of PyCuber

Key error: white

I am trying to input a cube configuration manually.
I am initialising a cube and the assigning each color to one of the default colors. For one of my cubes, you can see the pycuber cube I got in the console image below, and it is a valid cube!

When I run the CFOPSolver function, I am getting the error 'Key error: white'

Please help me resolve this issue! Thanks!
This is the console:
Screenshot from 2020-06-25 11-08-47

Feature suggestion/request: 2x2x2 block solver

I came across PyCuber again and remembered that I planned to implement a block solver for 2x2x2 blocks which lists the shortest solutions for each of the 8 possible 2x2x2 blocks for a given scramble. The main purpose would be to practice block solving skills for FMC.
It would be awesome to have such a solver in PyCuber. I will probably not have the time to implement it myself soon, so if you are looking for new ideas for improvements, this might be a good idea. ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.