package hp88_config import ( "encoding/json" "fmt" "math/rand" "os" "path/filepath" ) type Config struct { Weight int `json:"weight"` MulDivisor int `json:"mulDivisor"` Reel [][]int `json:"reel"` ReelWeight [][]int `json:"reelWeight"` ReelFree [][]int `json:"reelFree"` ReelFreeWeight [][]int `json:"reelFreeWeight"` Score map[string][]int `json:"score"` CoronaGroupWeight []int `json:"coronaGroupWeight"` ReelHoldSpin []int `json:"reelHoldSpin"` HoldSpinGold []int `json:"holdSpinGold"` HoldSpinGoldWeight []int `json:"holdSpinGoldWeight"` HoldSpinGoldWeightAll int `json:"holdSpinGoldWeightAll"` HoldMajor int `json:"holdMajor"` HoldMajorWeight int `json:"holdMajorWeight"` HoldSpin [][]int `json:"holdSpin"` Jackpot []int `json:"jackpot"` WinLine [][]int `json:"winLine"` BetConf []int `json:"betConf"` BetMul []int `json:"betMul"` } type AxisConfig struct { Reels []*AxisWeight HoldSpin [][]int HoldSpinGold []int HoldSpinGoldWeight []int HoldSpinGoldWeightAll int HoldMajor int HoldMajorWeight int WinLine [][]int Score map[string][]int BetMul []int BetConf []int Jackpot []int CoronaGroupWeight []int MulDivisor int Weight int } type AxisWeight struct { Reel [][]int ReelWeight [][]int AllWeight []int Row int } var ( AxisConfigs []*AxisConfig AllWeight = 0 ) func LoadConfig(cfgName string, target any) { rootDir, _ := os.Getwd() cfgDefPath := filepath.Join(rootDir, "../../config/hp88", 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() { cfs := []string{"rtp_156.json"} for i := 0; i < len(cfs); i++ { cfg := &Config{} LoadConfig(cfs[i], cfg) reels := []*AxisWeight{} reels = append(reels, newAxisWeight(cfg.Reel, cfg.ReelWeight, 3)) reels = append(reels, newAxisWeight(cfg.ReelFree, cfg.ReelFreeWeight, 3)) axisConfig := &AxisConfig{ Reels: reels, Weight: cfg.Weight, HoldSpin: cfg.HoldSpin, HoldSpinGold: cfg.HoldSpinGold, HoldSpinGoldWeight: cfg.HoldSpinGoldWeight, HoldSpinGoldWeightAll: cfg.HoldSpinGoldWeightAll, HoldMajor: cfg.HoldMajor, HoldMajorWeight: cfg.HoldMajorWeight, WinLine: cfg.WinLine, BetMul: cfg.BetMul, BetConf: cfg.BetConf, Jackpot: cfg.Jackpot, CoronaGroupWeight: cfg.CoronaGroupWeight, Score: cfg.Score, MulDivisor: cfg.MulDivisor, } AxisConfigs = append(AxisConfigs, axisConfig) AllWeight += cfg.Weight } } func GetAxisConfig(idx int) (*AxisConfig, int) { if idx == -1 { randin := rand.Intn(AllWeight) w := 0 for i := 0; i < len(AxisConfigs); i++ { w += AxisConfigs[i].Weight if w > randin { return AxisConfigs[i], i } } } if idx >= 0 && idx < len(AxisConfigs) { return AxisConfigs[idx], idx } return AxisConfigs[0], 0 } func newAxisWeight(reel [][]int, reelWeight [][]int, row int) *AxisWeight { r := &AxisWeight{ Reel: reel, ReelWeight: reelWeight, Row: row, } all := make([]int, len(reelWeight)) for i := 0; i < len(reelWeight); i++ { all[i] = 0 for _, w := range reelWeight[i] { all[i] += w } } r.AllWeight = all return r } func (s *AxisWeight) GeneralCards(i int, randin int) []int { w, cards := 0, []int{} for j := 0; j < len(s.ReelWeight[i]); j++ { w += s.ReelWeight[i][j] if w > randin { for m := 0; m < s.Row; m++ { cards = append(cards, s.Reel[i][(j+m)%len(s.Reel[i])]) } break } } return cards }