other: 优化 combination 包命名,删除无用文件

This commit is contained in:
kercylan98 2023-07-29 15:26:32 +08:00
parent 48d9c11316
commit 57936b2b25
6 changed files with 8 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import (
) )
// NewCombination 创建一个新的组合器 // NewCombination 创建一个新的组合器
func NewCombination[T Item](options ...CombinationOption[T]) *Combination[T] { func NewCombination[T Item](options ...Option[T]) *Combination[T] {
combination := &Combination[T]{ combination := &Combination[T]{
matchers: make(map[string]*Matcher[T]), matchers: make(map[string]*Matcher[T]),
} }

View File

@ -1,14 +1,14 @@
package combination package combination
// CombinationOption 组合器选项 // Option 组合器选项
type CombinationOption[T Item] func(*Combination[T]) type Option[T Item] func(*Combination[T])
// WithCombinationEvaluation 设置组合评估函数 // WithEvaluation 设置组合评估函数
// - 用于对组合进行评估,返回一个分值的评价函数 // - 用于对组合进行评估,返回一个分值的评价函数
// - 通过该选项将设置所有匹配器的默认评估函数为该函数 // - 通过该选项将设置所有匹配器的默认评估函数为该函数
// - 通过匹配器选项 WithMatcherEvaluation 可以覆盖该默认评估函数 // - 通过匹配器选项 WithMatcherEvaluation 可以覆盖该默认评估函数
// - 默认的评估函数将返回一个随机数 // - 默认的评估函数将返回一个随机数
func WithCombinationEvaluation[T Item](evaluate func(items []T) float64) CombinationOption[T] { func WithEvaluation[T Item](evaluate func(items []T) float64) Option[T] {
return func(c *Combination[T]) { return func(c *Combination[T]) {
c.evaluate = evaluate c.evaluate = evaluate
} }

View File

@ -12,7 +12,7 @@ type Poker struct {
} }
func TestCombination_Best(t *testing.T) { func TestCombination_Best(t *testing.T) {
combine := combination.NewCombination(combination.WithCombinationEvaluation(func(items []*Poker) float64 { combine := combination.NewCombination(combination.WithEvaluation(func(items []*Poker) float64 {
var total float64 var total float64
for _, item := range items { for _, item := range items {
total += float64(item.Point) total += float64(item.Point)

View File

@ -1 +0,0 @@
package combination

View File

@ -1,4 +1,5 @@
package combination package combination
type Item interface { type Item interface {
// 占位
} }

View File

@ -12,7 +12,7 @@ type MatcherOption[T Item] func(matcher *Matcher[T])
// WithMatcherEvaluation 设置匹配器评估函数 // WithMatcherEvaluation 设置匹配器评估函数
// - 用于对组合进行评估,返回一个分值的评价函数 // - 用于对组合进行评估,返回一个分值的评价函数
// - 通过该选项将覆盖匹配器的默认(WithCombinationEvaluation)评估函数 // - 通过该选项将覆盖匹配器的默认(WithEvaluation)评估函数
func WithMatcherEvaluation[T Item](evaluate func(items []T) float64) MatcherOption[T] { func WithMatcherEvaluation[T Item](evaluate func(items []T) float64) MatcherOption[T] {
return func(m *Matcher[T]) { return func(m *Matcher[T]) {
m.evaluate = evaluate m.evaluate = evaluate