/* ---------------- 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) }