修复大乱斗问题
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
昔念
2026-02-20 09:40:22 +08:00
parent 58440d5993
commit 53b18cfd0c
6 changed files with 37 additions and 17 deletions

View File

@@ -1,7 +1,24 @@
package input
import "blazing/logic/service/fight/info"
import (
"blazing/logic/service/fight/info"
"math/rand"
"time"
)
// Shuffle 打乱切片顺序,使用 Fisher-Yates 洗牌算法,泛型支持任意类型
func Shuffle[T any](slice []T) {
// 初始化随机数生成器,用当前时间作为种子,避免每次打乱结果相同
r := rand.New(rand.NewSource(time.Now().UnixNano()))
// 从后往前遍历,逐个交换
for i := len(slice) - 1; i > 0; i-- {
// 生成 0 到 i 之间的随机索引
j := r.Intn(i + 1)
// 交换 i 和 j 位置的元素
slice[i], slice[j] = slice[j], slice[i]
}
}
func (our *Input) GetAction() {
next := our.Exec(func(t Effect) bool {
@@ -58,6 +75,7 @@ func (our *Input) GetAction() {
}
}
Shuffle(skills)
if usedskill == nil {
for _, s := range skills {