package pptth_config import ( "encoding/json" "fmt" "math/rand" "os" "path/filepath" pptth_json "pptth/json" ) type ReelConfig struct { Normal ReelInfo `json:"normal"` Free ReelInfo `json:"free"` Weight int `json:"weight"` WinFreeSpinCountWeight map[int]int `json:"winFreeSpinCountWeight"` WinFreeSpinCountWeightTotal int } type ReelInfo struct { Hit float64 `json:"hit"` Reel [][]int `json:"reel"` ReelWeight [][]int `json:"reelWeight"` AllWeight []int Col int // 行 Wild []int `json:"wild"` WildWeight []int `json:"wildWeight"` WildWeightTotal int } var ReelConfigs []*ReelConfig var allWeight = 0 var GameConfigs pptth_json.GameConfig var OddConfigs pptth_json.OddConfig func LoadConfig(cfgName string, target any) { rootDir, _ := os.Getwd() cfgDefPath := filepath.Join(rootDir, "../../config/pptth", cfgName) file, err := os.Open(cfgDefPath) if err != nil { fmt.Println("Error opening file:", err) return } defer file.Close() decoder := json.NewDecoder(file) if err := decoder.Decode(target); err != nil { fmt.Println("Error decoding JSON:", err) return } } func Init() { gameConfs := "gameConf.json" oddConfs := "oddConf.json" reelConfs := []string{"rtp_98.json"} LoadConfig(gameConfs, &GameConfigs) LoadConfig(oddConfs, &OddConfigs) for i := 0; i < len(reelConfs); i++ { cfg := &ReelConfig{} LoadConfig(reelConfs[i], &cfg) updateReelWeight(&cfg.Normal) updateReelWeight(&cfg.Free) ReelConfigs = append(ReelConfigs, cfg) allWeight += cfg.Weight cfg.WinFreeSpinCountWeightTotal = 0 for _, value := range cfg.WinFreeSpinCountWeight { cfg.WinFreeSpinCountWeightTotal += value } } } func GetAxisConfig(idx int) (*ReelConfig, int) { if idx == -1 { randin := rand.Intn(allWeight) w := 0 for i := 0; i < len(ReelConfigs); i++ { w += ReelConfigs[i].Weight if w > randin { return ReelConfigs[i], i } } } if idx >= 0 && idx < len(ReelConfigs) { return ReelConfigs[idx], idx } return ReelConfigs[0], 0 } func (s *ReelInfo) Randmon(i int, randin int) []int { w := 0 cards := []int{} for j := 0; j < len(s.ReelWeight[i]); j++ { w += s.ReelWeight[i][j] if w > randin { for m := 0; m < s.Col; m++ { cards = append(cards, s.Reel[i][(j+m)%len(s.Reel[i])]) } break } } return cards } func updateReelWeight(reel *ReelInfo) { reel.Col = 3 reel.AllWeight = make([]int, len(reel.ReelWeight)) for i := 0; i < len(reel.ReelWeight); i++ { reel.AllWeight[i] = 0 for j := 0; j < len(reel.ReelWeight[i]); j++ { reel.AllWeight[i] += reel.ReelWeight[i][j] } } reel.WildWeightTotal = 0 for i := 0; i < len(reel.WildWeight); i++ { reel.WildWeightTotal += reel.WildWeight[i] } }