commit e08a78010c968b66235e334eaec97bfba27d4be2 Author: Hayden Johnson Date: Sun Feb 15 12:58:06 2026 -0800 initial commit diff --git a/main.odin b/main.odin new file mode 100644 index 0000000..7ee89c7 --- /dev/null +++ b/main.odin @@ -0,0 +1,100 @@ +/* + ---------------- + Phase 10 Tracker + ---------------- + + 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 main + +import "core:fmt" +import "core:os" +import "core:mem" +import "core:strings" +import "core:strconv" + +// Return a slice of space delimited strings from stdin +getSpaceDelimetedItems :: proc(backingBuffer: []byte) -> []string { + count, _ := os.read(os.stdin, backingBuffer) + response := string(backingBuffer[:count - 1]) // leave off the newline + items, _ := strings.split(response, " ") + return items +} + +// Prompt user for names of all players +getNames :: proc(backingBuffer: []byte) -> []string { + fmt.print("Enter Names: ") + return getSpaceDelimetedItems(backingBuffer) +} + +// Prompt user to enter scores for each player +addScores :: proc(scores: [][dynamic]int, names: []string) { + buf: [2048]byte + fmt.print(" ") + for name in names { + fmt.print(name, "") + } + fmt.println() + fmt.print("Scores: ") + newScores := getSpaceDelimetedItems(buf[:]) + defer delete(newScores) + for score, index in newScores { + intScore, _ := strconv.parse_int(score) + append(&(scores[index]), intScore) + } +} + +main :: proc() { + // Set up memory tracker + // 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) + // } + + // Prompt for names + buf: [2048]byte + names := getNames(buf[:]) + defer delete(names) + + // Show names to user + for name in names { + fmt.println("Name:", name) + } + + // Create lists of scores for each player. Each element will by a dynamic + // array of scores per player. + scores : [dynamic][dynamic]int + for name in names { + scorelist: [dynamic]int + append(&scores, scorelist) + } + defer { + for scorelist in scores { + delete(scorelist) + } + delete(scores) + } + + // Main loop of adding scores + fmt.println(scores) + addScores(scores[:], names) + addScores(scores[:], names) + addScores(scores[:], names) + fmt.println(scores) +} diff --git a/phase-10-tracker b/phase-10-tracker new file mode 100755 index 0000000..87f92b1 Binary files /dev/null and b/phase-10-tracker differ diff --git a/phase10.odin b/phase10.odin new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/phase10.odin @@ -0,0 +1 @@ +package main