forked from larspetrus/Roofpig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factored out the "side drift" code into a Pov class that at least *I*…
… now actually understand.
- Loading branch information
1 parent
58456ec
commit 582a7ea
Showing
12 changed files
with
133 additions
and
95 deletions.
There are no files selected for viewing
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
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
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
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,36 @@ | ||
# POV = Point Of View. Cube notations has two POVs. | ||
# | ||
# Seen from the cube, U is always up, and there are only six kinds of moves: B, R, D, F, L, and U. | ||
# Seen from the hands of a human, more moves exist (x, y, x, M, E, S, etc), and after a z2 move, | ||
# U seen from the cube is D seen from the hands. | ||
# | ||
# This class keeps track of and maps between these POVs | ||
|
||
class Pov | ||
constructor: (moves) -> | ||
@map = Pov.start_map() | ||
this.track(moves) if moves | ||
|
||
@start_map: -> | ||
{B: 'B', D: 'D', F: 'F',L: 'L', R: 'R', U: 'U'} | ||
|
||
track: (moves) -> | ||
moves = [moves] unless Array.isArray(moves) | ||
for move in moves | ||
move.track_pov(@map) | ||
|
||
hand_to_cube_map: -> | ||
reverse_map = {} | ||
for own key, value of @map | ||
reverse_map[value] = key | ||
reverse_map | ||
|
||
cube_to_hand: (code) -> | ||
this._case_map(@map, code) | ||
|
||
hand_to_cube: (code) -> | ||
this._case_map(this.hand_to_cube_map(), code) | ||
|
||
_case_map: (map, code) -> | ||
return code unless code | ||
(map[char] || map[char.toUpperCase()]?.toLowerCase() || char for char in code.split('')).join('') |
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
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
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,33 @@ | ||
#= require Pov | ||
|
||
describe "Pov", -> | ||
describe "track", -> | ||
it "handles move or array", -> | ||
pov = new Pov() | ||
expect(pov.map).to.deep.equal(Pov.start_map()) | ||
|
||
pov.track(new Move("M")) | ||
expect(pov.map).to.deep.equal(B: 'U', D: 'B', F: 'D', L: 'L', R: 'R', U: 'F') | ||
|
||
pov = new Pov() | ||
pov.track([new Move("M"), new Move("F'"), new Move("E2")]) | ||
expect(pov.map).to.deep.equal(B: 'U', D: 'F', F: 'D', L: 'R', R: 'L', U: 'B') | ||
|
||
describe "cube_to_hand", -> | ||
it "cube_to_hand", -> | ||
pov = new Pov(new Move("S'")) | ||
expect(pov.cube_to_hand("XYZ:URF")).to.equal("XYZ:LUF") | ||
expect(pov.cube_to_hand("XYZ:Urf")).to.equal("XYZ:Luf") | ||
expect(pov.cube_to_hand(null)).to.equal(null) | ||
|
||
describe "hand_to_cube", -> | ||
it "hand_to_cube", -> | ||
pov = new Pov(new Move("S'")) | ||
expect(pov.hand_to_cube("F"), 1).to.equal("F") | ||
expect(pov.hand_to_cube("L"), 1).to.equal("U") | ||
|
||
pov = new Pov(new Move("E")) | ||
expect(pov.hand_to_cube("F"), 1).to.equal("L") | ||
expect(pov.hand_to_cube("f"), 1).to.equal("l") | ||
|
||
expect(pov.cube_to_hand(null)).to.equal(null) |