other: 优化 combination 包命名,删除无用文件
This commit is contained in:
parent
48d9c11316
commit
57936b2b25
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
// NewCombination 创建一个新的组合器
|
||||
func NewCombination[T Item](options ...CombinationOption[T]) *Combination[T] {
|
||||
func NewCombination[T Item](options ...Option[T]) *Combination[T] {
|
||||
combination := &Combination[T]{
|
||||
matchers: make(map[string]*Matcher[T]),
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package combination
|
||||
|
||||
// CombinationOption 组合器选项
|
||||
type CombinationOption[T Item] func(*Combination[T])
|
||||
// Option 组合器选项
|
||||
type Option[T Item] func(*Combination[T])
|
||||
|
||||
// WithCombinationEvaluation 设置组合评估函数
|
||||
// WithEvaluation 设置组合评估函数
|
||||
// - 用于对组合进行评估,返回一个分值的评价函数
|
||||
// - 通过该选项将设置所有匹配器的默认评估函数为该函数
|
||||
// - 通过匹配器选项 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]) {
|
||||
c.evaluate = evaluate
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ type Poker struct {
|
|||
}
|
||||
|
||||
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
|
||||
for _, item := range items {
|
||||
total += float64(item.Point)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package combination
|
|
@ -1,4 +1,5 @@
|
|||
package combination
|
||||
|
||||
type Item interface {
|
||||
// 占位
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ type MatcherOption[T Item] func(matcher *Matcher[T])
|
|||
|
||||
// WithMatcherEvaluation 设置匹配器评估函数
|
||||
// - 用于对组合进行评估,返回一个分值的评价函数
|
||||
// - 通过该选项将覆盖匹配器的默认(WithCombinationEvaluation)评估函数
|
||||
// - 通过该选项将覆盖匹配器的默认(WithEvaluation)评估函数
|
||||
func WithMatcherEvaluation[T Item](evaluate func(items []T) float64) MatcherOption[T] {
|
||||
return func(m *Matcher[T]) {
|
||||
m.evaluate = evaluate
|
||||
|
|
Loading…
Reference in New Issue