Skip to content

Commit

Permalink
add fc_solve_expand_moves_filter_solution_text
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed Dec 2, 2023
1 parent 06ff49a commit 0ce69f8
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
18 changes: 18 additions & 0 deletions fc-solve/site/wml/src/ts/tests/fcs-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down
81 changes: 80 additions & 1 deletion fc-solve/site/wml/src/ts/web-fc-solve--expand-moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");

Expand Down Expand Up @@ -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;
}

0 comments on commit 0ce69f8

Please sign in to comment.