Skip to content

Commit 4beb858

Browse files
committed
完善对雀魂三麻的支持
1 parent 30b759c commit 4beb858

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

core.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ func newPlayerInfo(name string, selfWindTile int) *playerInfo {
118118
}
119119
}
120120

121+
func modifySanninPlayerInfoList(lst []*playerInfo, roundNumber int) []*playerInfo {
122+
windToIdxMap := map[int]int{}
123+
for i, pi := range lst {
124+
windToIdxMap[pi.selfWindTile] = i
125+
}
126+
127+
idxS, idxW, idxN := windToIdxMap[28], windToIdxMap[29], windToIdxMap[30]
128+
switch roundNumber % 4 {
129+
case 0:
130+
case 1:
131+
// 北和西交换
132+
lst[idxN].selfWindTile, lst[idxW].selfWindTile = lst[idxW].selfWindTile, lst[idxN].selfWindTile
133+
case 2:
134+
// 北和西交换,再和南交换
135+
lst[idxN].selfWindTile, lst[idxW].selfWindTile, lst[idxS].selfWindTile = lst[idxW].selfWindTile, lst[idxS].selfWindTile, lst[idxN].selfWindTile
136+
default:
137+
panic("[modifySanninPlayerInfoList] 代码有误")
138+
}
139+
return lst
140+
}
141+
121142
func (p *playerInfo) doraNum(doraList []int) (doraCount int) {
122143
for _, meld := range p.melds {
123144
for _, tile := range meld.Tiles {
@@ -235,6 +256,7 @@ func (d *roundData) reset(roundNumber int, benNumber int, dealer int) {
235256
for i := 1; i <= 7; i++ {
236257
newData.leftCounts[i] = 0
237258
}
259+
newData.players = modifySanninPlayerInfoList(newData.players, roundNumber)
238260
}
239261
*d = *newData
240262
}
@@ -275,7 +297,7 @@ func (d *roundData) doraList() (dl []int) {
275297
func (d *roundData) printDiscards() {
276298
// 三麻的北家是不需要打印的
277299
for i := len(d.players) - 1; i >= 1; i-- {
278-
if player := d.players[i]; d.playerNumber != 3 || len(player.discardTiles) > 0 {
300+
if player := d.players[i]; d.playerNumber != 3 || player.selfWindTile != 30 {
279301
player.printDiscards()
280302
}
281303
}

core_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"encoding/json"
99
"github.com/EndlessCheng/mahjong-helper/util/debug"
10+
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func Test_majsoul_analysis(t *testing.T) {
@@ -142,3 +143,34 @@ func Test_tenhou_analysis(t *testing.T) {
142143
}
143144
}
144145
}
146+
147+
func Test_modifySanninPlayerInfoList(t *testing.T) {
148+
assert := assert.New(t)
149+
150+
roundNumber := 0
151+
dealer := 2
152+
rd := newRoundData(nil, roundNumber, 0, dealer)
153+
newPlayers := modifySanninPlayerInfoList(rd.players, roundNumber)
154+
assert.Equal(newPlayers[0].selfWindTile, 29)
155+
assert.Equal(newPlayers[1].selfWindTile, 30)
156+
assert.Equal(newPlayers[2].selfWindTile, 27)
157+
assert.Equal(newPlayers[3].selfWindTile, 28)
158+
159+
roundNumber = 1
160+
dealer = 3
161+
rd = newRoundData(nil, roundNumber, 0, dealer)
162+
newPlayers = modifySanninPlayerInfoList(rd.players, roundNumber)
163+
assert.Equal(newPlayers[0].selfWindTile, 28)
164+
assert.Equal(newPlayers[1].selfWindTile, 30)
165+
assert.Equal(newPlayers[2].selfWindTile, 29)
166+
assert.Equal(newPlayers[3].selfWindTile, 27)
167+
168+
roundNumber = 2
169+
dealer = 0
170+
rd = newRoundData(nil, roundNumber, 0, dealer)
171+
newPlayers = modifySanninPlayerInfoList(rd.players, roundNumber)
172+
assert.Equal(newPlayers[0].selfWindTile, 27)
173+
assert.Equal(newPlayers[1].selfWindTile, 30)
174+
assert.Equal(newPlayers[2].selfWindTile, 28)
175+
assert.Equal(newPlayers[3].selfWindTile, 29)
176+
}

majsoul.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ func (d *majsoulRoundData) ParseInit() (roundNumber int, benNumber int, dealer i
303303
// dealer: 0=自家, 1=下家, 2=对家, 3=上家
304304
dealer = (4 - d.selfSeat) % 4
305305
return
306+
} else if len(msg.Tiles2) > 0 {
307+
if len(msg.Tiles3) > 0 {
308+
d.playerNumber = 4
309+
} else {
310+
d.playerNumber = 3
311+
}
306312
}
307313
dealer = -1
308314

0 commit comments

Comments
 (0)