Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
instructr13 committed Oct 20, 2024
1 parent 0d4a17f commit a9aac2c
Show file tree
Hide file tree
Showing 26 changed files with 582 additions and 2,628 deletions.
8 changes: 4 additions & 4 deletions apps/frontend/src/app/routes/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ type GenerationKindStart =
| "column-seq"
| "column-seq-reverse"
| "column-group-shuffle"
| "random-area-reverse"
| "block-swap";
| "random-rectangle-area"
| "random-eclipse-area";

const generationKindStarts: GenerationKindStart[] = [
"all-random",
"gen-random",
"column-seq",
"column-seq-reverse",
"column-group-shuffle",
"random-area-reverse",
"block-swap",
"random-rectangle-area",
"random-eclipse-area",
] as const;

type GenerationKindGoal =
Expand Down
38 changes: 35 additions & 3 deletions apps/solver/src/features/algorithm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class AlgorithmFeature extends FeatureBase {
#tx: ChannelTx<UIMessageEventBase>;
#subscriberCount$: ReadonlyStore<number>;
readonly #solve: SolveFunc;
readonly #solveBeam: SolveFunc = getSolveFunc("vbeam");

constructor(
log: LogLayer,
Expand Down Expand Up @@ -100,19 +101,19 @@ export class AlgorithmFeature extends FeatureBase {

const scope = span(this.log, "Solve finished");

const [answer, finalBoard] = await this.#solve(
const solvePromise = this.#solve(
solvingState.problem,
(workers) => {
this.sendEvent({
eventName: "solve.start",
solveId: solvingState.id,
workers,
workers: workers * 2,
startedAt: solvingState.startedAt,
board: solvingState.problem.board,
general: solvingState.problem.general,
} satisfies SolveStartEvent);

solvingState.workers = workers;
solvingState.workers = workers * 2;
},
async (workerId, answer) => {
this.sendEvent({
Expand All @@ -138,8 +139,39 @@ export class AlgorithmFeature extends FeatureBase {
},
);

const solveBeamPromise = this.#solveBeam(
solvingState.problem,
(workers) => {},
async (workerId, answer) => {
this.sendEvent({
eventName: "solve.progress",
solveId: solvingState.id,
workerId: workerId + 8,
turns: answer.n,
} satisfies SolveProgressEvent);

if (solvingState.currentShortestAnswer === null || answer.n < solvingState.currentShortestAnswer.n) {
solvingState.currentShortestAnswer = answer;

const [, revision] = await this.submitAnswer(solvingState.id, solvingState.problem, answer);

this.log
.withMetadata({
id: solvingState.id,
turns: answer.ops.length,
revision,
})
.info("Answer updated");
}
},
);

scope.end();

const [answer, finalBoard] = (await Promise.all([solvePromise, solveBeamPromise])).toSorted(
(a: [Answer, string[]], b: [Answer, string[]]) => a[0].n - b[0].n,
)[0];

const [correct, revision] = await this.submitAnswer(solvingState.id, solvingState.problem, answer, finalBoard);

this.sendEvent({
Expand Down
Binary file modified bun.lockb
Binary file not shown.
7 changes: 3 additions & 4 deletions packages/algorithm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Answer, Problem } from "@data-maki/schemas";
import { solve as solveV1 } from "./workers/v1.master";
import { solve as solveV2 } from "./workers/v2.master";
import { solve as solveV3 } from "./workers/v3.master";

import { solve as solveVBeam } from "./workers/vbeam.master";
export { easyKatanuki } from "./katanuki";

export const VERSIONS = ["v1", "v2", "v3"] as const;
export const VERSIONS = ["vbeam", "v1", "v2"] as const;

const solveFuncs: { [key in (typeof VERSIONS)[number]]: SolveFunc } = {
vbeam: solveVBeam,
v1: solveV1,
v2: solveV2,
v3: solveV3,
};

export const isSolveFuncVersion = (version: string): version is (typeof VERSIONS)[number] =>
Expand Down
199 changes: 0 additions & 199 deletions packages/algorithm/src/v3/Cargo.lock

This file was deleted.

18 changes: 0 additions & 18 deletions packages/algorithm/src/v3/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion packages/algorithm/src/v3/index.ts

This file was deleted.

55 changes: 0 additions & 55 deletions packages/algorithm/src/v3/pkg/algorithm_v3_wasm.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/algorithm/src/v3/pkg/algorithm_v3_wasm.js

This file was deleted.

Loading

0 comments on commit a9aac2c

Please sign in to comment.