Skip to content

Commit

Permalink
雀魂的起始宝牌指示牌添加对 doras 字段的解析
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed Sep 28, 2019
1 parent 811d2ac commit 589c01f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
16 changes: 10 additions & 6 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type DataParser interface {
// roundNumber: 场数(如东1为0,东2为1,...,南1为4,...,南4为7,...),对于三麻来说南1也是4
// benNumber: 本场数
// dealer: 庄家 0-3
// doraIndicator: 宝牌指示牌
// doraIndicators: 宝牌指示牌
// handTiles: 手牌
// numRedFives: 按照 mps 的顺序,赤5个数
IsInit() bool
ParseInit() (roundNumber int, benNumber int, dealer int, doraIndicator int, handTiles []int, numRedFives []int)
ParseInit() (roundNumber int, benNumber int, dealer int, doraIndicators []int, handTiles []int, numRedFives []int)

// 自家摸牌
// tile: 0-33
Expand Down Expand Up @@ -512,7 +512,7 @@ func (d *roundData) analysis() error {
clearConsole()
}

roundNumber, benNumber, dealer, doraIndicator, hands, numRedFives := d.parser.ParseInit()
roundNumber, benNumber, dealer, doraIndicators, hands, numRedFives := d.parser.ParseInit()
switch d.parser.GetDataSourceType() {
case dataSourceTypeTenhou:
d.reset(roundNumber, benNumber, dealer)
Expand Down Expand Up @@ -540,8 +540,10 @@ func (d *roundData) analysis() error {
currentRoundCache = analysisCache.wholeGameCache[d.roundNumber][d.benNumber]
}

d.doraIndicators = []int{doraIndicator}
d.descLeftCounts(doraIndicator)
d.doraIndicators = doraIndicators
for _, dora := range doraIndicators {
d.descLeftCounts(dora)
}
for _, tile := range hands {
d.counts[tile]++
d.descLeftCounts(tile)
Expand All @@ -568,7 +570,9 @@ func (d *roundData) analysis() error {
fmt.Printf("%d局开始,自风为", roundNumber%4+1)
color.New(color.FgHiGreen).Printf("%s", util.MahjongZH[d.players[0].selfWindTile])
fmt.Println()
color.HiYellow("宝牌指示牌是 %s", util.MahjongZH[doraIndicator])
info := fmt.Sprintln(util.TilesToMahjongZHInterface(d.doraIndicators)...)
info = info[:len(info)-1]
color.HiYellow("宝牌指示牌是 " + info)
fmt.Println()
// TODO: 显示地和概率
return analysisPlayerWithRisk(playerInfo, nil)
Expand Down
12 changes: 10 additions & 2 deletions majsoul.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (d *majsoulRoundData) IsInit() bool {
return msg.IsGameStart != nil || msg.MD5 != ""
}

func (d *majsoulRoundData) ParseInit() (roundNumber int, benNumber int, dealer int, doraIndicator int, handTiles []int, numRedFives []int) {
func (d *majsoulRoundData) ParseInit() (roundNumber int, benNumber int, dealer int, doraIndicators []int, handTiles []int, numRedFives []int) {
msg := d.msg

if playerNumber := len(msg.SeatList); playerNumber >= 3 {
Expand All @@ -314,7 +314,15 @@ func (d *majsoulRoundData) ParseInit() (roundNumber int, benNumber int, dealer i

roundNumber = 4*(*msg.Chang) + *msg.Ju
benNumber = *msg.Ben
doraIndicator, _ = d.mustParseMajsoulTile(msg.Dora)
if msg.Dora != "" {
doraIndicator, _ := d.mustParseMajsoulTile(msg.Dora)
doraIndicators = append(doraIndicators, doraIndicator)
} else {
for _, dora := range msg.Doras {
doraIndicator, _ := d.mustParseMajsoulTile(dora)
doraIndicators = append(doraIndicators, doraIndicator)
}
}
numRedFives = make([]int, 3)

var majsoulTiles []string
Expand Down
5 changes: 3 additions & 2 deletions tenhou.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (d *tenhouRoundData) IsInit() bool {
return d.msg.Tag == "INIT" || d.msg.Tag == "REINIT"
}

func (d *tenhouRoundData) ParseInit() (roundNumber int, benNumber int, dealer int, doraIndicator int, handTiles []int, numRedFives []int) {
func (d *tenhouRoundData) ParseInit() (roundNumber int, benNumber int, dealer int, doraIndicators []int, handTiles []int, numRedFives []int) {
d.isRoundEnd = false

seedSplits := strings.Split(d.msg.Seed, ",")
Expand All @@ -458,7 +458,8 @@ func (d *tenhouRoundData) ParseInit() (roundNumber int, benNumber int, dealer in
}

dealer, _ = strconv.Atoi(d.msg.Dealer)
doraIndicator, _ = d._parseTenhouTile(seedSplits[5])
doraIndicator, _ := d._parseTenhouTile(seedSplits[5])
doraIndicators = append(doraIndicators, doraIndicator)
numRedFives = make([]int, 3)
tenhouTiles := strings.Split(d.msg.Hai, ",")
for _, tenhouTile := range tenhouTiles {
Expand Down
14 changes: 14 additions & 0 deletions util/tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ var MahjongZH = [...]string{

var YaochuTiles = [...]int{0, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33}

func TilesToMahjongZH(tiles []int) (words []string) {
for _, tile := range tiles {
words = append(words, MahjongZH[tile])
}
return
}

func TilesToMahjongZHInterface(tiles []int) (words []interface{}) {
for _, tile := range tiles {
words = append(words, MahjongZH[tile])
}
return
}

// 进张
// map[进张牌]剩余数
type Waits map[int]int
Expand Down

0 comments on commit 589c01f

Please sign in to comment.