From 589c01fd5d1d6f51342febe7674bf09dda8d25d2 Mon Sep 17 00:00:00 2001 From: Endless Date: Sat, 28 Sep 2019 14:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=80=E9=AD=82=E7=9A=84=E8=B5=B7=E5=A7=8B?= =?UTF-8?q?=E5=AE=9D=E7=89=8C=E6=8C=87=E7=A4=BA=E7=89=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=20doras=20=E5=AD=97=E6=AE=B5=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core.go | 16 ++++++++++------ majsoul.go | 12 ++++++++++-- tenhou.go | 5 +++-- util/tile.go | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/core.go b/core.go index 7ce18fe..b6cbd16 100644 --- a/core.go +++ b/core.go @@ -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 @@ -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) @@ -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) @@ -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) diff --git a/majsoul.go b/majsoul.go index 6d0ac5e..ba9158a 100644 --- a/majsoul.go +++ b/majsoul.go @@ -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 { @@ -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 diff --git a/tenhou.go b/tenhou.go index 0d5feef..1b87fc2 100644 --- a/tenhou.go +++ b/tenhou.go @@ -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, ",") @@ -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 { diff --git a/util/tile.go b/util/tile.go index 23fea34..eeb2d9a 100644 --- a/util/tile.go +++ b/util/tile.go @@ -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