-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking changes. - Separated lib and bin crates - Changed fs operations behaviour - Table data is now bundeled in the binary
- Loading branch information
1 parent
7d77391
commit 566301d
Showing
23 changed files
with
227 additions
and
290 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1 @@ | ||
[package] | ||
name = "kewb" | ||
version = "0.2.1" | ||
edition = "2021" | ||
description = "A crate for manipulating and solving a 3x3 rubik's cube with Kociemba two phase algorithm" | ||
authors = [ | ||
"LIOKA Ranraison Fiderana <luckasranarison@gmail.com>", | ||
"Miklos Vajna <vmiklos@vmiklos.hu>", | ||
] | ||
repository = "https://github.com/luckasRanarison/kewb" | ||
keywords = ["rubiks-cube", "cube-solver", "kociemba", "two-phase"] | ||
categories = ["algorithms"] | ||
license = "MIT" | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
rand = "0.8.3" | ||
bincode = { version = "2.0.0-rc", features = ["serde"] } | ||
clap = { version = "4.2.5", features = ["derive"] } | ||
spinners = "4.1.0" | ||
workspace.members = ["kewb", "kewb-cli"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "kewb-cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "CLI application for solving and scrambling the 3x3 Rubik's cube" | ||
authors = [ | ||
"LIOKA Ranraison Fiderana <luckasranarison@gmail.com>", | ||
"Miklos Vajna <vmiklos@vmiklos.hu>", | ||
] | ||
repository = "https://github.com/luckasRanarison/kewb" | ||
keywords = ["rubiks-cube", "cube-solver", "kociemba", "two-phase"] | ||
categories = ["command-line-utilities"] | ||
license = "MIT" | ||
readme = "../README.md" | ||
|
||
[dependencies] | ||
kewb = { path = "../kewb" } | ||
clap = { version = "4.2.5", features = ["derive"] } | ||
spinners = { version = "4.1.0" } | ||
bincode = { version = "2.0.0-rc", features = ["serde"] } | ||
|
||
[build-dependencies] | ||
kewb = { path = "../kewb" } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use kewb::{error::Error, fs::write_table}; | ||
|
||
fn main() -> Result<(), Error> { | ||
write_table("bin/table.bin")?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "kewb" | ||
version = "0.2.1" | ||
edition = "2021" | ||
description = "A crate for manipulating and solving a 3x3 Rubik's cube with Kociemba's two phase algorithm" | ||
authors = [ | ||
"LIOKA Ranraison Fiderana <luckasranarison@gmail.com>", | ||
"Miklos Vajna <vmiklos@vmiklos.hu>", | ||
] | ||
repository = "https://github.com/luckasRanarison/kewb" | ||
keywords = ["rubiks-cube", "cube-solver", "kociemba", "two-phase"] | ||
categories = ["algorithms"] | ||
license = "MIT" | ||
readme = "../README.md" | ||
|
||
[dependencies] | ||
rand = "0.8.3" | ||
bincode = { version = "2.0.0-rc", features = ["serde"] } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use super::utils::DataTable; | ||
use crate::error::Error; | ||
use bincode::{ | ||
config::{self, Configuration}, | ||
decode_from_slice, encode_to_vec, | ||
error::DecodeError, | ||
}; | ||
use std::{fs, path::Path}; | ||
|
||
const CONFIG: Configuration = config::standard(); | ||
|
||
pub fn write_table<P>(path: P) -> Result<(), Error> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
let table = DataTable::default(); | ||
let encoded = encode_to_vec(table, CONFIG)?; | ||
|
||
fs::write(path, encoded)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn read_table<P>(path: P) -> Result<DataTable, Error> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
let encoded = fs::read(path)?; | ||
let table = decode_table(&encoded)?; | ||
|
||
Ok(table) | ||
} | ||
|
||
pub fn decode_table(bytes: &[u8]) -> Result<DataTable, Error> { | ||
let (decoded, written) = decode_from_slice(bytes, CONFIG)?; | ||
let additional = bytes.len() - written; | ||
|
||
if additional != 0 { | ||
return Err(DecodeError::UnexpectedEnd { additional })?; | ||
} | ||
|
||
Ok(decoded) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::{ | ||
cube::moves::Move::{self, *}, | ||
move_table::MoveTable, | ||
pruning_table::PruningTable, | ||
}; | ||
use bincode::{Decode, Encode}; | ||
|
||
/// Corner orientation count | ||
pub const CO_COUNT: u16 = 2187; | ||
/// Edge orientation count | ||
pub const EO_COUNT: u16 = 2048; | ||
/// E-slice edge combination count | ||
pub const E_COMBO_COUNT: u16 = 495; | ||
|
||
/// Corner premutation count | ||
pub const CP_COUNT: u16 = 40320; | ||
/// U-D layer edge premutation count | ||
pub const UD_EP_COUNT: u16 = 40320; | ||
/// E-slice edge permutation count | ||
pub const E_EP_COUNT: u16 = 24; | ||
|
||
pub const ALL_MOVES: [Move; 18] = [ | ||
U, U2, U3, D, D2, D3, R, R2, R3, L, L2, L3, F, F2, F2, B, B3, B2, | ||
]; | ||
pub const PHASE2_MOVES: [Move; 10] = [U, U2, U3, D, D2, D3, R2, L2, F2, B2]; | ||
|
||
pub type Table<T> = Vec<Vec<T>>; | ||
|
||
/// Contains the move and prunning table used by the two-phase algorithm | ||
#[derive(Default, Encode, Decode)] | ||
pub struct DataTable { | ||
pub move_table: MoveTable, | ||
pub pruning_table: PruningTable, | ||
} |
Oops, something went wrong.