richardspirit / mtga_stats

Originated as way to manage Magic The Gathering decks on MGTA so that I knew which decks were performing the best and which decks should be deleted.
GNU Lesser General Public License v3.0
1 stars 0 forks source link

Validator for Gametype #52

Closed richardspirit closed 3 years ago

richardspirit commented 3 years ago

this does not work:

    re, _ := regexp.Compile(`p|b|sr|tsp|tsr|thr|hr|hb|Bot|e`)
    for !re.MatchString(s) {
        fmt.Println("Invalid Entry")
        fmt.Println("Play(p), Brawl(b), Standard Ranked(sr), Traditional Standard Play(tsp), Traditional Standard Ranked(tsr),")
        fmt.Println("Traditional Historic Ranked(thr), Historic Ranked(hr), Historic Brawl(hb), Bot")
        s, _ = reader.ReadString('\n')
        s = strings.TrimSuffix(strings.TrimSuffix(s, "\r"), "\n")
richardspirit commented 3 years ago

Decided to solve this with the following function which eliminates users error

func gametype() (typereturn string) { m := make(map[string]string)

// Set key/value pairs using typical `name[key] = val`
m["k1"] = fmt.Sprintf("%-30s", "Play")
m["k2"] = fmt.Sprintf("%0s", "Brawl")
m["k3"] = fmt.Sprintf("%-30s", "Standard Ranked")
m["k4"] = fmt.Sprintf("%0s", "Traditional Standard Play")
m["k5"] = fmt.Sprintf("%-30s", "Traditional Standard Ranked")
m["k6"] = fmt.Sprintf("%0s", "Traditional Historic Ranked")
m["k7"] = fmt.Sprintf("%-30s", "Historic Ranked")
m["k8"] = fmt.Sprintf("%0s", "Historic Brawl")
m["k9"] = fmt.Sprintf("%-30s", "Bot")
m["k10"] = fmt.Sprintf("%0s", "Event")

fmt.Println("1:", m["k1"], " 2:", m["k2"])
fmt.Println("3:", m["k3"], " 4:", m["k4"])
fmt.Println("5:", m["k5"], " 6:", m["k6"])
fmt.Println("7:", m["k7"], " 8:", m["k8"])
fmt.Println("9:", m["k9"], "10:", m["k10"])

in := bufio.NewScanner(os.Stdin)
in.Scan()
choice, _ := strconv.Atoi(in.Text())

switch choice {
case 1:
    typereturn = "Play"
case 2:
    typereturn = "Brawl"
case 3:
    typereturn = "Standard Ranked"
case 4:
    typereturn = "Traditional Standard Play"
case 5:
    typereturn = "Traditional Standard Ranked"
case 6:
    typereturn = "Traditional Historic Ranked"
case 7:
    typereturn = "Historic Ranked"
case 8:
    typereturn = "Historic Brawl"
case 9:
    typereturn = "Bot"
case 10:
    fmt.Println("Event Name:")
    in.Scan()
    typereturn = in.Text()
    typereturn = strings.TrimSpace(typereturn)
default:
    println("Invalid Entry")
    gametype()
}
return typereturn

}