Skip to content

Commit

Permalink
Bump the number of supported moves for the simultaneous move indexer …
Browse files Browse the repository at this point in the history
…up to 256.

Closes #325

This also fixes the calculation to prevent URLs like https://alpha.twizzle.net/edit/?alg=%28R+L%27%29+%28.%2910000000 from failing to load.
  • Loading branch information
lgarron committed Mar 21, 2024
1 parent 180a844 commit 85fd58f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/cubing/notation/CountMoves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,50 @@ class CountMoves extends TraversalUp<number> {
}
}

// TODO
class CountLeavesInExpansionForSimultaneousMoveIndexer extends TraversalUp<number> {
public traverseAlg(alg: Alg): number {
let r = 0;
for (const algNode of alg.childAlgNodes()) {
r += this.traverseAlgNode(algNode);
}
return r;
}

public traverseGrouping(grouping: Grouping): number {
const alg: Alg = grouping.alg;
return this.traverseAlg(alg) * Math.abs(grouping.amount);
}

public traverseMove(move: Move): number {
return 1;
}

public traverseCommutator(commutator: Commutator): number {
return (
2 * (this.traverseAlg(commutator.A) + this.traverseAlg(commutator.B))
);
}

public traverseConjugate(conjugate: Conjugate): number {
return 2 * this.traverseAlg(conjugate.A) + this.traverseAlg(conjugate.B);
}

// TODO: Remove spaces between repeated pauses (in traverseSequence)
public traversePause(_pause: Pause): number {
return 1;
}

public traverseNewline(_newLine: Newline): number {
return 1;
}

// TODO: Enforce being followed by a newline (or the end of the alg)?
public traverseLineComment(_comment: LineComment): number {
return 1;
}
}

function isCharUppercase(c: string): boolean {
return "A" <= c && c <= "Z";
}
Expand Down Expand Up @@ -120,6 +164,11 @@ export const countRangeBlockMovesPG = functionFromTraversal(CountMoves, [
rangeBlockTurnMetric,
]);

export const countLeavesInExpansionForSimultaneousMoveIndexer =
functionFromTraversal(CountLeavesInExpansionForSimultaneousMoveIndexer, [
baseMetric,
]);

/**
* Only implemented so far:
*
Expand Down
1 change: 1 addition & 0 deletions src/cubing/notation/cubing-private/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { countLeavesInExpansionForSimultaneousMoveIndexer } from "../CountMoves";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AlgIndexer } from "../../../..";
import type { Alg } from "../../../../../alg";
import type { KPuzzle } from "../../../../../kpuzzle";
import { experimentalCountMoves } from "../../../../../notation";
import { countLeavesInExpansionForSimultaneousMoveIndexer } from "../../../../../notation/CountMoves";
import { SimpleAlgIndexer } from "../../../../controllers/indexer/SimpleAlgIndexer";
import { SimultaneousMoveIndexer } from "../../../../controllers/indexer/simultaneous-moves/SimultaneousMoveIndexer";
import { TreeAlgIndexer } from "../../../../controllers/indexer/tree/TreeAlgIndexer";
Expand All @@ -20,6 +20,9 @@ interface IndexerConstructorPropInputs {
indexerConstructorRequest: IndexerStrategyName;
}

// `SimultaneousMoveIndexer` is currently not optimized and has to expand the alg. This bounds the number of moves in the expanded alg.
const SIMULTANEOUS_INDEXER_MAX_EXPANDED_LEAVES = 256;

// TODO: Also handle PG3D vs. 3D
export class IndexerConstructorProp extends TwistyPropDerived<
IndexerConstructorPropInputs,
Expand All @@ -29,7 +32,8 @@ export class IndexerConstructorProp extends TwistyPropDerived<
switch (inputs.indexerConstructorRequest) {
case "auto":
if (
experimentalCountMoves(inputs.alg.alg) < 100 &&
countLeavesInExpansionForSimultaneousMoveIndexer(inputs.alg.alg) <=
SIMULTANEOUS_INDEXER_MAX_EXPANDED_LEAVES &&
inputs.puzzle === "3x3x3" &&
inputs.visualizationStrategy === "Cube3D"
) {
Expand Down

0 comments on commit 85fd58f

Please sign in to comment.