phase-10-tracker/main.odin

76 lines
2.1 KiB
Odin

/*
----------------
Phase 10 Tracker
----------------
Author: Hayden Johnson
This program helps the user keep track of a game of Phase 10 as it is being
played. It will keep track of players and their scores over the course of the
game, inferring which phase they are on based on their score.
To use the program, first you will input the first names of all of the
players, seperated by spaces. Then, after each round is finished, you will
enter the score of each player's hand, again seperated by spaces and in the
same order that the names were supplied.
*/
package phase10
import "core:os"
import "core:fmt"
import "core:mem"
main :: proc() {
// Memory tracking when building in debug mode
when ODIN_DEBUG {
track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, context.allocator)
context.allocator = mem.tracking_allocator(&track)
defer {
if len(track.allocation_map) > 0 {
fmt.eprintf(
"=== %v allocations not freed: ===\n",
len(track.allocation_map)
)
for _, entry in track.allocation_map {
fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location)
}
}
mem.tracking_allocator_destroy(&track)
}
}
// Create game
game: Game
if len(os.args) > 1 {
importGame(&game, os.args[1])
} else {
// Prompt for names
buf: [2048]byte
names := getNames(buf[:])
defer delete(names)
for name in names {
addPlayer(&game, name)
}
}
defer deleteGameData(&game) // Clean up game data
// Main game loop
printGame(&game)
winner: int = checkWinner(&game)
for winner == -1 {
addScores(&game)
updatePhasesByScores(&game)
printGame(&game)
winner = checkWinner(&game)
exportGame(&game, "game.csv")
}
// Print winner and export game
fmt.printfln(
"%v wins! They had %v points!",
game.names[winner],
getScore(&game, winner)
)
}