diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 113 |
1 files changed, 5 insertions, 108 deletions
@@ -204,20 +204,6 @@ exports.setup = function (seed, scenario, options) { // === GAME STATE ACCESSORS === -function for_each_front_card(fn) { - for (let c of game.front[0]) - fn(c) - for (let c of game.front[1]) - fn(c) -} - -function for_each_reserve_card(fn) { - for (let c of game.reserve[0]) - fn(c) - for (let c of game.reserve[1]) - fn(c) -} - function card_number(c) { return data.cards[c].number } @@ -335,7 +321,7 @@ function is_card_attack_with_target_in_play(c) { for (let a of data.cards[c].actions) { if (a.type === "Attack") { for (let t of a.target_list) - if (is_card_in_play(c)) + if (is_card_in_play(t)) return true } } @@ -354,7 +340,7 @@ function check_impossible_to_attack_victory() { } function check_morale_loss(p) { - return game.morale[0] === 0 + return game.morale[p] === 0 } // === ROLL PHASE === @@ -705,7 +691,7 @@ function gen_doubles(c) { gen_pool_die(v) } -function gen_triples() { +function gen_triples(c) { for (let v = 1; v <= 6; ++v) if (check_single_count(c, v, 3)) gen_pool_die(v) @@ -877,7 +863,7 @@ function has_any_cubes_on_card(c) { return map_get(game.cubes, c, 0) >= 1 } -function count_dice_on_card(c, v) { +function count_dice_on_card(c) { let n = 0 for (let i = 0; i < 12; ++i) if (get_dice_location(i) === c) @@ -1142,7 +1128,7 @@ states.bombard = { }, } -function goto_attack(c) { +function goto_attack() { let a = current_action() game.state = "attack" game.target = find_target_of_attack(a) @@ -1742,16 +1728,6 @@ function random(range) { return (game.seed = Number(BigInt(game.seed) * 5667072534355537n % 9007199254740881n)) % range } -function shuffle(list) { - // Fisher-Yates shuffle - for (let i = list.length - 1; i > 0; --i) { - let j = random(i + 1) - let tmp = list[j] - list[j] = list[i] - list[i] = tmp - } -} - // Fast deep copy for objects without cycles function object_copy(original) { if (Array.isArray(original)) { @@ -1787,26 +1763,12 @@ function array_remove(array, index) { array.length = n - 1 } -function array_remove_item(array, item) { - let n = array.length - for (let i = 0; i < n; ++i) - if (array[i] === item) - return array_remove(array, i) -} - function array_insert(array, index, item) { for (let i = array.length; i > index; --i) array[i] = array[i - 1] array[index] = item } -function array_remove_pair(array, index) { - let n = array.length - for (let i = index + 2; i < n; ++i) - array[i - 2] = array[i] - array.length = n - 2 -} - function array_insert_pair(array, index, key, value) { for (let i = array.length; i > index; i -= 2) { array[i] = array[i-2] @@ -1818,10 +1780,6 @@ function array_insert_pair(array, index, key, value) { // Set as plain sorted array -function set_clear(set) { - set.length = 0 -} - function set_has(set, item) { let a = 0 let b = set.length - 1 @@ -1871,24 +1829,6 @@ function set_delete(set, item) { } } -function set_toggle(set, item) { - let a = 0 - let b = set.length - 1 - while (a <= b) { - let m = (a + b) >> 1 - let x = set[m] - if (item < x) - b = m - 1 - else if (item > x) - a = m + 1 - else { - array_remove(set, m) - return - } - } - array_insert(set, a, item) -} - // Map as plain sorted array of key/value pairs function map_clear(map) { @@ -1944,46 +1884,3 @@ function map_set(map, key, value) { } array_insert_pair(map, a<<1, key, value) } - -function map_delete(map, item) { - let a = 0 - let b = (map.length >> 1) - 1 - while (a <= b) { - let m = (a + b) >> 1 - let x = map[m<<1] - if (item < x) - b = m - 1 - else if (item > x) - a = m + 1 - else { - array_remove_pair(map, m<<1) - return - } - } -} - -function object_diff(a, b) { - if (a === b) - return false - if (a !== null && b !== null && typeof a === "object" && typeof b === "object") { - if (Array.isArray(a)) { - if (!Array.isArray(b)) - return true - let a_length = a.length - if (b.length !== a_length) - return true - for (let i = 0; i < a_length; ++i) - if (object_diff(a[i], b[i])) - return true - return false - } - for (let key in a) - if (object_diff(a[key], b[key])) - return true - for (let key in b) - if (!(key in a)) - return true - return false - } - return true -} |