// NewAlphaStrategy initializes and returns a new AlphaStrategy given random seed

NewAlphaStrategy initializes and returns a new AlphaStrategy given random seed
// NewAlphaStrategy initializes and returns a new AlphaStrategy given random seed
func NewAlphaStrategy(seed int64, discount, epsilon, learningRate float64) *AlphaStrategy {
	source := rand.NewSource(seed)
	r := rand.New(source)
	numberOfActions := (len(tdef.AllTowers)+len(tdef.AllTroops))*3 + 1
	actionIDs := makeRange(0, numberOfActions)
	weights := make([]float64, numberOfActions)
	if _, err := os.Stat(alphaStrategySaveFileName); os.IsNotExist(err) || !os.IsExist(err) {
		for i := range weights {
			weights[i] = float64(1 / numberOfActions)
		}
		fp, err := os.Create(alphaStrategySaveFileName)
		fp.Close()
		if err != nil {
			log.Println("Could create model file")
		}
	} else {
		b, _ := ioutil.ReadFile(alphaStrategySaveFileName)
		data := strings.Split(string(b), "\n")
		for i, d := range data {
			w, err := strconv.ParseFloat(d, 64)
			if err != nil {
				log.Printf("Error reading model file: '%s'\n", d)
				weights[i] = float64(1 / numberOfActions)
			} else {
				weights[i] = w
			}
		}
	}
	s := AlphaStrategy{0, weights, false, -1, nil, -1, numberOfActions, actionIDs, r, discount,
		epsilon, learningRate}
	return &s
}
func NewAlphaStrategy ( seed int64 , discount , epsilon , learningRate float64 ) * AlphaStrategy { source := rand . NewSource ( seed ) r := rand . New ( source ) numberOfActions := ( len ( tdef . AllTowers ) + len ( tdef . AllTroops ) ) * 3 + 1 actionIDs := makeRange ( 0 , numberOfActions ) weights := make ( [ ] float64 , numberOfActions ) if _ , err := os . Stat ( alphaStrategySaveFileName ) ; os . IsNotExist ( err ) || ! os . IsExist ( err ) { for i := range weights { weights [ i ] = float64 ( 1 / numberOfActions ) } fp , err := os . Create ( alphaStrategySaveFileName ) fp . Close ( ) if err != nil { log . Println ( " " ) } } else { b , _ := ioutil . ReadFile ( alphaStrategySaveFileName ) data := strings . Split ( string ( b ) , " \n " ) for i , d := range data { w , err := strconv . ParseFloat ( d , 64 ) if err != nil { log . Printf ( " \n " , d ) weights [ i ] = float64 ( 1 / numberOfActions ) } else { weights [ i ] = w } } } s := AlphaStrategy { 0 , weights , false , - 1 , nil , - 1 , numberOfActions , actionIDs , r , discount , epsilon , learningRate } return & s }
NewAlphaStrategy initializes and returns a new AlphaStrategy given random seed
NewAlphaStrategy initializes and returns a new AlphaStrategy given random seed