Giter Club home page Giter Club logo

cubesimrs's Introduction

CubeSim V2

CubeSim is a Rubik's Cube simulator and solver written entirely in Rust.

Features

Planned Features

  • User interface (web interface using WASM perhaps?).
  • Optimal solutions using the Kociemba algorithm

Usage

The core types in the library are as follows:

  • Cube trait: To support multiple implementations of a Rubik’s Cube, we define a trait which includes the minimal set of behaviours expected of a Rubik’s Cube. Specific implementations can then be used for different scenarios. For example, the FaceletCube is most performant while the GeoCube allows for easy 3D modelling.
  • Face enum: A face of a Rubik’s Cube sticker represented in WCA notation.
  • Move enum: A move of a 3x3x3 Rubik’s Cube represented in WCA notation. Each Move must be tagged with a MoveVariant to completely define a move.
  • MoveVariant enum: A move variation that must be applied to the Move enum.

After understanding these core types, we can start writing a basic simulation:

use cubesim::prelude::{Cube, Face, Move, MoveVariant};
use cubesim::cube_implementors::FaceletCube;
 
let cube = FaceletCube::new(3);
let turned_cube = cube.apply_move(Move::U(MoveVariant::Double));
println!("{:?}", turned_cube.get_state());

To build more complex simulations and solvers, please follow our official documentation.

Resources Used

cubesimrs's People

Contributors

stanleydesu avatar thecjharries avatar v-wong 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

Watchers

 avatar  avatar  avatar

Forkers

stanleydesu

cubesimrs's Issues

Fix tense inconsistencies in doc comments

I see some inconsistencies in tense (present and past) in some doc comments (currently detected in generic_cube.rs).
E.g.

/// Maps over the pieces of the cube, replacing each piece
/// according to the given mask function. 
fn mask(&self, mask: &dyn Fn(i32, Face) -> Face) -> Self;

/// Apply a move to a cube.
/// ...
fn apply_move(&self, mv: Move) -> Self;

Refactor Geometric Moves

The implementation of geometrics moves currently features a lot of duplicate code. This was originally done as a temporary solution to support arbitrary sized cubes. A more elegant solution with less duplicate code would be preferred here.

Convert GeometricMove's predicate to use unboxed closures

If a move's n value was passed when checking if a sticker satisfies the predicate, the predicate field can become
pub predicate: fn(&Sticker, u32) -> bool>, which is potentially cleaner/faster than the current boxed dyn implementation.

Change Mask To Use Solved Indices

The mask method in the Cube trait is intended to ignore certain stickers which can be useful for defining solvers of certain states (e.g. cross, first block, etc). The method however currently takes in a slice of indices within the current cube state. It would be much more useful if it were to take a slice of indices with respect to the original solved cube state.

Scramble parser improvements

parse_scramble should:

  • trim the provided scramble
  • split by whitespace (use split_whitespace instead of split(' ')
  • return an empty Vec for a string with no moves, as it currently panics on this case

Cache pruning tables in Thistlethwaite solver

The pruning tables inside each phase of the Thislethwaite solver are constant and do not vary from call to call. At the moment, the tables are regenerated at each function call. This is inefficient and caching the tables would be preferable.

Set MoveVariant's 'Standard' value to 1

Standard,

By setting MoveVariant's 'Standard' value to 1, it improves semantics, as

  • Standard is equivalent to 1 clockwise turn,
  • Double becomes 2 turns,
  • Inverse becomes 3 turns, equivalent to 1 anticlockwise turn

This allows reduction/simplification of summed MoveVariants, and can simplify modify_move (geometric_cube/moves.rs) to

fn modify_move(mv: GeometricMove, variant: MoveVariant) -> GeometricMove {
    GeometricMove { angle: mv.angle * variant as f32, ..mv }
}

Cubes created from FaceletCube::from(faces) are invalid

In cube.rs, the new function initializes as:

            .enumerate()
            .map(|(i, s)| (*s, i as u16))

Effectively adding the number of the position of the original vec inside as extra info.

While on the from function:

            faces: faces.iter().map(|f| (*f, 0)).collect(),

Sets all indices to zero.

As a result, calling cubesim::solve(&cube) will always return None for cubes that are created with the from function instead of new.

This makes impossible to use this library for arbitrary cubes where we don't know the rotations made to get into that position.

Facelet Cube Bottleneck

The current FaceletCube implementation is not as performant as I would like it to be. Since the results are cached, actual computations are rarely required. I suspect the bottleneck to lie in the actual caching mechanism.

Refactor GeoCube with unsigned integers

The implementation of GeoCube currently features many i32s, where u32s would be more appropriate, such as the size field in the GeoCube struct, and other mentions of size as a parameter.
A better semantically-typed solution would be preferred here.

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.