From 4beb858bbefca241cbc0fd6ad1793b2fe751ce77 Mon Sep 17 00:00:00 2001 From: Endless Date: Mon, 15 Jul 2019 22:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AF=B9=E9=9B=80=E9=AD=82?= =?UTF-8?q?=E4=B8=89=E9=BA=BB=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core.go | 24 +++++++++++++++++++++++- core_test.go | 32 ++++++++++++++++++++++++++++++++ majsoul.go | 6 ++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/core.go b/core.go index db860af..a60c74e 100644 --- a/core.go +++ b/core.go @@ -118,6 +118,27 @@ func newPlayerInfo(name string, selfWindTile int) *playerInfo { } } +func modifySanninPlayerInfoList(lst []*playerInfo, roundNumber int) []*playerInfo { + windToIdxMap := map[int]int{} + for i, pi := range lst { + windToIdxMap[pi.selfWindTile] = i + } + + idxS, idxW, idxN := windToIdxMap[28], windToIdxMap[29], windToIdxMap[30] + switch roundNumber % 4 { + case 0: + case 1: + // 北和西交换 + lst[idxN].selfWindTile, lst[idxW].selfWindTile = lst[idxW].selfWindTile, lst[idxN].selfWindTile + case 2: + // 北和西交换,再和南交换 + lst[idxN].selfWindTile, lst[idxW].selfWindTile, lst[idxS].selfWindTile = lst[idxW].selfWindTile, lst[idxS].selfWindTile, lst[idxN].selfWindTile + default: + panic("[modifySanninPlayerInfoList] 代码有误") + } + return lst +} + func (p *playerInfo) doraNum(doraList []int) (doraCount int) { for _, meld := range p.melds { for _, tile := range meld.Tiles { @@ -235,6 +256,7 @@ func (d *roundData) reset(roundNumber int, benNumber int, dealer int) { for i := 1; i <= 7; i++ { newData.leftCounts[i] = 0 } + newData.players = modifySanninPlayerInfoList(newData.players, roundNumber) } *d = *newData } @@ -275,7 +297,7 @@ func (d *roundData) doraList() (dl []int) { func (d *roundData) printDiscards() { // 三麻的北家是不需要打印的 for i := len(d.players) - 1; i >= 1; i-- { - if player := d.players[i]; d.playerNumber != 3 || len(player.discardTiles) > 0 { + if player := d.players[i]; d.playerNumber != 3 || player.selfWindTile != 30 { player.printDiscards() } } diff --git a/core_test.go b/core_test.go index f6fa5d3..43209cc 100644 --- a/core_test.go +++ b/core_test.go @@ -7,6 +7,7 @@ import ( "fmt" "encoding/json" "github.com/EndlessCheng/mahjong-helper/util/debug" + "github.com/stretchr/testify/assert" ) func Test_majsoul_analysis(t *testing.T) { @@ -142,3 +143,34 @@ func Test_tenhou_analysis(t *testing.T) { } } } + +func Test_modifySanninPlayerInfoList(t *testing.T) { + assert := assert.New(t) + + roundNumber := 0 + dealer := 2 + rd := newRoundData(nil, roundNumber, 0, dealer) + newPlayers := modifySanninPlayerInfoList(rd.players, roundNumber) + assert.Equal(newPlayers[0].selfWindTile, 29) + assert.Equal(newPlayers[1].selfWindTile, 30) + assert.Equal(newPlayers[2].selfWindTile, 27) + assert.Equal(newPlayers[3].selfWindTile, 28) + + roundNumber = 1 + dealer = 3 + rd = newRoundData(nil, roundNumber, 0, dealer) + newPlayers = modifySanninPlayerInfoList(rd.players, roundNumber) + assert.Equal(newPlayers[0].selfWindTile, 28) + assert.Equal(newPlayers[1].selfWindTile, 30) + assert.Equal(newPlayers[2].selfWindTile, 29) + assert.Equal(newPlayers[3].selfWindTile, 27) + + roundNumber = 2 + dealer = 0 + rd = newRoundData(nil, roundNumber, 0, dealer) + newPlayers = modifySanninPlayerInfoList(rd.players, roundNumber) + assert.Equal(newPlayers[0].selfWindTile, 27) + assert.Equal(newPlayers[1].selfWindTile, 30) + assert.Equal(newPlayers[2].selfWindTile, 28) + assert.Equal(newPlayers[3].selfWindTile, 29) +} diff --git a/majsoul.go b/majsoul.go index 671c2d5..1b8d237 100644 --- a/majsoul.go +++ b/majsoul.go @@ -303,6 +303,12 @@ func (d *majsoulRoundData) ParseInit() (roundNumber int, benNumber int, dealer i // dealer: 0=自家, 1=下家, 2=对家, 3=上家 dealer = (4 - d.selfSeat) % 4 return + } else if len(msg.Tiles2) > 0 { + if len(msg.Tiles3) > 0 { + d.playerNumber = 4 + } else { + d.playerNumber = 3 + } } dealer = -1