Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record "2" moves (eg. L2) as one Turn #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const COLORS: number[] = [WHITE, GREEN, RED, YELLOW, BLUE, ORANGE]

export const CLOCKWISE = 1
export const COUNTER_CLOCKWISE = -1
export const DOUBLE = 2

export const FACE_COUNT = 6
export const PIECES_PER_FACE = 9
Expand Down
7 changes: 3 additions & 4 deletions modules/cube-objects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {COLORS, CLOCKWISE, COUNTER_CLOCKWISE, CORNER_PIECE, EDGE_PIECE, CENTER_PIECE} from './constants'
import {COLORS, CLOCKWISE, COUNTER_CLOCKWISE, CORNER_PIECE, EDGE_PIECE, CENTER_PIECE, DOUBLE} from './constants'

import { getOppositeColor, incrementColor, isOddColor, getLetterForColor, getTerminalColorFunction } from './color-functions'

Expand Down Expand Up @@ -403,7 +403,7 @@ export class Cube {
}

getTurnHistoryAsString (): string {
return this.getTurnHistory().map(turn => [`U`, `F`, `R`, `D`, `B`, `L`][turn.getFace().getId()] + (turn.getDirection() === COUNTER_CLOCKWISE ? `'` : ``)).join(` `)
return this.getTurnHistory().map(turn => [`U`, `F`, `R`, `D`, `B`, `L`][turn.getFace().getId()] + (turn.getDirection() === DOUBLE ? `2` : (turn.getDirection() === COUNTER_CLOCKWISE ? `'` : ``))).join(` `)
}

simplifyTurnHistory (silent = true): void {
Expand Down Expand Up @@ -436,8 +436,7 @@ export class Cube {
if (finalDirection === 0) {
// Do nothing
} else if (finalDirection === 2 || finalDirection === -2) {
newTurnHistory.push(new Turn(turn.getFace(), finalDirection / 2))
newTurnHistory.push(new Turn(turn.getFace(), finalDirection / 2))
newTurnHistory.push(new Turn(turn.getFace(), Math.abs(finalDirection)))
} else {
newTurnHistory.push(new Turn(turn.getFace(), finalDirection))
}
Expand Down