From 26b0b0fda578ff58eae8e854464559057ef0cfe7 Mon Sep 17 00:00:00 2001 From: Ethan Date: Wed, 4 Dec 2019 00:08:55 +1100 Subject: [PATCH] Record "2" moves (eg. L2) as one Turn --- modules/constants.ts | 1 + modules/cube-objects.ts | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/constants.ts b/modules/constants.ts index 185ebc9..5b1efd9 100644 --- a/modules/constants.ts +++ b/modules/constants.ts @@ -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 diff --git a/modules/cube-objects.ts b/modules/cube-objects.ts index add2807..e8e2177 100644 --- a/modules/cube-objects.ts +++ b/modules/cube-objects.ts @@ -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' @@ -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 { @@ -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)) }