/
RoomInfo.go
119 lines (107 loc) · 3.07 KB
/
RoomInfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package mahjong
import (
"strings"
)
// GetPlayerList returns the list of player's name
func (room Room) GetPlayerList() []string {
var nameList []string
for _, player := range room.Players {
nameList = append(nameList, player.Name())
}
return nameList
}
// GetWindAndRound returns the wind and round
func (room Room) GetWindAndRound() (int, int) {
return room.Wind, room.Round
}
// GetReadyPlayers returns the name list of ready player
func (room Room) GetReadyPlayers() []string {
var nameList []string
for _, player := range room.Players {
nameList = append(nameList, player.Name())
}
return nameList
}
// GetHandCount returns each player's amount of hand
func (room Room) GetHandCount() []int {
if room.State < IdxTurn {
return []int{}
}
var amounts []int
for _, player := range room.Players {
amounts = append(amounts, int(player.Hand.Count()))
}
return amounts
}
// GetRemainCount returns amount of deck
func (room Room) GetRemainCount() int {
if room.State < IdxTurn {
return 56
}
return int(room.Deck.Count())
}
// GetDoor returns each player's door
func (room Room) GetDoor(id int) ([][][]string, []int, bool) {
if room.State < IdxTurn {
return [][][]string{}, []int{}, true
}
var inVisibleList []int
var visibleList [][][]string
for _, player := range room.Players {
var tmp []string
for _, act := range player.EatTiles {
tmp = append(tmp, strings.Join([]string{act.First.ToString(), act.Center.ToString()}, ","))
}
if id == player.ID {
visibleList = append(visibleList, [][]string{tmp, player.PonTiles.ToStringArray(), player.GonTiles.ToStringArray(), player.OngonTiles.ToStringArray()})
inVisibleList = append(inVisibleList, 0)
} else {
visibleList = append(visibleList, [][]string{tmp, player.PonTiles.ToStringArray(), player.GonTiles.ToStringArray(), []string{}})
inVisibleList = append(inVisibleList, int(player.OngonTiles.Count()))
}
}
return visibleList, inVisibleList, false
}
// GetSea returns each player's discard tile
func (room Room) GetSea() ([][]string, bool) {
if room.State < IdxTurn {
return [][]string{}, true
}
var discardTileList [][]string
for _, player := range room.Players {
discardTileList = append(discardTileList, player.DiscardTiles.ToStringArray())
}
return discardTileList, false
}
// GetFlower returns each player's flower tile
func (room Room) GetFlower() ([][]string, bool) {
var flowerList [][]string
for _, player := range room.Players {
flowerList = append(flowerList, player.Flowers.ToStringArray())
}
return flowerList, false
}
// GetCurrentIdx returns current index
func (room Room) GetCurrentIdx() int {
id := -1
if room.State >= IdxTurn {
id = room.State - IdxTurn
}
return id
}
// GetScore returns each player's score
func (room Room) GetScore() []int {
var scoreList []int
for _, player := range room.Players {
scoreList = append(scoreList, player.Credit)
}
return scoreList
}
// GetTing returns each player's isTing
func (room Room) GetTing() []bool {
var tingList []bool
for _, player := range room.Players {
tingList = append(tingList, player.IsTing)
}
return tingList
}