From 0ce69f886f59a4281e685ab3eb05780177d4948d Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 2 Dec 2023 20:13:15 +0200 Subject: [PATCH] add fc_solve_expand_moves_filter_solution_text --- fc-solve/site/wml/src/ts/tests/fcs-core.ts | 18 +++++ .../wml/src/ts/web-fc-solve--expand-moves.ts | 81 ++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/fc-solve/site/wml/src/ts/tests/fcs-core.ts b/fc-solve/site/wml/src/ts/tests/fcs-core.ts index 112090536..7f3add9d5 100644 --- a/fc-solve/site/wml/src/ts/tests/fcs-core.ts +++ b/fc-solve/site/wml/src/ts/tests/fcs-core.ts @@ -7,6 +7,7 @@ import * as s2i from "../s2ints_js"; import Module from "../libfcs-wrap"; import * as w from "../web-fc-solve"; +import * as expander from "../web-fc-solve--expand-moves"; import * as deal_finder from "../find-fc-deal"; import * as test_strings from "../web-fcs-tests-strings"; import { perl_range } from "../prange"; @@ -521,6 +522,23 @@ function my_func(qunit: QUnit, _my_mod, my_callback: () => void) { assert.equal(ret, 0, "bh_free ret"); } }); + qunit.test("expand-sol-text", (assert) => { + assert.expect(2); + + const ret_str = expander.fc_solve_expand_moves_filter_solution_text( + 8, + 4, + solution_for_deal_24__default, + ); + // TEST + assert.ok(true, "True is, well, true."); + // TEST + assert.equal( + ret_str, + solution_for_deal_24__expanded_moves, + "Freecell_Deal_Finder", + ); + }); }); my_callback(); diff --git a/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts b/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts index c092f8649..d322a69bd 100644 --- a/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts +++ b/fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts @@ -123,7 +123,15 @@ class Expander { "\n" + expander.modified_state.c .map((col) => { - return ": " + col.join(" ") + "\n"; + return ( + ":" + + col + .map((card) => { + return " " + card; + }) + .join("") + + "\n" + ); }) .join(""); @@ -304,3 +312,74 @@ export function fc_solve_expand_move( return expander.ret_array; } + +export function fc_solve_expand_moves_filter_solution_text( + num_stacks: number, + num_freecells: number, + initial_str: string, +): string { + const fo = "^Foundations:[^\\n]*\\n"; + const fc = "^Freecells:[^\\n]*\\n"; + const m = + "^Move (?:[2-9][0-9]*|1[0-9]+) cards from stack [0-9]+ to stack [0-9]+$"; + const bo = fo + fc + "(?:^:[^\\n]*\\n)+"; + const b2m = "\n\n====================\n\n"; + const m2b = "\n"; + const m2bout = "\n\n"; + let ret_str = initial_str; + let changes = 0; + do { + changes = 0; + ret_str = ret_str.replace( + new RegExp( + "(" + + bo + + ")" + + b2m + + "(" + + m + + ")" + + "\\n" + + m2b + + "(?=" + + "(" + + bo + + ")" + + ")", + "gms", + ), + function replacer(match, initial_str, move, fin) { + ++changes; + let r = ""; + let arr = fc_solve_expand_move( + num_stacks, + num_freecells, + initial_str, + { str: move }, + fin, + ); + r += initial_str; + r += b2m; + let i; + // arr.pop(); + for (i = 0; i < arr.length - 1; i += 2) { + if (arr[i].type != "m") { + throw "wrong KI.T ''" + arr[i].type + "''"; + } + if (arr[i + 1].type != "s") { + throw "wrong m"; + } + r += arr[i].str; + r += m2bout; + r += arr[i + 1].str; + r += b2m; + } + r += arr[i].str; + r += m2bout; + return r; + }, + ); + } while (changes != 0); + + return ret_str; +}