From 0e9e28c2595c1ec46d8601efa6f4d377ee70cb27 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Tue, 11 Nov 2025 17:50:02 +0100 Subject: First version of proposal --- assets/favicon.ipe | 325 +++++++++++++++++++++++++++++++++++++++++++++++++++++ assets/favicon.svg | 19 ++++ favicon.ico | Bin 0 -> 13054 bytes game.mjs | 60 ++++++++-- index.js | 16 +-- player.mjs | 7 +- utils.mjs | 31 ++--- 7 files changed, 425 insertions(+), 33 deletions(-) create mode 100644 assets/favicon.ipe create mode 100644 assets/favicon.svg create mode 100644 favicon.ico diff --git a/assets/favicon.ipe b/assets/favicon.ipe new file mode 100644 index 0000000..5d79b35 --- /dev/null +++ b/assets/favicon.ipe @@ -0,0 +1,325 @@ + + + + + + + +0 0 m +-1 0.333 l +-1 -0.333 l +h + + + + +0 0 m +-1 0.333 l +-1 -0.333 l +h + + + + +0 0 m +-1 0.333 l +-0.8 0 l +-1 -0.333 l +h + + + + +0 0 m +-1 0.333 l +-0.8 0 l +-1 -0.333 l +h + + + + +0.6 0 0 0.6 0 0 e +0.4 0 0 0.4 0 0 e + + + + +0.6 0 0 0.6 0 0 e + + + + + +0.5 0 0 0.5 0 0 e + + +0.6 0 0 0.6 0 0 e +0.4 0 0 0.4 0 0 e + + + + + +-0.6 -0.6 m +0.6 -0.6 l +0.6 0.6 l +-0.6 0.6 l +h +-0.4 -0.4 m +0.4 -0.4 l +0.4 0.4 l +-0.4 0.4 l +h + + + + +-0.6 -0.6 m +0.6 -0.6 l +0.6 0.6 l +-0.6 0.6 l +h + + + + + +-0.5 -0.5 m +0.5 -0.5 l +0.5 0.5 l +-0.5 0.5 l +h + + +-0.6 -0.6 m +0.6 -0.6 l +0.6 0.6 l +-0.6 0.6 l +h +-0.4 -0.4 m +0.4 -0.4 l +0.4 0.4 l +-0.4 0.4 l +h + + + + + + +-0.43 -0.57 m +0.57 0.43 l +0.43 0.57 l +-0.57 -0.43 l +h + + +-0.43 0.57 m +0.57 -0.43 l +0.43 -0.57 l +-0.57 0.43 l +h + + + + + +0 0 m +-1 0.333 l +-1 -0.333 l +h + + + + +0 0 m +-1 0.333 l +-0.8 0 l +-1 -0.333 l +h + + + + +0 0 m +-1 0.333 l +-0.8 0 l +-1 -0.333 l +h + + + + +-1 0.333 m +0 0 l +-1 -0.333 l + + + + +0 0 m +-1 0.333 l +-1 -0.333 l +h +-1 0 m +-2 0.333 l +-2 -0.333 l +h + + + + +0 0 m +-1 0.333 l +-1 -0.333 l +h +-1 0 m +-2 0.333 l +-2 -0.333 l +h + + + + +0.5 0 m +-0.5 0.333 l +-0.5 -0.333 l +h + + + + +0.5 0 m +-0.5 0.333 l +-0.5 -0.333 l +h + + + + +0.5 0 m +-0.5 0.333 l +-0.3 0 l +-0.5 -0.333 l +h + + + + +0.5 0 m +-0.5 0.333 l +-0.3 0 l +-0.5 -0.333 l +h + + + + +1 0 m +0 0.333 l +0 -0.333 l +h +0 0 m +-1 0.333 l +-1 -0.333 l +h + + + + +1 0 m +0 0.333 l +0 -0.333 l +h +0 0 m +-1 0.333 l +-1 -0.333 l +h + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +M + +8 840 m +8 824 l +24 824 l +24 840 l +h + + + diff --git a/assets/favicon.svg b/assets/favicon.svg new file mode 100644 index 0000000..ab0b740 --- /dev/null +++ b/assets/favicon.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..6cb5040 Binary files /dev/null and b/favicon.ico differ diff --git a/game.mjs b/game.mjs index 7b5d4c9..75c4906 100644 --- a/game.mjs +++ b/game.mjs @@ -1,3 +1,5 @@ +import { getMatchCount, shuffle } from "./utils.mjs"; + class Team { constructor(player_1, player_2) { this.player_1 = player_1; @@ -11,7 +13,7 @@ class Team { } } -class Game { +export class Game { constructor(court, team_1, team_2) { this.court_id = court.id; this.court_status = court.status; @@ -29,19 +31,61 @@ class Game { } } +export function generateDummyGames(courts) { + let team = new Team("---", "---"); + let games = []; + for (const court of courts ) { + let game = new Game(court, team, team); + games.push(game); + } + return games; +} + export class Round { - constructor(number, courts) { + constructor(number, games) { this.number = number; - this.courts = courts; + this.games = games; } - render() { - let output = `

Round ${this.number}

`; - let team = new Team("---", "---"); - for (const court of this.courts ) { - let game = new Game(court, team, team); + render(description) { + let heading = typeof description !== 'undefined' ? description : "Round " + this.number; + let output = `

${heading}

CourtTeam 1Team 2
`; + for (const game of this.games ) { output += game.render() } output += "
CourtTeam 1Team 2
"; return output; } +} + +export function proposeGames(players, courts) { + console.log("Proposing new games!"); + let possibleMatches = getMatchCount(players, courts); + let requiredPlayers = possibleMatches * 4; + console.log("Required players are " + requiredPlayers); + const activeCourts = courts.filter(function (c) { return c.status }); + const inactiveCourts = courts.filter(function (c) { return !c.status }); + const activePlayers = players.filter(function (p) { return p.status;}); + console.log("Total reserved courts are " + inactiveCourts.length + "."); + console.log("Total possible matches are " + possibleMatches + "."); + console.log("Active players are:"); + console.log(activePlayers.map((i) => {return i.name;}).join(',')); + const shuffledPlayers = shuffle(activePlayers); + shuffledPlayers.sort((a, b) => a.totalPlayed - b.totalPlayed); + const selectedPlayers = shuffledPlayers.slice(0, requiredPlayers); + selectedPlayers.sort((a, b) => a.level - b.level); + console.log("Selected players are:"); + console.log(selectedPlayers.map((i) => {return i.name;}).join(',')); + console.log("The matches are:"); + let games = []; + for (let index = 0; index < possibleMatches; index++) { + const startIndex = 4 * index; + const endIndex = startIndex + 4; + const courtPlayers = selectedPlayers.slice(startIndex, endIndex); + const team_1 = new Team(courtPlayers[0].name, courtPlayers[3].name); + const team_2 = new Team(courtPlayers[1].name, courtPlayers[2].name); + const game = new Game(activeCourts[index], team_1, team_2); + game.print(); + games.push(game); + } + return games; } \ No newline at end of file diff --git a/index.js b/index.js index 8b146a8..7f39140 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -import { Round } from "./game.mjs"; +import { Round, generateDummyGames, proposeGames } from "./game.mjs"; import { generateCourts } from "./court.mjs"; import { csvToPlayers, generatePlayers } from "./player.mjs"; import { addToggleBehaviour } from "./utils.mjs"; @@ -12,8 +12,8 @@ addToggleBehaviour(courts, "court_"); let regulars = generatePlayers(); addToggleBehaviour(regulars, "regular_"); const fileInput = document.querySelector("#player-load input[type=file]"); - if (fileInput !== null) { - fileInput.onchange = () => { +if (fileInput !== null) { + fileInput.onchange = () => { if (fileInput.files.length > 0) { const file = fileInput.files[0]; if (file) { @@ -27,12 +27,12 @@ const fileInput = document.querySelector("#player-load input[type=file]"); } } } -}; +} // Game handling -let games = new Round(0, courts); -let renderedHTML = games.render(); -document.getElementById("game_list").innerHTML = renderedHTML; +let round = new Round(0, generateDummyGames(courts)); +document.getElementById("game_list").innerHTML = round.render(); document.getElementById("propose").addEventListener("click", () => { - console.log("Propose new games!"); + round = new Round(0, proposeGames(regulars, courts)); + document.getElementById("game_list").innerHTML = round.render(); }) \ No newline at end of file diff --git a/player.mjs b/player.mjs index 75d31d8..91d146a 100644 --- a/player.mjs +++ b/player.mjs @@ -1,9 +1,10 @@ export class Player { - constructor(id, name, level, status) { + constructor(id, name, level, status, totalPlayed) { this.id = id; this.name = name; this.level = typeof level !== 'undefined' ? level : 1; this.status = typeof status !== 'undefined' ? status : false; + this.totalPlayed = typeof totalPlayed !== 'undefined' ? status : 0; } toggle() { this.status = !this.status; @@ -31,7 +32,7 @@ function randomStatus() { export function generatePlayers() { let players = []; for (let i = 0; i < 71; i++) { - players.push(new Player(i, "Player " + i, randomLevel(), randomStatus())); + players.push(new Player(i, "Player " + i, randomLevel(), randomStatus(), 0)); } return players; } @@ -41,7 +42,7 @@ function parseLineToPlayer(data) { var id = Number(info[0].trim()); var name = info[1].trim() + " " + info[2].trim(); var level = Number(info[3].trim()); - return new Player(id, name, level, false); + return new Player(id, name, level, false, 0); } export function csvToPlayers(csv) { diff --git a/utils.mjs b/utils.mjs index 968731c..308bba8 100644 --- a/utils.mjs +++ b/utils.mjs @@ -12,17 +12,20 @@ export function addToggleBehaviour(list, description) { } } -// document.querySelector("#player-load input[type=file]").onchange = () => { -// if (fileInput.files.length > 0) { -// const file = fileInput.files[0]; -// if (file) { -// const reader = new FileReader(); -// reader.onload = function(e) { -// const content = e.target.result; -// regulars = csvToPlayers(content); -// addToggleBehaviour(regulars, "regular_"); -// }; -// reader.readAsText(file); -// } -// } -// } \ No newline at end of file +export function getMatchCount(regulars, courts) { + const activeCourts = courts.filter(function (c) { return c.status }); + console.log("There are a total of " + activeCourts.length + " courts available."); + const activePlayers = regulars.filter(function (p) { return p.status;}); + console.log("There are a total of " + activePlayers.length + " players available."); + var possibleMatches = Math.floor(activePlayers.length / 4); + possibleMatches = possibleMatches > activeCourts.length ? activeCourts.length : possibleMatches; + return possibleMatches; +} + +export function shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; +} \ No newline at end of file -- cgit v1.3.1