From 5a4a5159b3dcc1caa01e81222f3f1beefcfb4b02 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 30 Jul 2025 20:25:15 +0200 Subject: use any instead of interface{} --- go/game/targets.go | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'go/game/targets.go') diff --git a/go/game/targets.go b/go/game/targets.go index 3eccfe76..742d5c7f 100644 --- a/go/game/targets.go +++ b/go/game/targets.go @@ -12,7 +12,7 @@ import ( ) type ( - TargetConstraintFunc func(interface{}) error + TargetConstraintFunc func(any) error TargetDesc struct { target, req string @@ -27,7 +27,7 @@ type ( desc string requirement TargetRequirement constraint TargetConstraintFunc - sel []interface{} + sel []any } Targets struct { @@ -70,7 +70,7 @@ func (t *Targets) String() string { return s[:len(s)-1] + "]" } -func newTargetWithSel(s *LocalState, desc TargetDesc, action Action, sel []interface{}) *Target { +func newTargetWithSel(s *LocalState, desc TargetDesc, action Action, sel []any) *Target { t := &Target{ s: s, desc: desc.target, @@ -83,13 +83,13 @@ func newTargetWithSel(s *LocalState, desc TargetDesc, action Action, sel []inter } func newTarget(s *LocalState, desc TargetDesc, action Action) *Target { - return newTargetWithSel(s, desc, action, []interface{}{}) + return newTargetWithSel(s, desc, action, []any{}) } func newUnitAiTarget(s *LocalState, desc TargetDesc, ai *UnitAI) *Target { // Dummy action allowing the parsing code to determine the controller of the AI dummyAction := NewPassPriority(ai.u.controller) - return newTargetWithSel(s, desc, dummyAction, []interface{}{}) + return newTargetWithSel(s, desc, dummyAction, []any{}) } func newConstraintTarget(s *LocalState, desc TargetDesc, constraint TargetConstraintFunc, action Action, @@ -144,7 +144,7 @@ func newArtifactMoveTargets(s *LocalState, a *ArtifactMoveAction) *Targets { constraints = []TargetConstraintFunc{tileTargetConstraint} constraints = append(constraints, availableTileConstraint(a, a.Artifact.Card())) - constraints = append(constraints, func(t interface{}) error { + constraints = append(constraints, func(t any) error { c := rangeTargetConstraint(moveTarget.sel[0], 1) return c(t) }) @@ -207,11 +207,11 @@ func (t *Target) HasSelection() bool { return len(t.sel) > 0 } func (t *Target) AllowSelection() bool { return (t.requirement.max == -1 || len(t.sel) < t.requirement.max) && len(t.Options()) > 0 } -func (t *Target) ClearSelection() { t.sel = []interface{}{} } -func (t *Target) NoSelection() bool { return len(t.sel) == 0 } -func (t *Target) Selection() []interface{} { return t.sel } +func (t *Target) ClearSelection() { t.sel = []any{} } +func (t *Target) NoSelection() bool { return len(t.sel) == 0 } +func (t *Target) Selection() []any { return t.sel } -func (t *Target) Options() (options []interface{}) { +func (t *Target) Options() (options []any) { candidates := t.candidates() for _, candidate := range candidates { @@ -328,7 +328,7 @@ func (targets *Targets) AllowSelection() bool { } func conjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { - return func(t interface{}) error { + return func(t any) error { for _, constraint := range constraints { if err := constraint(t); err != nil { return err @@ -340,7 +340,7 @@ func conjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { } func disjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { - return func(t interface{}) error { + return func(t any) error { var err error for _, constraint := range constraints { if err = constraint(t); err == nil { @@ -353,7 +353,7 @@ func disjunction(constraints ...TargetConstraintFunc) TargetConstraintFunc { } func noPreviousSelectionConstraint(targets *Targets, idx int) TargetConstraintFunc { - return func(t interface{}) error { + return func(t any) error { for i := 0; i < idx && i < targets.idx; i++ { target := targets.ts[i] if slices.Contains(target.sel, t) { @@ -410,7 +410,7 @@ func enemyPermanentTargetConstraint(action Action) TargetConstraintFunc { log.Panicf("Unhandled source type %T in enemyPermanentTargetConstraint", source) } - return func(t interface{}) (err error) { + return func(t any) (err error) { p, _ := t.(Permanent) if !p.Controller().IsEnemy(sourceController) { err = fmt.Errorf("Controller %v of target %v is not an enemy of %v", @@ -468,7 +468,7 @@ func attackableTargetConstraint(action Action) TargetConstraintFunc { } } -func posFromTileOrPermanent(tileOrPermanent interface{}) Position { +func posFromTileOrPermanent(tileOrPermanent any) Position { switch obj := tileOrPermanent.(type) { case *Tile: return obj.Position @@ -480,10 +480,10 @@ func posFromTileOrPermanent(tileOrPermanent interface{}) Position { } } -func rangeTargetConstraint(source interface{}, r int) TargetConstraintFunc { +func rangeTargetConstraint(source any, r int) TargetConstraintFunc { sourcePos := posFromTileOrPermanent(source) - return func(t interface{}) (err error) { + return func(t any) (err error) { targetPos := posFromTileOrPermanent(t) if !IsPositionInRange(sourcePos, targetPos, r) { err = fmt.Errorf("Position %v of target %v not in range %d of source's position %v", @@ -494,7 +494,7 @@ func rangeTargetConstraint(source interface{}, r int) TargetConstraintFunc { } func typeTargetConstraint[T any](typeDesc string) TargetConstraintFunc { - return func(t interface{}) (err error) { + return func(t any) (err error) { _, ok := t.(T) if !ok { err = fmt.Errorf("unexpected target type %T not %s", t, typeDesc) @@ -504,7 +504,7 @@ func typeTargetConstraint[T any](typeDesc string) TargetConstraintFunc { } func cardTypeTargetConstraint(f func(CardType) bool) TargetConstraintFunc { - return func(t interface{}) (err error) { + return func(t any) (err error) { p, ok := t.(Permanent) if !ok { err = fmt.Errorf("unexpected target type %T not Permanent", t) @@ -580,7 +580,7 @@ func parseArtifactTargetConstraint(constraint string, s *LocalState, action Acti return constraints } -func _relaxedTileTarget(t interface{}) *Tile { +func _relaxedTileTarget(t any) *Tile { switch t := t.(type) { case *Tile: return t @@ -593,7 +593,7 @@ func _relaxedTileTarget(t interface{}) *Tile { return nil } -func relaxedTileTarget(action Action, t interface{}) *Tile { +func relaxedTileTarget(action Action, t any) *Tile { switch action.(type) { // Some actions allow to also move to Tile occupied by a crewable permanent case *MoveAction: @@ -806,7 +806,7 @@ func parseCardTargetConstraint(desc string, s *LocalState, action Action) []Targ } } - constraints = append(constraints, func(t interface{}) (err error) { + constraints = append(constraints, func(t any) (err error) { c := t.(*Card) for _, poc := range pocs { if poc.Contains(c) { @@ -820,7 +820,7 @@ func parseCardTargetConstraint(desc string, s *LocalState, action Action) []Targ return constraints } -func (t *Target) candidates() []interface{} { +func (t *Target) candidates() []any { c := []any{} if strings.Contains(t.desc, "unit") || strings.Contains(t.desc, "artifact") || -- cgit v1.2.3