Merge branch 'main' of git.proxy.lxtend.com:lixiangwuxian/qq_bot
This commit is contained in:
commit
5b7f4b2118
@ -4,7 +4,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"git.lxtend.com/lixiangwuxian/qqbot/handler/blackjack/model"
|
||||
"git.lxtend.com/lixiangwuxian/qqbot/handler/blackjack/util"
|
||||
"git.lxtend.com/lixiangwuxian/qqbot/handler/blackjack/utiljack"
|
||||
)
|
||||
|
||||
type BackJackSimulator struct {
|
||||
@ -13,7 +13,7 @@ type BackJackSimulator struct {
|
||||
playerCards *model.Deck
|
||||
dealerScore int
|
||||
playerScore int
|
||||
status util.Status
|
||||
status utiljack.Status
|
||||
}
|
||||
|
||||
func NewBlackJackSimulator() *BackJackSimulator {
|
||||
@ -77,13 +77,13 @@ func (simulator *BackJackSimulator) Init() *BackJackSimulator {
|
||||
simulator.playerCards = initPlayerCards(simulator.playerCards, simulator.deck)
|
||||
|
||||
simulator.dealerScore, simulator.playerScore = 0, 0
|
||||
simulator.status = util.INITIALIZED
|
||||
simulator.status = utiljack.INITIALIZED
|
||||
|
||||
return simulator
|
||||
}
|
||||
|
||||
func (simulator *BackJackSimulator) Hit() *BackJackResponse {
|
||||
if simulator.status == util.FAILED || simulator.status == util.WINNED || simulator.status == util.DRAW {
|
||||
if simulator.status == utiljack.FAILED || simulator.status == utiljack.WINNED || simulator.status == utiljack.DRAW {
|
||||
return NewBlackJackResponse(400, "[🐧] You have failed in this Blackjack game !\n")
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func (simulator *BackJackSimulator) Hit() *BackJackResponse {
|
||||
}
|
||||
|
||||
if simulator.playerScore > 21 {
|
||||
simulator.status = util.FAILED
|
||||
simulator.status = utiljack.FAILED
|
||||
return NewBlackJackResponse(400, "[🐧] Your total score exceeds 21 ! You lose !\n")
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ func (simulator *BackJackSimulator) Hit() *BackJackResponse {
|
||||
}
|
||||
|
||||
func (simulator *BackJackSimulator) Stand() *BackJackResponse {
|
||||
if simulator.status == util.FAILED || simulator.status == util.WINNED || simulator.status == util.DRAW {
|
||||
if simulator.status == utiljack.FAILED || simulator.status == utiljack.WINNED || simulator.status == utiljack.DRAW {
|
||||
return NewBlackJackResponse(400, "[🐧] You have failed in this Blackjack game !\n")
|
||||
}
|
||||
|
||||
@ -150,20 +150,20 @@ func (simulator *BackJackSimulator) Stand() *BackJackResponse {
|
||||
}
|
||||
|
||||
if minDealerScore > 21 {
|
||||
simulator.status = util.WINNED
|
||||
simulator.status = utiljack.WINNED
|
||||
return NewBlackJackResponse(400, "[🐧] The dealer burst and you have won the game !\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if maxDealerScore > maxPlayerScore {
|
||||
simulator.status = util.FAILED
|
||||
simulator.status = utiljack.FAILED
|
||||
return NewBlackJackResponse(400, "[🐧] The dealer wins the game !\n")
|
||||
} else if maxDealerScore < maxPlayerScore {
|
||||
simulator.status = util.WINNED
|
||||
simulator.status = utiljack.WINNED
|
||||
return NewBlackJackResponse(400, "[🐧] You have won the game !\n")
|
||||
} else if maxDealerScore == maxPlayerScore {
|
||||
simulator.status = util.DRAW
|
||||
simulator.status = utiljack.DRAW
|
||||
return NewBlackJackResponse(200, "[🐧] It is a draw !\n")
|
||||
}
|
||||
|
||||
@ -178,6 +178,6 @@ func (simulator *BackJackSimulator) GetPlayerCards() *model.Deck {
|
||||
return simulator.playerCards
|
||||
}
|
||||
|
||||
func (simulator *BackJackSimulator) GetStatus() util.Status {
|
||||
func (simulator *BackJackSimulator) GetStatus() utiljack.Status {
|
||||
return simulator.status
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package util
|
||||
|
||||
type Status int
|
||||
|
||||
const (
|
||||
INITIALIZED Status = iota
|
||||
WINNED Status = iota
|
||||
FAILED Status = iota
|
||||
DRAW Status = iota
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
package util
|
||||
package utiljack
|
||||
|
||||
var Dict map[string]string
|
||||
|
10
handler/blackjack/utiljack/status.go
Normal file
10
handler/blackjack/utiljack/status.go
Normal file
@ -0,0 +1,10 @@
|
||||
package utiljack
|
||||
|
||||
type Status int
|
||||
|
||||
const (
|
||||
INITIALIZED Status = iota
|
||||
WINNED Status = iota
|
||||
FAILED Status = iota
|
||||
DRAW Status = iota
|
||||
)
|
@ -630,7 +630,8 @@ func getRecent10Scores(playerID string) ([]ScoreSaberPlayerScore, error) {
|
||||
|
||||
// 获取玩家的所有分数并转换为 SongData
|
||||
func getAllScoreSaberScores(playerID string) ([]SongData, error) {
|
||||
var allSongs []SongData
|
||||
// var allSongs []SongData
|
||||
allSongs := make([]SongData, 40)
|
||||
cwd, _ := os.Getwd()
|
||||
|
||||
// 获取Best30
|
||||
@ -638,31 +639,54 @@ func getAllScoreSaberScores(playerID string) ([]SongData, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("获取Best30失败: %v", err)
|
||||
}
|
||||
for i, score := range topScores {
|
||||
songData, err := convertScoreSaberToSongData(score, cwd)
|
||||
if err != nil {
|
||||
log.Printf("转换分数失败: %v", err)
|
||||
continue
|
||||
}
|
||||
songData.IsBest30 = i < 30
|
||||
allSongs = append(allSongs, songData)
|
||||
}
|
||||
|
||||
// 获取Recent10
|
||||
recentScores, err := getRecent10Scores(playerID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("获取Recent10失败: %v", err)
|
||||
}
|
||||
for _, score := range recentScores {
|
||||
wgAll := sync.WaitGroup{}
|
||||
wgAll.Add(2)
|
||||
go func() {
|
||||
defer util.ReportPanicToDev()
|
||||
defer wgAll.Done()
|
||||
wg := sync.WaitGroup{}
|
||||
for i, score := range topScores {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer util.ReportPanicToDev()
|
||||
defer wg.Done()
|
||||
songData, err := convertScoreSaberToSongData(score, cwd)
|
||||
if err != nil {
|
||||
log.Printf("转换分数失败: %v", err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
songData.IsBest30 = i < 30
|
||||
allSongs[i] = songData
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}()
|
||||
// 获取Recent10
|
||||
go func() {
|
||||
defer util.ReportPanicToDev()
|
||||
defer wgAll.Done()
|
||||
wg := sync.WaitGroup{}
|
||||
for i, score := range recentScores {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer util.ReportPanicToDev()
|
||||
defer wg.Done()
|
||||
songData, err := convertScoreSaberToSongData(score, cwd)
|
||||
if err != nil {
|
||||
log.Printf("转换分数失败: %v", err)
|
||||
return
|
||||
}
|
||||
songData.IsBest30 = false
|
||||
allSongs = append(allSongs, songData)
|
||||
allSongs[i+30] = songData
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
}()
|
||||
wgAll.Wait()
|
||||
return allSongs, nil
|
||||
}
|
||||
|
@ -4,6 +4,12 @@ import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
/*
|
||||
按空格分割字符串,返回分割后的字符串数组
|
||||
@param text 要分割的字符串
|
||||
@param n 分割的次数
|
||||
@return 分割后的字符串数组
|
||||
*/
|
||||
func SplitN(text string, n int) []string {
|
||||
re := regexp.MustCompile(`\s+`)
|
||||
tokens := re.Split(text, n)
|
||||
|
Loading…
x
Reference in New Issue
Block a user