mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
* init commit for chess
* fix lint & error
* remove issue link
* fix lint
* remove embed
* regex fix
* use strings.Builder
* 改不动了,先 push 了备份下
* 基本上改好了
* limit
* 使用等宽字体渲染棋盘
* use syncx
* 不会更新依赖库😭
* 先 push 备份下
* 更新依赖版本,确保能读取到字体文件
* fix log
38 lines
1003 B
Go
38 lines
1003 B
Go
package chess
|
|
|
|
import (
|
|
"math"
|
|
)
|
|
|
|
// calculateNewRate calculate new rate of the player
|
|
func calculateNewRate(whiteRate, blackRate int, whiteScore, blackScore float64) (int, int) {
|
|
k := getKFactor(whiteRate, blackRate)
|
|
exceptionWhite := calculateException(whiteRate, blackRate)
|
|
exceptionBlack := calculateException(blackRate, whiteRate)
|
|
whiteRate = calculateRate(whiteRate, whiteScore, exceptionWhite, k)
|
|
blackRate = calculateRate(blackRate, blackScore, exceptionBlack, k)
|
|
return whiteRate, blackRate
|
|
}
|
|
|
|
func calculateException(rate int, opponentRate int) float64 {
|
|
return 1.0 / (1.0 + math.Pow(10.0, float64(opponentRate-rate)/400.0))
|
|
}
|
|
|
|
func calculateRate(rate int, score float64, exception float64, k int) int {
|
|
newRate := int(math.Round(float64(rate) + float64(k)*(score-exception)))
|
|
if newRate < 1 {
|
|
newRate = 1
|
|
}
|
|
return newRate
|
|
}
|
|
|
|
func getKFactor(rateA, rateB int) int {
|
|
if rateA > 2400 && rateB > 2400 {
|
|
return 16
|
|
}
|
|
if rateA > 2100 && rateB > 2100 {
|
|
return 24
|
|
}
|
|
return 32
|
|
}
|