func ParsePlayers(inputFilename string) []Player { mappedRows := baseutil.MapReader(inputFilename) players := make([]Player, len(mappedRows)) for i, row := range mappedRows { firstName := row["First Name"] lastName := row["Last Name"] gender, err := StringToGender(row["Gender"]) baseutil.Check(err) rating, err := strconv.ParseFloat(row["Balanced Rating"], 32) baseutil.Check(err) players[i] = Player{ Name{firstName, lastName}, float32(rating), gender, uint8(0), []Name{}} } return players }
// ParseBaggages has the side effect of setting the .baggage for all Players func ParseBaggages(inputFilename string, players []Player) { for _, baggage := range baseutil.MapReader(inputFilename) { playerPointer, err := FindPlayer( players, Name{baggage["firstname1"], baggage["lastname1"]}) baseutil.Check(err) playerPointer.baggages = append( playerPointer.baggages, Name{baggage["firstname2"], baggage["lastname2"]}) newLog.Debug("Found baggage of %v for %v", playerPointer.baggages[len(playerPointer.baggages)-1], playerPointer.String()) } }
func NewGame() (state GameState) { // Combine two decks to make our game deck newDeck := deck.NewDeck(false) newDeck2 := deck.NewDeck(false) newDeck.Cards = append(newDeck.Cards, newDeck2.Cards...) newDeck.Shuffle() // All cards start in the stock, and our foundations start empty state.Stock.Cards = newDeck.Cards state.Foundations = make([]deck.Deck, 8) // Populate our tableaus with cards off the stock state.Tableaus = make([]deck.Deck, 10) for i, _ := range state.Tableaus { for j := 0; j < numStartingCardsPerTableau; j++ { card, err := state.popFromStock() baseutil.Check(err) state.Tableaus[i].Cards = append(state.Tableaus[i].Cards, card) } } state.updateScore() return }