From 4b10dbb65df230981f485c496f6a00a48627a91f Mon Sep 17 00:00:00 2001 From: CoderSherlock Date: Fri, 12 Apr 2024 23:45:45 +0000 Subject: [PATCH] Refactor code, added new checkXu test cases(9 latterns) --- bin/pattern-lookup/generatetable.go | 180 ++++++++++++++-------------- go.mod | 7 +- go.sum | 4 + pkg/environment/environment.go | 67 +++++++++++ pkg/environment/environment_test.go | 17 +++ pkg/{ => pattern}/fan.go | 2 +- pkg/{ => pattern}/fan_test.go | 2 +- pkg/pattern/pattern.go | 13 ++ pkg/{ => tiles}/tiles.go | 69 +---------- pkg/tiles/tiles_opts.go | 5 + pkg/{ => tiles}/tiles_test.go | 22 +--- 11 files changed, 212 insertions(+), 176 deletions(-) create mode 100644 pkg/environment/environment.go create mode 100644 pkg/environment/environment_test.go rename pkg/{ => pattern}/fan.go (98%) rename pkg/{ => pattern}/fan_test.go (98%) create mode 100644 pkg/pattern/pattern.go rename pkg/{ => tiles}/tiles.go (81%) create mode 100644 pkg/tiles/tiles_opts.go rename pkg/{ => tiles}/tiles_test.go (82%) diff --git a/bin/pattern-lookup/generatetable.go b/bin/pattern-lookup/generatetable.go index 69688d1..9ef94cd 100644 --- a/bin/pattern-lookup/generatetable.go +++ b/bin/pattern-lookup/generatetable.go @@ -2,108 +2,108 @@ package main import ( "fmt" - pkg "mjhelper/pkg" + pattern "mjhelper/pkg/pattern" "github.com/mowshon/iterium" ) -func allFans() []pkg.Fan { - testFans := []pkg.Fan{ - {Id: 1, Name: "大四喜", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{38, 49, 62, 63}, Value: 88}, - {Id: 2, Name: "大三元", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 88}, - {Id: 3, Name: "绿一色", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 88}, - {Id: 4, Name: "九莲宝灯", Pattern: pkg.PatternDivision{Ke: 2, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 88}, - {Id: 5, Name: "四杠", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 4}, ExcludeIds: []int{}, Value: 88}, - {Id: 6, Name: "连七对", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 7, Gang: 0}, ExcludeIds: []int{}, Value: 88}, - {Id: 7, Name: "十三幺", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 88}, - {Id: 8, Name: "清幺九", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, - {Id: 9, Name: "小四喜", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, - {Id: 10, Name: "小三元", Pattern: pkg.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, - {Id: 11, Name: "字一色", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, - {Id: 12, Name: "四暗刻", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 2, Gang: 0}, ExcludeIds: []int{}, Value: 64}, - {Id: 13, Name: "一色双龙会", Pattern: pkg.PatternDivision{Ke: 0, Shun: 4, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, - {Id: 14, Name: "一色四同顺", Pattern: pkg.PatternDivision{Ke: 0, Shun: 4, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 48}, - {Id: 15, Name: "一色四节高", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 48}, - {Id: 16, Name: "一色四步高", Pattern: pkg.PatternDivision{Ke: 0, Shun: 4, Dui: 2, Gang: 0}, ExcludeIds: []int{}, Value: 32}, - {Id: 17, Name: "三杠", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 3}, ExcludeIds: []int{}, Value: 32}, - {Id: 18, Name: "混幺九", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 32}, - {Id: 19, Name: "七对", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 7, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 20, Name: "七星不靠", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 21, Name: "全双刻", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 2, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 22, Name: "清一色", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 23, Name: "一色三同顺", Pattern: pkg.PatternDivision{Ke: 0, Shun: 3, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 24, Name: "一色三节高", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 25, Name: "全大", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 26, Name: "全中", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 27, Name: "全小", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, - {Id: 28, Name: "清龙", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, - {Id: 29, Name: "三色双龙会", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, - {Id: 30, Name: "一色三步高", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, - {Id: 31, Name: "全带五", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, - {Id: 32, Name: "三同刻", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, - {Id: 33, Name: "三暗刻", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, - {Id: 34, Name: "全不靠", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 12}, - {Id: 35, Name: "组合龙", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, - {Id: 36, Name: "大于五", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, - {Id: 37, Name: "小于五", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, - {Id: 38, Name: "三风刻", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, - {Id: 39, Name: "花龙", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 40, Name: "推不倒", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 41, Name: "三色三同顺", Pattern: pkg.PatternDivision{Ke: 0, Shun: 3, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 42, Name: "三色三节高", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 43, Name: "无番和", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 44, Name: "妙手回春", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 45, Name: "海底捞月", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 8}, - {Id: 46, Name: "杠上开花", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 1}, ExcludeIds: []int{}, Value: 8}, - {Id: 47, Name: "抢杠和", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 8}, +func allFans() []pattern.Fan { + testFans := []pattern.Fan{ + {Id: 1, Name: "大四喜", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{38, 49, 62, 63}, Value: 88}, + {Id: 2, Name: "大三元", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 88}, + {Id: 3, Name: "绿一色", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 88}, + {Id: 4, Name: "九莲宝灯", Pattern: pattern.PatternDivision{Ke: 2, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 88}, + {Id: 5, Name: "四杠", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 4}, ExcludeIds: []int{}, Value: 88}, + {Id: 6, Name: "连七对", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 7, Gang: 0}, ExcludeIds: []int{}, Value: 88}, + {Id: 7, Name: "十三幺", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 88}, + {Id: 8, Name: "清幺九", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, + {Id: 9, Name: "小四喜", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, + {Id: 10, Name: "小三元", Pattern: pattern.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, + {Id: 11, Name: "字一色", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, + {Id: 12, Name: "四暗刻", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 2, Gang: 0}, ExcludeIds: []int{}, Value: 64}, + {Id: 13, Name: "一色双龙会", Pattern: pattern.PatternDivision{Ke: 0, Shun: 4, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 64}, + {Id: 14, Name: "一色四同顺", Pattern: pattern.PatternDivision{Ke: 0, Shun: 4, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 48}, + {Id: 15, Name: "一色四节高", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 48}, + {Id: 16, Name: "一色四步高", Pattern: pattern.PatternDivision{Ke: 0, Shun: 4, Dui: 2, Gang: 0}, ExcludeIds: []int{}, Value: 32}, + {Id: 17, Name: "三杠", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 3}, ExcludeIds: []int{}, Value: 32}, + {Id: 18, Name: "混幺九", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 32}, + {Id: 19, Name: "七对", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 7, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 20, Name: "七星不靠", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 21, Name: "全双刻", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 2, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 22, Name: "清一色", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 23, Name: "一色三同顺", Pattern: pattern.PatternDivision{Ke: 0, Shun: 3, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 24, Name: "一色三节高", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 25, Name: "全大", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 26, Name: "全中", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 27, Name: "全小", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 24}, + {Id: 28, Name: "清龙", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, + {Id: 29, Name: "三色双龙会", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, + {Id: 30, Name: "一色三步高", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, + {Id: 31, Name: "全带五", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, + {Id: 32, Name: "三同刻", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, + {Id: 33, Name: "三暗刻", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 16}, + {Id: 34, Name: "全不靠", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 12}, + {Id: 35, Name: "组合龙", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, + {Id: 36, Name: "大于五", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, + {Id: 37, Name: "小于五", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, + {Id: 38, Name: "三风刻", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 12}, + {Id: 39, Name: "花龙", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 40, Name: "推不倒", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 41, Name: "三色三同顺", Pattern: pattern.PatternDivision{Ke: 0, Shun: 3, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 42, Name: "三色三节高", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 43, Name: "无番和", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 44, Name: "妙手回春", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 45, Name: "海底捞月", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 8}, + {Id: 46, Name: "杠上开花", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 1}, ExcludeIds: []int{}, Value: 8}, + {Id: 47, Name: "抢杠和", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 8}, // 双暗杠 98版计6番,06版计8番 - {Id: 48, Name: "双暗杠", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 2}, ExcludeIds: []int{}, Value: 6}, - {Id: 49, Name: "碰碰和", Pattern: pkg.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 50, Name: "混一色", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 51, Name: "三色三步高", Pattern: pkg.PatternDivision{Ke: 0, Shun: 3, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 52, Name: "三色三节高", Pattern: pkg.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 53, Name: "五门齐", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 54, Name: "全求人", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 48, Name: "双暗杠", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 2}, ExcludeIds: []int{}, Value: 6}, + {Id: 49, Name: "碰碰和", Pattern: pattern.PatternDivision{Ke: 4, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 50, Name: "混一色", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 51, Name: "三色三步高", Pattern: pattern.PatternDivision{Ke: 0, Shun: 3, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 52, Name: "三色三节高", Pattern: pattern.PatternDivision{Ke: 3, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 53, Name: "五门齐", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 54, Name: "全求人", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 6}, // 明暗杠 06版计6番,存疑 - {Id: 55, Name: "明暗杠", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 56, Name: "双箭刻", Pattern: pkg.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, - {Id: 57, Name: "全带幺", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 4}, - {Id: 58, Name: "不求人", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 4}, - {Id: 59, Name: "双明杠", Pattern: pkg.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 2}, ExcludeIds: []int{}, Value: 4}, - {Id: 60, Name: "和绝张", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 4}, - {Id: 61, Name: "箭刻", Pattern: pkg.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 62, Name: "圈风刻", Pattern: pkg.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 63, Name: "门风刻", Pattern: pkg.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 64, Name: "门前清", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 65, Name: "平和", Pattern: pkg.PatternDivision{Ke: 0, Shun: 4, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 66, Name: "四归一", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 67, Name: "双同刻", Pattern: pkg.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 68, Name: "双暗刻", Pattern: pkg.PatternDivision{Ke: 2, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 69, Name: "暗杠", Pattern: pkg.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 1}, ExcludeIds: []int{}, Value: 2}, - {Id: 70, Name: "断幺", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, - {Id: 71, Name: "一般高", Pattern: pkg.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 72, Name: "喜相逢", Pattern: pkg.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 73, Name: "连六", Pattern: pkg.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 74, Name: "老少副", Pattern: pkg.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 75, Name: "幺九刻", Pattern: pkg.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 76, Name: "明杠", Pattern: pkg.PatternDivision{Ke: 1, Shun: 0, Dui: 0, Gang: 1}, ExcludeIds: []int{}, Value: 1}, - {Id: 77, Name: "缺一门", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 78, Name: "无字", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 79, Name: "边张", Pattern: pkg.PatternDivision{Ke: 0, Shun: 1, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 80, Name: "坎张", Pattern: pkg.PatternDivision{Ke: 0, Shun: 1, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 81, Name: "单钓将", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 82, Name: "自摸", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, - {Id: 82, Name: "花牌", Pattern: pkg.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 55, Name: "明暗杠", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 56, Name: "双箭刻", Pattern: pattern.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 6}, + {Id: 57, Name: "全带幺", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 4}, + {Id: 58, Name: "不求人", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 4}, + {Id: 59, Name: "双明杠", Pattern: pattern.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 2}, ExcludeIds: []int{}, Value: 4}, + {Id: 60, Name: "和绝张", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 4}, + {Id: 61, Name: "箭刻", Pattern: pattern.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 62, Name: "圈风刻", Pattern: pattern.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 63, Name: "门风刻", Pattern: pattern.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 64, Name: "门前清", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 65, Name: "平和", Pattern: pattern.PatternDivision{Ke: 0, Shun: 4, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 66, Name: "四归一", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 67, Name: "双同刻", Pattern: pattern.PatternDivision{Ke: 2, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 68, Name: "双暗刻", Pattern: pattern.PatternDivision{Ke: 2, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 69, Name: "暗杠", Pattern: pattern.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 1}, ExcludeIds: []int{}, Value: 2}, + {Id: 70, Name: "断幺", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 2}, + {Id: 71, Name: "一般高", Pattern: pattern.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 72, Name: "喜相逢", Pattern: pattern.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 73, Name: "连六", Pattern: pattern.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 74, Name: "老少副", Pattern: pattern.PatternDivision{Ke: 0, Shun: 2, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 75, Name: "幺九刻", Pattern: pattern.PatternDivision{Ke: 1, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 76, Name: "明杠", Pattern: pattern.PatternDivision{Ke: 1, Shun: 0, Dui: 0, Gang: 1}, ExcludeIds: []int{}, Value: 1}, + {Id: 77, Name: "缺一门", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 78, Name: "无字", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 79, Name: "边张", Pattern: pattern.PatternDivision{Ke: 0, Shun: 1, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 80, Name: "坎张", Pattern: pattern.PatternDivision{Ke: 0, Shun: 1, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 81, Name: "单钓将", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 1, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 82, Name: "自摸", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, + {Id: 82, Name: "花牌", Pattern: pattern.PatternDivision{Ke: 0, Shun: 0, Dui: 0, Gang: 0}, ExcludeIds: []int{}, Value: 1}, } return testFans } func AllFansToFile() { allFans := allFans() - pkg.FansToFile(allFans, "test.json") + pattern.FansToFile(allFans, "test.json") } -func GenerateFan(fan pkg.Fan) { +func GenerateFan(fan pattern.Fan) { } @@ -144,7 +144,7 @@ func main() { "1B", "2B", "3B", "4B", "5B", "6B", "7B", "8B", "9B", "DO", "XI", "NA", "BE", "ZH", "FA", "BA"}, 1) fmt.Println(result2_1.Count() * result2_2.Count()) - for i := range result2_1.Chan() { + /*for i := range result2_1.Chan() { fmt.Println(i) - } + }*/ } diff --git a/go.mod b/go.mod index 81ee6f1..52f28c5 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module mjhelper go 1.20 -require ( - github.com/mowshon/iterium v1.0.0 // indirect - golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect -) +require github.com/mowshon/iterium v1.0.0 + +require golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect diff --git a/go.sum b/go.sum index bdd5837..2061d39 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,8 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/mowshon/iterium v1.0.0 h1:04pku9dTNnfVvshf+DQIV3E92T/EwmnXKtXMkmZ3+5Q= github.com/mowshon/iterium v1.0.0/go.mod h1:Bnchn9HAYNQ/7MLUwKDyvjduSuVJQQwrNxmXJDqpXg4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKMIXrEpFxNMs0spT3/5s= golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go new file mode 100644 index 0000000..5299d4a --- /dev/null +++ b/pkg/environment/environment.go @@ -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 +} diff --git a/pkg/environment/environment_test.go b/pkg/environment/environment_test.go new file mode 100644 index 0000000..ab96f9d --- /dev/null +++ b/pkg/environment/environment_test.go @@ -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) +} diff --git a/pkg/fan.go b/pkg/pattern/fan.go similarity index 98% rename from pkg/fan.go rename to pkg/pattern/fan.go index 0b7ad8f..3a03248 100644 --- a/pkg/fan.go +++ b/pkg/pattern/fan.go @@ -1,4 +1,4 @@ -package pkg +package pattern import ( "encoding/json" diff --git a/pkg/fan_test.go b/pkg/pattern/fan_test.go similarity index 98% rename from pkg/fan_test.go rename to pkg/pattern/fan_test.go index c6baee6..f605d9b 100644 --- a/pkg/fan_test.go +++ b/pkg/pattern/fan_test.go @@ -1,4 +1,4 @@ -package pkg +package pattern import ( "fmt" diff --git a/pkg/pattern/pattern.go b/pkg/pattern/pattern.go new file mode 100644 index 0000000..5c58a89 --- /dev/null +++ b/pkg/pattern/pattern.go @@ -0,0 +1,13 @@ +package pattern + +type pattern struct { +} + +type shun struct { +} + +type ke struct { +} + +type jiang struct { +} diff --git a/pkg/tiles.go b/pkg/tiles/tiles.go similarity index 81% rename from pkg/tiles.go rename to pkg/tiles/tiles.go index f4c99b7..32a0de9 100644 --- a/pkg/tiles.go +++ b/pkg/tiles/tiles.go @@ -1,4 +1,4 @@ -package pkg +package tiles import ( "errors" @@ -8,80 +8,21 @@ import ( "sort" ) -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 -) - -var tileTypes = [34]string{ +var TileTypes = [34]string{ "1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W", "1T", "2T", "3T", "4T", "5T", "6T", "7T", "8T", "9T", "1B", "2B", "3B", "4B", "5B", "6B", "7B", "8B", "9B", "DO", "XI", "NA", "BE", "ZH", "FA", "BA"} var tileHuaTypes = [8]string{"ME", "LA", "ZU", "JU", "CH", "XA", "QI", "DN"} -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", 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 -} - +// Given two tiles, return if first tile is smaller the second tile, functions used as comparator for ordering +// Default order is: 万 < 条 < 饼 < 字(东西南北中发白) func TileComparator(i, j string) (bool, error) { if i == j { return false, nil } ii, ij := -1, -1 - for k, v := range tileTypes { + for k, v := range TileTypes { if i == v { ii = k } diff --git a/pkg/tiles/tiles_opts.go b/pkg/tiles/tiles_opts.go new file mode 100644 index 0000000..fe78659 --- /dev/null +++ b/pkg/tiles/tiles_opts.go @@ -0,0 +1,5 @@ +package tiles + +type tileStruct struct { + +} \ No newline at end of file diff --git a/pkg/tiles_test.go b/pkg/tiles/tiles_test.go similarity index 82% rename from pkg/tiles_test.go rename to pkg/tiles/tiles_test.go index 6389801..fca3d07 100644 --- a/pkg/tiles_test.go +++ b/pkg/tiles/tiles_test.go @@ -1,23 +1,11 @@ -package pkg +package tiles import ( - "fmt" "log" "reflect" "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) -} - func TestTileComparator(t *testing.T) { type testcase struct { Args [2]string @@ -76,13 +64,15 @@ func TestCheckXushuTile(t *testing.T) { {Name: "三同顺或三同刻", Args: []string{"3W", "3W", "3W", "4W", "4W", "4W", "5W", "5W", "5W"}, Want: [][][]string{{{"3W", "3W", "3W"}, {"4W", "4W", "4W"}, {"5W", "5W", "5W"}}, {{"3W", "4W", "5W"}, {"3W", "4W", "5W"}, {"3W", "4W", "5W"}}}}, {Name: "三步四张齐", Args: []string{"3W", "3W", "3W", "3W", "4W", "4W", "4W", "4W", "5W", "5W", "5W", "5W"}, Want: [][][]string{{{"3W", "3W", "3W", "3W"}, {"4W", "4W", "4W", "4W"}, {"5W", "5W", "5W", "5W"}}, {{"3W", "4W", "5W"}, {"3W", "3W", "3W"}, {"4W", "4W", "4W"}, {"5W", "5W", "5W"}}, {{"3W", "4W", "5W"}, {"3W", "4W", "5W"}, {"3W", "4W", "5W"}, {"3W", "4W", "5W"}}, {{"3W", "3W"}, {"3W", "3W"}, {"4W", "4W"}, {"4W", "4W"}, {"5W", "5W"}, {"5W", "5W"}}}}, {Name: "三张不靠", Args: []string{"1W", "4W", "7W"}, Want: [][][]string{{{"1W"}, {"4W"}, {"7W"}}}}, - {Name: "两张不靠#1", Args: []string{"4W", "7W"}, Want: [][][]string{{{"4W"}, {"7W"}}}}, - {Name: "两张不靠#2", Args: []string{"1W", "4W"}, Want: [][][]string{{{"1W"}, {"4W"}}}}, - {Name: "两张不靠#3", Args: []string{"1W", "7W"}, Want: [][][]string{{{"1W"}, {"7W"}}}}, + {Name: "两张不靠", Args: []string{"4W", "7W"}, Want: [][][]string{{{"4W"}, {"7W"}}}}, + {Name: "两张不靠", Args: []string{"1W", "4W"}, Want: [][][]string{{{"1W"}, {"4W"}}}}, + {Name: "两张不靠", Args: []string{"1W", "7W"}, Want: [][][]string{{{"1W"}, {"7W"}}}}, {Name: "", Args: []string{"1W", "1W", "9W"}, Want: [][][]string{{{"1W"}, {"1W"}, {"9W"}}}}, {Name: "", Args: []string{"1W", "9W", "9W"}, Want: [][][]string{{{"1W"}, {"9W"}, {"9W"}}}}, {Name: "", Args: []string{"1W", "9W"}, Want: [][][]string{{{"1W"}, {"9W"}}}}, {Name: "无组合", Args: []string{"1W", "3W", "5W"}, Want: [][][]string{}}, + {Name: "九连宝灯", Args: []string{"1W", "1W", "1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W", "9W", "9W", "1W"}, Want: [][][]string{{{"1W", "2W", "3W"}, {"1W", "1W", "1W"}, {"4W", "5W", "6W"}, {"7W", "8W", "9W"}, {"9W", "9W"}}}}, + {Name: "九连宝灯", Args: []string{"1W", "1W", "1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W", "9W", "9W", "5W"}, Want: [][][]string{{{"1W", "1W", "1W"}, {"2W", "3W", "4W"}, {"5W", "5W"}, {"6W", "7W", "8W"}, {"9W", "9W", "9W"}}}}, } for _, tc := range testcases { t.Run(tc.Name, func(t *testing.T) {