Refactor code, added new checkXu test cases(9 latterns)

This commit is contained in:
2024-04-12 23:45:45 +00:00
parent e341a048fc
commit 4b10dbb65d
11 changed files with 212 additions and 176 deletions
+67
View File
@@ -0,0 +1,67 @@
package pkg
import (
"fmt"
"mjhelper/pkg/tiles"
)
const (
// 未出场
tl_notshow = 0
// 本家状态
tl_mhand = 1
tl_mshow = 2
tl_mdisc = 3
// 下家状态
tl_nhand = 4
tl_nshow = 5
tl_ndisc = 6
// 对家状态
tl_ohand = 7
tl_oshow = 8
tl_odisc = 9
// 上家状态
tl_phand = 10
tl_pshow = 11
tl_pdisc = 12
)
type environment struct {
board [4][34]int
}
func (e environment) Print() {
for i := 0; i < len(e.board)+1; i++ {
for j := 0; j < len(e.board[0]); j++ {
if i == 0 {
fmt.Printf("|% 3s", tiles.TileTypes[j])
} else {
fmt.Printf("|% 3d", e.board[i-1][j])
}
}
fmt.Printf("|\n")
}
}
func (e environment) PatternNormalization() [3][34]int {
var ret [3][34]int
for i := 0; i < len(e.board[0]); i++ {
hand := 0
disc := 0
noshow := 0
for j := 0; j < len(e.board); j++ {
switch e.board[j][i] {
case tl_mhand, tl_mshow:
hand += 1
case tl_mdisc, tl_ndisc, tl_nshow, tl_odisc, tl_oshow, tl_pdisc, tl_pshow:
disc += 1
case tl_notshow:
noshow += 1
}
}
ret[0][i] = hand
ret[1][i] = disc
ret[2][i] = noshow
}
return ret
}
+17
View File
@@ -0,0 +1,17 @@
package pkg
import (
"fmt"
"testing"
)
func TestPrint(t *testing.T) {
var env environment
env.Print()
}
func TestPatternNormalization(t *testing.T) {
var env environment
handTiles := env.PatternNormalization()
fmt.Println(handTiles)
}