Skip to content

Commit

Permalink
fix build; typescript web-fc-solve *.ts sources
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed Jan 19, 2025
1 parent f0df769 commit 9219898
Show file tree
Hide file tree
Showing 15 changed files with 1,052 additions and 350 deletions.
3 changes: 3 additions & 0 deletions bin/copy-web-fc-solve.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
# Distributed under the terms of the MIT license.
#

set -e -x

fcs_site="${FC_SOLVE_SITE:-/home/shlomif/progs/freecell/git/fc-solve/fc-solve/site/wml}"
cp -f "$fcs_site"/dest/js/lib{freecell,fcs-wrap}* ext/libfreecell-solver/
cp -f "$fcs_site"/src/ts/{capitalize-cards,fcs-validate,web-fc-solve--expand-moves,web-fc-solve,web-fcs-api-base}.ts src/ts/
2 changes: 1 addition & 1 deletion docs/js/all-min.js

Large diffs are not rendered by default.

353 changes: 268 additions & 85 deletions docs/js/all.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/js/combined-min.js

Large diffs are not rendered by default.

51 changes: 2 additions & 49 deletions docs/js/fcs-validate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
define(["require", "exports", "./prange", "./french-cards"], function (require, exports, prange_1, french_cards_1) {
define(["require", "exports", "./prange", "./french-cards", "./capitalize-cards"], function (require, exports, prange_1, french_cards_1, capitalize_cards_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BoardParseResult = exports.ParseErrorType = exports.ErrorLocationType = exports.Foundations = exports.suits__str_to_int = exports.MAX_RANK = exports.MIN_RANK = exports.NUM_SUITS = exports.ranks__str_to_int = void 0;
exports.capitalize_cards = capitalize_cards;
exports.fcs_js__card_from_string = fcs_js__card_from_string;
exports.fcs_js__column_from_string = fcs_js__column_from_string;
exports.fcs_js__freecells_from_string = fcs_js__freecells_from_string;
Expand Down Expand Up @@ -66,52 +65,6 @@ define(["require", "exports", "./prange", "./french-cards"], function (require,
french_cards_1.suits__int_to_str.substring(this.suit, this.suit + 1));
}
}
class BoardTextLine {
constructor(line) {
this.line = line;
const that = this;
const m1 = line.match(/^([^\n\r]*)([\n\r]*)$/);
that.newline = m1[2];
let l = m1[1];
if (m1[1].match(/#/)) {
const m2 = m1[1].match(/^(.*?)(#.*)/);
that.comment = m2[2];
l = m2[1];
}
else {
that.comment = "";
}
if (l.match(/:/)) {
const m3 = l.match(/^([^:]*:)(.*)/);
that.prefix = m3[1];
that.content = m3[2];
}
else {
that.prefix = "";
that.content = l;
}
return;
}
getContent() {
return this.content;
}
capitalize() {
const that = this;
const ret = that.prefix +
that.getContent().toUpperCase() +
that.comment +
that.newline;
return ret;
}
}
function capitalize_cards(board) {
return board
.match(/[^\n]*\n?/g)
.map((l) => {
return new BoardTextLine(l).capitalize();
})
.join("");
}
class Column {
constructor(cards) {
this.cards = cards;
Expand Down Expand Up @@ -490,7 +443,7 @@ define(["require", "exports", "./prange", "./french-cards"], function (require,
this.is_valid = true;
const that = this;
const lines = orig_s.match(/[^\n]*\n?/g).map((l) => {
return new BoardTextLine(l);
return new capitalize_cards_1.BoardTextLine(l);
});
for (const l of lines) {
{
Expand Down
73 changes: 70 additions & 3 deletions docs/js/web-fc-solve--expand-moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fc_solve_expand_move = fc_solve_expand_move;
exports.fc_solve_expand_moves_filter_solution_text = fc_solve_expand_moves_filter_solution_text;
function _to_int(s) {
return parseInt(s, 10);
}
Expand Down Expand Up @@ -95,7 +96,13 @@ define(["require", "exports"], function (require, exports) {
"\n" +
expander.modified_state.c
.map((col) => {
return ": " + col.join(" ") + "\n";
return (":" +
col
.map((card) => {
return " " + card;
})
.join("") +
"\n");
})
.join("");
expander.ret_array.push({
Expand Down Expand Up @@ -192,13 +199,19 @@ define(["require", "exports"], function (require, exports) {
}
function fc_solve_expand_move(num_stacks, num_freecells, initial_src_state_str, initial_move, initial_dest_state_str) {
const matched = initial_move.str.match(/^Move ([0-9]+) cards from stack ([0-9]+) to stack ([0-9]+)$/);
const raw_ret = [
{
str: initial_move.str,
type: "m",
},
];
if (!matched) {
return [initial_move];
return raw_ret;
}
const ultimate_num_cards = _to_int(matched[1]);
// TODO : Implement the case where the sequence move is unlimited.
if (ultimate_num_cards === 1) {
return [initial_move];
return raw_ret;
}
const ultimate_source = _to_int(matched[2]);
const ultimate_dest = _to_int(matched[3]);
Expand All @@ -208,4 +221,58 @@ define(["require", "exports"], function (require, exports) {
expander.recursive_move(ultimate_source, ultimate_dest, ultimate_num_cards, expander.empty_stack_indexes);
return expander.ret_array;
}
function fc_solve_expand_moves_filter_solution_text(num_stacks, num_freecells, initial_str) {
const founds_pat = "^Foundations:[^\\n]*\\n";
const freecells_pat = "^Freecells:[^\\n]*\\n";
const move_line_pat = "^Move (?:[2-9][0-9]*|1[0-9]+) cards from stack [0-9]+ to stack [0-9]+$";
const board_pat = founds_pat + freecells_pat + "(?:^:[^\\n]*\\n)+";
const board2move_sep = "\n\n====================\n\n";
const move2board_sep = "\n";
const move2board_sep4output = "\n\n";
const re = new RegExp("(" +
board_pat +
")" +
board2move_sep +
"(" +
move_line_pat +
")" +
"\\n" +
move2board_sep +
"(?=" +
"(" +
board_pat +
")" +
")", "gms");
let expanded_sol = initial_str;
let changes = 0;
do {
changes = 0;
expanded_sol = expanded_sol.replace(re, function replacer(match, initial_str, move, fin) {
++changes;
let ret = "";
const arr = fc_solve_expand_move(num_stacks, num_freecells, initial_str, { str: move }, fin);
ret += initial_str;
ret += board2move_sep;
let i;
for (i = 0; i < arr.length - 1; i += 2) {
const m_elem = arr[i];
if (m_elem.type != "m") {
throw "wrong KI.T ''" + m_elem.type + "''";
}
ret += m_elem.str;
ret += move2board_sep4output;
const s_elem = arr[i + 1];
if (s_elem.type != "s") {
throw "wrong K[I+1].T ''" + s_elem.type + "''";
}
ret += s_elem.str;
ret += board2move_sep;
}
ret += arr[i].str;
ret += move2board_sep4output;
return ret;
});
} while (changes != 0);
return expanded_sol;
}
});
Loading

0 comments on commit 9219898

Please sign in to comment.