Commit 044c1035c1c840632165f9f4be247fadca3c88e3
1 parent
9cb54a8d
Exists in
master
and in
1 other branch
feat✨:机器人随机ID
Showing
4 changed files
with
10 additions
and
5 deletions
Show diff stats
main.go
| ... | ... | @@ -11,6 +11,8 @@ import ( |
| 11 | 11 | "github.com/astaxie/beego" |
| 12 | 12 | "github.com/astaxie/beego/logs" |
| 13 | 13 | "github.com/astaxie/beego/plugins/cors" |
| 14 | + "math/rand" | |
| 15 | + "time" | |
| 14 | 16 | ) |
| 15 | 17 | |
| 16 | 18 | func main() { |
| ... | ... | @@ -42,6 +44,8 @@ func Init() bool { |
| 42 | 44 | |
| 43 | 45 | svconst.AppName = beego.AppConfig.String("appname") |
| 44 | 46 | |
| 47 | + rand.NewSource(time.Now().UnixNano()) | |
| 48 | + | |
| 45 | 49 | svlog.Init() |
| 46 | 50 | |
| 47 | 51 | if beego.BConfig.RunMode != "dev" { | ... | ... |
service/roomrank/dto-room.go
| ... | ... | @@ -8,6 +8,7 @@ import ( |
| 8 | 8 | "encoding/json" |
| 9 | 9 | "fmt" |
| 10 | 10 | "github.com/samber/lo" |
| 11 | + "math/rand" | |
| 11 | 12 | ) |
| 12 | 13 | |
| 13 | 14 | // Room 房间排行持久数据 |
| ... | ... | @@ -46,7 +47,7 @@ type RoomPlayer struct { |
| 46 | 47 | |
| 47 | 48 | func NewRoomRobot(robotConfigId int, userType int) *RoomPlayer { |
| 48 | 49 | d := &RoomPlayer{ |
| 49 | - Uid: 0, | |
| 50 | + Uid: rand.Int63(), | |
| 50 | 51 | Score: 0, |
| 51 | 52 | JoinTime: lxtime.NowUninx(), |
| 52 | 53 | UserType: userType, | ... | ... |
service/roomrank/room.go
| ... | ... | @@ -6,7 +6,7 @@ import ( |
| 6 | 6 | "apigame/util/util-lx/lxalilog" |
| 7 | 7 | "apigame/util/util-lx/lxtime" |
| 8 | 8 | "math" |
| 9 | - "math/rand/v2" | |
| 9 | + "math/rand" | |
| 10 | 10 | "sort" |
| 11 | 11 | ) |
| 12 | 12 | |
| ... | ... | @@ -270,7 +270,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | score := (float64(confRobot.TotalScore-confRobot.MinScore) * |
| 273 | - float64(100-confRobot.TotalRate+rand.IntN(confRobot.TotalRate*2)) / 100) * percent / 100 | |
| 273 | + float64(100-confRobot.TotalRate+rand.Intn(confRobot.TotalRate*2)) / 100) * percent / 100 | |
| 274 | 274 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) |
| 275 | 275 | if result < int64(confRobot.MinScore) { |
| 276 | 276 | result = int64(confRobot.MinScore) |
| ... | ... | @@ -281,7 +281,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro |
| 281 | 281 | // GetRobotScoreMax 从机器人配置里得到最高分 |
| 282 | 282 | func GetRobotScoreMax(confRobot *confroomrank.RobotConfig) int64 { |
| 283 | 283 | score := float64(confRobot.TotalScore-confRobot.MinScore) * |
| 284 | - float64(100-confRobot.TotalRate+rand.IntN(confRobot.TotalRate*2)) / float64(100) | |
| 284 | + float64(100-confRobot.TotalRate+rand.Intn(confRobot.TotalRate*2)) / float64(100) | |
| 285 | 285 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) |
| 286 | 286 | if result < int64(confRobot.MinScore) { |
| 287 | 287 | result = int64(confRobot.MinScore) | ... | ... |