示例#1
0
文件: app.go 项目: uhhhclem/sentinels
func main() {

	flag.IntVar(&pc, "pc", 3, "player count (3-5)")
	flag.IntVar(&lp, "lp", 50, "target loss percent (1-99, default 50")
	flag.IntVar(&rg, "rg", 10, "allowable difficulty variance around target loss percent (0-100, default 10")

	var err error

	if err = validateFlags(); err != nil {
		fmt.Println(err)
		return
	}

	s, i, err := sentinels.FindSetup(pc, lp, rg, []sentinels.ExpansionType{sentinels.BaseSet, sentinels.MiniExpansion})
	if err != nil {
		fmt.Println(err)
		return
	}
	if s != nil {
		fmt.Printf("\nFound in %d iterations:\n\n", i)
		fmt.Printf("%s", s)
	} else {
		fmt.Printf("\nNo setup found in %d iterations.\n", i)
	}

}
示例#2
0
func handler(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case "GET":
		templates.ExecuteTemplate(w, "form.html", "")
	case "POST":
		if m, err := formInts(r, "pc", "lp"); err != nil {
			log.Println(err)
		} else {
			exp := []sentinels.ExpansionType{}
			for i, v := range expansions {
				if r.FormValue(v) == "on" {
					exp = append(exp, sentinels.ExpansionType(i))
				}
			}
			r := &result{}
			if len(exp) == 0 {
				r.Msg = "No card set selected."
			} else {
				r.PC = m["pc"]
				r.LP = m["lp"]
				r.Nump = fmt.Sprintf("%d heroes", m["pc"])
				var err error
				if r.Setup, r.Iterations, err = sentinels.FindSetup(r.PC, r.LP, 10, exp); err != nil {
					r.Msg = err.Error()
				}
			}
			templates.ExecuteTemplate(w, "result.html", r)
		}
	default:
		log.Printf("Unhandled method: %s", r.Method)
	}
}