diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-12-08 14:29:21 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-01-08 16:36:47 +0100 |
commit | 2bc24d10329f5ff9f4bc20a5e790c328abcbe21e (patch) | |
tree | 586e1d9c84e6b62aafacc4bb499a03bca557035f | |
parent | bc9231a030f94f98eb2a0afcbeaea0bb89756b0d (diff) | |
download | table-battles-2bc24d10329f5ff9f4bc20a5e790c328abcbe21e.tar.gz |
eslint
-rw-r--r-- | play.js | 26 | ||||
-rw-r--r-- | rules.js | 113 |
2 files changed, 26 insertions, 113 deletions
@@ -1,5 +1,7 @@ "use strict" +/* global data, view, send_action, action_button, player */ + const wing_name = [ "red", "pink", "blue", "dkblue" ] const reactions = [ "Screen", "Counterattack", "Absorb" ] @@ -133,8 +135,6 @@ function create_formation_slot(id, top) { function create_formation_card(id) { let card = data.cards[id] let e = create_div("card formation " + wing_name[card.wing]) - let e_a1 = null - let e_a2 = null register_action(e, "card", id) @@ -182,9 +182,9 @@ function create_formation_card(id) { } if (card.actions.length >= 1) - e_a1 = create_action(card.actions[0], 1) + create_action(card.actions[0], 1) if (card.actions.length >= 2) - e_a2 = create_action(card.actions[1], 2) + create_action(card.actions[1], 2) if (card.rule_text) append_div(e, "rule_text", card.rule_text) @@ -211,7 +211,7 @@ function create_formation_card(id) { function fill_card_row(top, parent, list) { parent.replaceChildren() for (let id of list) { - let i, n, x + let n, x if (!ui.cards[id]) ui.cards[id] = create_formation_card(id) @@ -357,6 +357,22 @@ for (let i = 0; i < 12; ++i) { register_animation(ui.dice[i], 250) } +function set_has(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 + return true + } + return false +} + function map_get(map, key, missing) { let a = 0 let b = (map.length >> 1) - 1 @@ -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 -} |