Extract full cube state from Bluetooth data
Closed this issue · 13 comments
Thanks for writing this package! Really fun to extract the moves from the browser.
Do you know how to extract the full state from the bluetooth data package as well?
I worked on the full cube state in my fork here: https://github.com/Scarygami/giiker
Still need to add some documentation though.
@hakatashi
I can send a pull request, but since I did some major changes, I wanted to check with you first if you are okay with those changes, or if I should rather publish my version under a different name.
Probably the biggest change (since it fits my way of working) is not to depend on babel (or other packages), publishing the library as "pure" es module, thus leaving the preferred build step to the user of the library.
Nice! Will check out your fork @Scarygami
Thanks for sharing, @Scarygami. I just started a project to do exactly this. Glad I checked the issues on this project before diving too deep. I think I'm going to build on your work and attempt to create a function that returns a cubejs
instance that mirrors the cube.
Alright. It's not pretty but here it is:
const FaceletMap = {
white: "U",
red: "L",
blue: "F",
orange: "R",
green: "B",
yellow: "D"
};
const state = giiker.state;
const cubeString =
"" +
// up
FaceletMap[state.corners[1].colors[1]] +
FaceletMap[state.edges[2].colors[1]] +
FaceletMap[state.corners[2].colors[0]] +
FaceletMap[state.edges[5].colors[0]] +
FaceletMap["white"] +
FaceletMap[state.edges[6].colors[0]] +
FaceletMap[state.corners[5].colors[0]] +
FaceletMap[state.edges[10].colors[1]] +
FaceletMap[state.corners[6].colors[1]] +
// right
FaceletMap[state.corners[6].colors[0]] +
FaceletMap[state.edges[6].colors[1]] +
FaceletMap[state.corners[2].colors[1]] +
FaceletMap[state.edges[11].colors[1]] +
FaceletMap["orange"] +
FaceletMap[state.edges[3].colors[1]] +
FaceletMap[state.corners[7].colors[1]] +
FaceletMap[state.edges[7].colors[1]] +
FaceletMap[state.corners[3].colors[0]] +
// front
FaceletMap[state.corners[5].colors[2]] +
FaceletMap[state.edges[10].colors[0]] +
FaceletMap[state.corners[6].colors[2]] +
FaceletMap[state.edges[9].colors[0]] +
FaceletMap["blue"] +
FaceletMap[state.edges[11].colors[0]] +
FaceletMap[state.corners[4].colors[2]] +
FaceletMap[state.edges[8].colors[0]] +
FaceletMap[state.corners[7].colors[2]] +
// down
FaceletMap[state.corners[4].colors[1]] +
FaceletMap[state.edges[8].colors[1]] +
FaceletMap[state.corners[7].colors[0]] +
FaceletMap[state.edges[4].colors[0]] +
FaceletMap["yellow"] +
FaceletMap[state.edges[7].colors[0]] +
FaceletMap[state.corners[0].colors[0]] +
FaceletMap[state.edges[0].colors[1]] +
FaceletMap[state.corners[3].colors[1]] +
// left
FaceletMap[state.corners[1].colors[0]] +
FaceletMap[state.edges[5].colors[1]] +
FaceletMap[state.corners[5].colors[1]] +
FaceletMap[state.edges[1].colors[1]] +
FaceletMap["red"] +
FaceletMap[state.edges[9].colors[1]] +
FaceletMap[state.corners[0].colors[1]] +
FaceletMap[state.edges[4].colors[1]] +
FaceletMap[state.corners[4].colors[0]] +
// back
FaceletMap[state.corners[2].colors[2]] +
FaceletMap[state.edges[2].colors[0]] +
FaceletMap[state.corners[1].colors[2]] +
FaceletMap[state.edges[3].colors[0]] +
FaceletMap["green"] +
FaceletMap[state.edges[1].colors[0]] +
FaceletMap[state.corners[3].colors[2]] +
FaceletMap[state.edges[0].colors[0]] +
FaceletMap[state.corners[0].colors[2]];
const cube = Cube.fromString(cubeString);
I've noticed a small error in the above code. Fixing now...
Just realized that the biiker.on('move', ()=>{})
listener views the green side as "F" - I wrote this with blue being "F".
With proper orientation, it should be:
const FaceletMap = {
white: "U",
red: "R",
blue: "B",
orange: "L",
green: "F",
yellow: "D"
};
const state = giiker.state;
const cubeString =
"" +
// up: 0
FaceletMap[state.corners[6].colors[1]] +
FaceletMap[state.edges[10].colors[1]] +
FaceletMap[state.corners[5].colors[0]] +
FaceletMap[state.edges[6].colors[0]] +
FaceletMap["white"] +
FaceletMap[state.edges[5].colors[0]] +
FaceletMap[state.corners[2].colors[0]] +
FaceletMap[state.edges[2].colors[1]] +
FaceletMap[state.corners[1].colors[1]] +
// right: 9
FaceletMap[state.corners[1].colors[0]] +
FaceletMap[state.edges[5].colors[1]] +
FaceletMap[state.corners[5].colors[1]] +
FaceletMap[state.edges[1].colors[1]] +
FaceletMap["red"] +
FaceletMap[state.edges[9].colors[1]] +
FaceletMap[state.corners[0].colors[1]] +
FaceletMap[state.edges[4].colors[1]] +
FaceletMap[state.corners[4].colors[0]] +
// front: 18
FaceletMap[state.corners[2].colors[2]] +
FaceletMap[state.edges[2].colors[0]] +
FaceletMap[state.corners[1].colors[2]] +
FaceletMap[state.edges[3].colors[0]] +
FaceletMap["green"] +
FaceletMap[state.edges[1].colors[0]] +
FaceletMap[state.corners[3].colors[2]] +
FaceletMap[state.edges[0].colors[0]] +
FaceletMap[state.corners[0].colors[2]] +
// down: 27
FaceletMap[state.corners[3].colors[1]] +
FaceletMap[state.edges[0].colors[1]] +
FaceletMap[state.corners[0].colors[0]] +
FaceletMap[state.edges[7].colors[0]] +
FaceletMap["yellow"] +
FaceletMap[state.edges[4].colors[0]] +
FaceletMap[state.corners[7].colors[0]] +
FaceletMap[state.edges[8].colors[1]] +
FaceletMap[state.corners[4].colors[1]] +
// left: 36
FaceletMap[state.corners[6].colors[0]] +
FaceletMap[state.edges[6].colors[1]] +
FaceletMap[state.corners[2].colors[1]] +
FaceletMap[state.edges[11].colors[1]] +
FaceletMap["orange"] +
FaceletMap[state.edges[3].colors[1]] +
FaceletMap[state.corners[7].colors[1]] +
FaceletMap[state.edges[7].colors[1]] +
FaceletMap[state.corners[3].colors[0]] +
// back: 45
FaceletMap[state.corners[5].colors[2]] +
FaceletMap[state.edges[10].colors[0]] +
FaceletMap[state.corners[6].colors[2]] +
FaceletMap[state.edges[9].colors[0]] +
FaceletMap["blue"] +
FaceletMap[state.edges[11].colors[0]] +
FaceletMap[state.corners[4].colors[2]] +
FaceletMap[state.edges[8].colors[0]] +
FaceletMap[state.corners[7].colors[2]];
@timhuff thanks for doing the mapping, I've updated my fork with a new property stateString
that will return the state in this cubejs compatible format.
PS. here's what I've been working on using this library :)
App: https://scary-cube.firebaseapp.com/
Infos: https://plus.google.com/+GerwinSturm/posts/jYsBZjJsPQ6
Sorry I'm late to the party.
@Scarygami Your code is pretty cool! Though I don't prefer exposing ES6+ codes without transpiling, I think it's acceptable here because giiker is intended to run on browser, not node.
Please send PR. I'll immediately merge it. 😀
I also want to invite you to collaborator of GitHub and npm once merged. Is it ok? @Scarygami
Sure, you can add me as collaborator, thanks :)
I have some more things I want to add to this library to make it feature-complete. I will send those as PR, once I'm done.
I would also like to know how to get the full state (colors on each side) from the Bluetooth characteristic response... for example the solved cube gives me this:
12 34 56 78 33 33 33 33 12 34 56 78 9a bc 00 00 33 31 23 23
What does this value mean exactly? any help would be appreciated! :-) Thanks!!