Skip to content

Commit

Permalink
All side drifting now done the good way.
Browse files Browse the repository at this point in the history
  • Loading branch information
larspetrus committed Mar 24, 2017
1 parent c9e0d8b commit b9932ce
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Valid properties are: `alg`, `algdisplay`, `base`, `colored`, `colors`, `flags`,
Define the animated algorithm like this: `alg=R F' x2 R D Lw'`. It handles standard cube notation and some more. If no alg is given, the playback buttons don't appear.

#####Standard notation
Roofpig supports (almost) all standard cube notation. Layer(s): **F, B, R, L, U, D. M, E, S. x, y, z. Fw, Bw, Rw, Lw, Uw, Dw, f, b, r, l, u, d**. Turns: **2, ', 2'**. You can also use **², Z, 1** and **3**.
Roofpig supports (almost) all standard cube notation. Layer(s): **F, B, R, L, U, D. M, E, S. x, y, z. Fw, Bw, Rw, Lw, Uw, Dw, f, b, r, l, u, d**. Turns: **2, ', 2'**. You can also use **², Z, 1**, and **3**.


#####Rotation notation
Expand Down
15 changes: 7 additions & 8 deletions src/Alg.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ class Alg
new Move(code, @world3d, @speed)

unhand: ->
drift = {U: 'U', D: 'D', L: 'L', R: 'R', F: 'F', B: 'B'}
drift = {U: 'U', D: 'D', L: 'L', R: 'R', F: 'F', B: 'B'} # drift.U says what center is on U
colors = new Colors(drift, "", "")

result = []
for move in @moves
drifted_move = this.fwd_drift(move.as_brdflu(), drift)
drifted_move = this.drift(move.as_brdflu(), drift)
result.push(drifted_move)
move.track_fwd_drift(drift)
move.track_drift(drift)
result.join(' ').replace(/[ ]+/g, ' ').replace(/^ +| +$/g, '')

fwd_drift: (code, side_drift) ->
drift: (code, side_drift) ->
return code unless code

inverted_drift = {}
Expand All @@ -123,10 +123,9 @@ class Alg

_side_drift: ->
drift = {U: 'U', D: 'D', L: 'L', R: 'R', F: 'F', B: 'B'}
@next = @moves.length
until this.at_start()
this.prev_move().track_drift(drift)
drift # How to think about this: The 'real' U side is now on drift.U
for move in @moves
move.track_drift(drift)
drift

_update_dom: (time = 'later') ->
if @dom && @moves.length > 0
Expand Down
14 changes: 9 additions & 5 deletions src/Colors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class Colors
_undrift: (code, side_drift) ->
return code unless code

reverse_drift = {}
uncased_drift = {}
for own key, value of side_drift
reverse_drift[value] = key
reverse_drift[value.toLowerCase()] = key.toLowerCase()
uncased_drift[key] = value
uncased_drift[key.toLowerCase()] = value.toLowerCase()

(reverse_drift[char] || char for char in code.split('')).join('')
(uncased_drift[char] || char for char in code.split('')).join('')

DEFAULT_COLORS = {g:'#0d0', b:'#07f', r:'red', o:'orange', y:'yellow', w:'#eee'}
@_set_colors: (overrides, side_drift) ->
Expand All @@ -58,6 +58,10 @@ class Colors
type = {s:'solved', i:'ignored', c:'cube'}[type] || type
result[type] = DEFAULT_COLORS[color] || color

[r, d] = [result, side_drift]
inverted_drift = {}
for own key, value of side_drift
inverted_drift[value] = key

[r, d] = [result, inverted_drift]
[r.U, r.D, r.R, r.L, r.F, r.B] = [r[d.U], r[d.D], r[d.R], r[d.L], r[d.F], r[d.B]]
result
3 changes: 0 additions & 3 deletions src/CompositeMove.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class CompositeMove
track_drift: (side_drift) ->
move.track_drift(side_drift) for move in @moves

track_fwd_drift: (side_drift) ->
move.track_fwd_drift(side_drift) for move in @moves

count: (count_rotations) ->
return 1 if @official_text

Expand Down
7 changes: 0 additions & 7 deletions src/Move.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ class Move
this.undo()

track_drift: (side_drift) ->
for cycle in [@layer.cycle1, @layer.cycle2] when cycle[0].length == 1 # center cycle
for side, location of side_drift
for i in [0..3]
if location == cycle[i]
side_drift[side] = cycle[(i+@turns+4)% 4]

track_fwd_drift: (side_drift) ->
for cycle in [@layer.cycle1, @layer.cycle2] when cycle[0].length == 1 # center cycle
for side, location of side_drift
for i in [0..3]
Expand Down
6 changes: 3 additions & 3 deletions test/Alg_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ describe "Alg", ->
it "#_side_drift", ->
world = null
expect(new Alg("F", world, "")._side_drift()).to.deep.equal(U: 'U', D: 'D', L: 'L', R: 'R', F: 'F', B: 'B')
expect(new Alg("M", world, "")._side_drift()).to.deep.equal(U: 'B', D: 'F', L: 'L', R: 'R', F: 'U', B: 'D')
expect(new Alg("M z", world, "")._side_drift()).to.deep.equal(U: 'L', D: 'R', L: 'F', R: 'B', F: 'U', B: 'D')
expect(new Alg("M", world, "")._side_drift()).to.deep.equal(B: 'U', F: 'D', L: 'L', R: 'R', U: 'F', D: 'B')
expect(new Alg("M z", world, "")._side_drift()).to.deep.equal(L: 'U', R: 'D', F: 'L', B: 'R', U: 'F', D: 'B')
expect(new Alg("MZ", world, "")._side_drift()).to.deep.equal(U: 'D', D: 'U', L: 'L', R: 'R', F: 'B', B: 'F')

it "@side_drift", ->
expect(Alg.side_drift("F")).to.deep.equal(U: 'U', D: 'D', L: 'L', R: 'R', F: 'F', B: 'B')
expect(Alg.side_drift("M")).to.deep.equal(U: 'B', D: 'F', L: 'L', R: 'R', F: 'U', B: 'D')
expect(Alg.side_drift("M")).to.deep.equal(B: 'U', F: 'D', L: 'L', R: 'R', U: 'F', D: 'B')

it "unhand", ->
expect(new Alg("F L2", null, "").unhand()).to.equal("F L2")
Expand Down
2 changes: 1 addition & 1 deletion test/Colors_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe "Colors", ->
expect(colors.to_draw('D', Layer.D).color).to.equal(colors.of(Layer.R))

describe "side drift adjustments", ->
z_drift = {U: 'L', D: 'R', R: 'U', L: 'D', F: 'F', B: 'B'}
z_drift = {L: 'U', R: 'D', U: 'R', D: 'L', F: 'F', B: 'B'}

it "side colors", ->
plain_colors = new Colors(nodrift, "", "", "")
Expand Down

0 comments on commit b9932ce

Please sign in to comment.