2026-02-15 20:58:06 +00:00
|
|
|
/*
|
|
|
|
|
----------------
|
|
|
|
|
Phase 10 Tracker
|
|
|
|
|
----------------
|
2026-02-20 04:38:25 +00:00
|
|
|
Author: Hayden Johnson
|
2026-02-15 20:58:06 +00:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2026-02-15 23:17:10 +00:00
|
|
|
package phase10
|
2026-02-15 20:58:06 +00:00
|
|
|
|
2026-02-20 04:38:25 +00:00
|
|
|
import "core:os"
|
2026-02-15 20:58:06 +00:00
|
|
|
import "core:fmt"
|
2026-02-20 04:38:25 +00:00
|
|
|
import "core:mem"
|
2026-02-15 20:58:06 +00:00
|
|
|
|
|
|
|
|
main :: proc() {
|
2026-02-20 04:38:25 +00:00
|
|
|
// 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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-15 23:17:10 +00:00
|
|
|
// Create game
|
|
|
|
|
game: Game
|
2026-02-20 05:10:23 +00:00
|
|
|
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)
|
|
|
|
|
}
|
2026-02-15 20:58:06 +00:00
|
|
|
}
|
2026-02-15 23:17:10 +00:00
|
|
|
defer deleteGameData(&game) // Clean up game data
|
2026-02-15 20:58:06 +00:00
|
|
|
|
2026-02-16 01:30:11 +00:00
|
|
|
// Main game loop
|
|
|
|
|
printGame(&game)
|
2026-02-20 05:10:23 +00:00
|
|
|
winner: int = checkWinner(&game)
|
2026-02-16 01:30:11 +00:00
|
|
|
for winner == -1 {
|
2026-02-15 23:17:10 +00:00
|
|
|
addScores(&game)
|
2026-02-16 01:30:11 +00:00
|
|
|
updatePhasesByScores(&game)
|
|
|
|
|
printGame(&game)
|
2026-02-15 23:17:10 +00:00
|
|
|
winner = checkWinner(&game)
|
2026-02-20 05:13:31 +00:00
|
|
|
exportGame(&game, "game.csv")
|
2026-02-15 23:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 04:38:25 +00:00
|
|
|
// Print winner and export game
|
2026-02-18 21:50:34 +00:00
|
|
|
fmt.printfln(
|
|
|
|
|
"%v wins! They had %v points!",
|
|
|
|
|
game.names[winner],
|
|
|
|
|
getScore(&game, winner)
|
|
|
|
|
)
|
2026-02-15 20:58:06 +00:00
|
|
|
}
|