2026-02-15 23:17:10 +00:00
|
|
|
package phase10
|
|
|
|
|
|
|
|
|
|
Game :: struct {
|
|
|
|
|
names: [dynamic]string,
|
|
|
|
|
scores: [dynamic][dynamic]int,
|
|
|
|
|
phases: [dynamic]int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteGameData :: proc(game: ^Game) {
|
|
|
|
|
for scorelist in game.scores {
|
|
|
|
|
delete(scorelist)
|
|
|
|
|
}
|
|
|
|
|
delete(game.scores)
|
|
|
|
|
delete(game.names)
|
|
|
|
|
delete(game.phases)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePhases :: proc(game: ^Game) {
|
|
|
|
|
for name, index in game.names {
|
|
|
|
|
phase: int = 1
|
|
|
|
|
for score in game.scores[index] {
|
|
|
|
|
if score < 50 {
|
|
|
|
|
phase += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
game.phases[index] = phase
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addPlayer :: proc(game: ^Game, name: string, score: int = 0, phase: int = 1) {
|
|
|
|
|
append(&game.names, name)
|
|
|
|
|
append(&game.phases, phase)
|
|
|
|
|
// Calculate necesasry score sheet to result in score and phase
|
|
|
|
|
scores: [dynamic]int
|
|
|
|
|
for i := 1; i < phase - 1; i += 1 {
|
|
|
|
|
append(&scores, 0)
|
|
|
|
|
}
|
|
|
|
|
if score >= 50 {
|
|
|
|
|
append(&scores, 0)
|
|
|
|
|
}
|
|
|
|
|
if (phase != 1) {
|
|
|
|
|
append(&scores, score)
|
|
|
|
|
}
|
|
|
|
|
append(&game.scores, scores)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkWinner :: proc(game: ^Game) -> string {
|
|
|
|
|
for player, index in game.names {
|
|
|
|
|
if game.phases[index] > 10 {
|
|
|
|
|
return player
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|