Skip to content

Commit

Permalink
Update utils.go
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy0411 authored Aug 29, 2024
1 parent e65f816 commit 78669d5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions plugin/niuniu/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package niuniu

import (
"fmt"
"github.com/shopspring/decimal"
"math"
"math/rand"
"time"
)

func generateRandomStingTwo(niuniu float64) (string, float64) {
probability := rand.Intn(100 + 1)
reduce := math.Abs(hitGlue(decimal.NewFromFloat(niuniu)))
reduce := math.Abs(hitGlue(niuniu))
switch {
case probability <= 40:
niuniu += reduce
Expand Down Expand Up @@ -138,13 +137,18 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) {
func determineResultBySkill(myLength, oppoLength float64) (string, float64, float64) {
probability := rand.Intn(100) + 1
winProbability := calculateWinProbability(myLength, oppoLength) * 100
return applySkill(myLength, oppoLength, 0 < probability && float64(probability) <= winProbability)
return applySkill(myLength, oppoLength,
0 < probability && float64(probability) <= winProbability)
}

// calculateWinProbability 计算胜率
func calculateWinProbability(heightA, heightB float64) float64 {
//第一个接收参数初始概率
pA := 0.9
var pA float64
if heightA > heightB {
pA = 0.7 + 0.2*(heightA-heightB)/heightA
} else {
pA = 0.6 - 0.2*(heightB-heightA)/heightB
}
heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB)
reductionRate := 0.1 * (heightRatio - 1)
reduction := pA * reductionRate
Expand All @@ -158,7 +162,6 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
if increaseLength1 {
myLength += reduce
oppoLength -= 0.8 * reduce

if myLength < 0 {
return fmt.Sprintf("哦吼!?你的牛牛在长大欸!长大了%.2fcm!", reduce), myLength, oppoLength
}
Expand All @@ -174,7 +177,7 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo

}

// fence 简单模拟击剑技巧效果
// fence
func fence(rd float64) float64 {
rd -= float64(time.Now().UnixNano() % 10)
if rd > 1000000 {
Expand All @@ -183,10 +186,7 @@ func fence(rd float64) float64 {
return float64(int(rd * rand.Float64()))
}

// hitGlue 调整传入的值
func hitGlue(l decimal.Decimal) float64 {
l = l.Sub(decimal.NewFromInt(1))
randomFactor := decimal.NewFromFloat(rand.Float64())
adjustedValue := randomFactor.Mul(l).Div(decimal.NewFromInt(2))
return adjustedValue.InexactFloat64()
func hitGlue(l float64) float64 {
return rand.Float64() * math.Log2(l) / 2
}

0 comments on commit 78669d5

Please sign in to comment.