Skip to content

Commit

Permalink
Update package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogacel committed Feb 17, 2021
1 parent d0ee378 commit 3f0eea8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
## Sample Code

```typescript
const cube = new Cube();
const cube = Cube.solved();

cube.isSolved(); // true

Expand Down
9 changes: 9 additions & 0 deletions src/cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ export class Cube {
return cube;
}

public equals(cube: Cube): boolean {
return this.faces.reduce<boolean>(
(prev, curr, curr_index) =>
prev && curr.colors.reduce<boolean>(
(_prev, _curr, _curr_index) =>
prev && cube.faces[curr_index].colors[_curr_index] === _curr,
true),
true);
}

public isSolved(): boolean {
return this.faces.reduce<boolean>((prev, curr) => prev && curr.isSolid(), true);
Expand Down
36 changes: 7 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
import { Cube } from "./cube";
import { parse, reconstruct } from "./utils";
export * from "./cube";
import { Cube } from "./cube"
import * as Util from "./utils"
import * as Const from "./consts"
import * as Face from "./face"

const cube = Cube.solved()

cube.print();
console.log(cube.isSolved());


// "U2 B2 F2 U' L2 D U2 F2 U' F2 U' R' F R' F' L2 F' U' B' y L U R' U R' F2 U' L U L2 U' L U' L U L' U' L U L' U2 R' U R U' R U R' y2 F R U R' U' R U R' U' F'"
const algorihtm = "U2 L2 F2 U2 L B2 D2 R' U2 R U2 L2 F' D L' B' D' B' U2 F R y R' U2 R2 B' R' B U L' U Rw D Rw' B' L U2 R U' R2 F R U2 F' U2 L' U L"
const moves = parse(algorihtm);
console.log(moves);
cube.apply(moves);

cube.print();
console.log(cube.isSolved());

console.log(cube.solvedEdges());
console.log(cube.solvedCorners());
console.log(cube.solvedCrosses());
console.log(cube.solvedPairs());

// const recon = reconstruct("U2 B2 F2 U' L2 D U2 F2 U' F2 U' R' F R' F' L2 F' U' B'",
// "y L U R' U R' F2 U' L U L2 U' L U' L U L' U' L U L' U2 R' U R U' R U R' y2 F R U R' U' R U R' U' F'")

const recon = reconstruct("L R2 B U2 R2 F D2 L2 F R' F2 D' F U F2 R' B L F'",
"x2 U2 Rw' U Rw L F2 R D y' U2 L' U L U' L' U L U' y' U' R' U R2 U' R' U2 L' U L U2 L' U L U' L U' L' y U' y' R U2 R' U R U' R' U2 Rw U R' U R U2 Rw' M' U M2 U M2 U M' U2 M2 U'");

console.log(recon.reduce((prev, curr) => prev + "\n" + curr.join(" "), ""));
export default {
Cube, Util, Const, Face
}
2 changes: 1 addition & 1 deletion src/tests/rotation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createAndMove = (m: Move, rest: (oldFaces: Face[], newFaces: Face[]) => an
return () => rest(oldFaces, cube.faces);
}

describe('Solved rotates', () => {
describe('Cube rotates', () => {
describe('X axis', () => {
it('X rotates correctly', createAndMove(Move.X, (oldFaces, newFaces) => {
assert.deepEqual(oldFaces[Fi], newFaces[Ui])
Expand Down

0 comments on commit 3f0eea8

Please sign in to comment.