Skip to content

Commit

Permalink
完善对雀魂三麻的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed Jul 15, 2019
1 parent 30b759c commit 4beb858
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
24 changes: 23 additions & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
}
Expand Down
32 changes: 32 additions & 0 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions majsoul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4beb858

Please sign in to comment.