import { GamesLog } from "./logging/games_log.js"; import { Tournament } from "./tournament/tournament.js"; import { Board } from "./game/board.js"; import { RankingReport } from "./reports/ranking_report.js"; import { BaseError } from "./common_errors/base_error.js"; import { ArgParse } from "./utils/arg_parse.js"; function printUsage() { console.log("Usage: npm start -- boardFile gameLogFile [options]"); console.log(" options:"); console.log(" -h --help Print this message"); console.log(" -m --maxPlayersPerGame Maximum players per game"); console.log(" -d --debug Print stack trace on error"); } async function main() { // Process command line arguments if (ArgParse.getBooleanArg("h", "help")) return printUsage(); const boardFilename = ArgParse.getStringArg(2); if (!boardFilename) return printUsage(); const gameLogFilename = ArgParse.getStringArg(3); if (!gameLogFilename) return printUsage(); const maxPlayersPerGame = ArgParse.getIntegerArg("m", "maxPlayersPerGame") ?? 2; // Set up tournament const board = await Board.loadFromFile(boardFilename); const tournament = new Tournament(board, { maxPlayersPerGame }); // Retrieve game events const gamesLog = new GamesLog(); await gamesLog.loadFile(gameLogFilename); const gameEvents = await gamesLog.readEvents(); // Process game events tournament.processEvents(gameEvents); tournament.requireCompletion(); // Generate and print report const rankingReport = new RankingReport(tournament); rankingReport.printPlayerSummary(); } try { await main(); } catch (err) { if (err instanceof BaseError) { const printTrace = ArgParse.getBooleanArg("d", "debug"); if (printTrace) { console.error(err); } else { console.log(`Error: ${err.message}`); } } else { // Non-Application Error, re-throw throw err; } }