diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-11-24 21:23:56 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-25 17:37:12 +0100 |
commit | 83835ea22d7e169f80d8740ce8a542103257d173 (patch) | |
tree | 24744e958aca45e583563ed6db9c58194dcd0b5c /tools/patchgame.js | |
parent | 1fd20db73895cf1ca8fab9cf2c7d288d3bcc1c92 (diff) | |
download | server-83835ea22d7e169f80d8740ce8a542103257d173.tar.gz |
Remove obsolete tools and update other tools.
Diffstat (limited to 'tools/patchgame.js')
-rw-r--r-- | tools/patchgame.js | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/tools/patchgame.js b/tools/patchgame.js index 9b63f4f..167aca9 100644 --- a/tools/patchgame.js +++ b/tools/patchgame.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +const VERIFY = true + const fs = require('fs') const sqlite3 = require('better-sqlite3') @@ -20,8 +22,8 @@ fs.writeFileSync("backup-" + game_id + ".txt", save) function is_valid_action(rules, game, role, action, a) { if (action !== 'undo') - if (game.active !== role && game.active !== "Both" && game.active !== "All") - return false + if (game.active !== role && game.active !== "Both" && game.active !== "All") + return false let view = rules.view(game, role) let va = view.actions[action] if (va === undefined) @@ -47,27 +49,27 @@ try { game = rules.resign(game, item.role) else { console.log("ACTION", i, game.seed, game.state, game.active, ">", item.role, item.action, item.arguments) - if (1) - if (!is_valid_action(rules, game, item.role, item.action, args)) { - console.log(`invalid action: ${item.role} ${item.action} ${item.arguments}`) - console.log("\t", game.state, game.active, JSON.stringify(rules.view(game, item.role).actions)) - throw "invalid action" + if (VERIFY) { + if (!is_valid_action(rules, game, item.role, item.action, args)) { + console.log(`invalid action: ${item.role} ${item.action} ${item.arguments}`) + console.log("\t", game.state, game.active, JSON.stringify(rules.view(game, item.role).actions)) + throw "invalid action" + } } game = rules.action(game, item.role, item.action, args) } ++i }) + console.log("SUCCESS %d", log.length) + db.prepare("update game_state set active=?, state=? where game_id=?").run(game.active, JSON.stringify(game), game_id) } catch (err) { console.log("FAILED %d/%d", i+1, log.length) console.log(err) - game.log=undefined - game.undo=undefined - //console.log(JSON.stringify(game,0,4)) + delete game.log + delete game.undo console.log(game) } -db.prepare("update game_state set active=?, state=? where game_id=?").run(game.active, JSON.stringify(game), game_id) - if (i < log.length) { console.log("BROKEN ENTRIES: %d", log.length-i) console.log(`sqlite3 db "delete from game_replay where game_id=${game_id} and replay_id>=${log[i].replay_id}"`) |