diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-30 20:25:15 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:33 +0200 |
| commit | 84d69cf805e1b998768a5a340f0388cf68307ff2 (patch) | |
| tree | c6578326dafade6fd00ccdee525af288f140fe8f /go/game | |
| parent | 81e9ab9db504e09e24523482b169726a25d9a3b1 (diff) | |
| download | muhqs-game-84d69cf805e1b998768a5a340f0388cf68307ff2.tar.gz muhqs-game-84d69cf805e1b998768a5a340f0388cf68307ff2.zip | |
use any instead of interface{}
Diffstat (limited to 'go/game')
| -rw-r--r-- | go/game/action.go | 10 | ||||
| -rw-r--r-- | go/game/card.go | 2 | ||||
| -rw-r--r-- | go/game/cardParsing.go | 8 | ||||
| -rw-r--r-- | go/game/costs.go | 2 | ||||
| -rw-r--r-- | go/game/targets.go | 46 | ||||
| -rw-r--r-- | go/game/trigger.go | 20 |
6 files changed, 44 insertions, 44 deletions
diff --git a/go/game/action.go b/go/game/action.go index 913e1574..cfb9809f 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -49,7 +49,7 @@ type Action interface { type PassPriority struct{ player *Player } -func (a *PassPriority) Source() interface{} { return a.player } +func (a *PassPriority) Source() any { return a.player } func (a *PassPriority) Controller() *Player { return a.player } func (a *PassPriority) Speed() ActionSpeed { return fast } func (a *PassPriority) GameState() *LocalState { return a.player.gameState } @@ -67,7 +67,7 @@ type TargetSelection struct { targets *Targets } -func (sel *TargetSelection) Source() interface{} { return sel.player } +func (sel *TargetSelection) Source() any { return sel.player } func (sel *TargetSelection) Controller() *Player { return sel.player } func (sel *TargetSelection) Speed() ActionSpeed { return fast } func (sel *TargetSelection) GameState() *LocalState { return sel.player.gameState } @@ -96,7 +96,7 @@ type DraftPick struct { pack PileOfCards } -func (pick *DraftPick) Source() interface{} { return pick.player } +func (pick *DraftPick) Source() any { return pick.player } func (pick *DraftPick) Controller() *Player { return pick.player } func (pick *DraftPick) Speed() ActionSpeed { return fast } func (pick *DraftPick) GameState() *LocalState { return pick.player.gameState } @@ -189,7 +189,7 @@ type DeclareTriggeredActionsAction struct { actions []*TriggeredAction } -func (sel *DeclareTriggeredActionsAction) Source() interface{} { return nil } +func (sel *DeclareTriggeredActionsAction) Source() any { return nil } func (sel *DeclareTriggeredActionsAction) Controller() *Player { return nil } func (sel *DeclareTriggeredActionsAction) Speed() ActionSpeed { return fast } func (sel *DeclareTriggeredActionsAction) GameState() *LocalState { return nil } @@ -270,7 +270,7 @@ func NewPlayActionCostFunc(player *Player, cost int, card *Card) ActionCostFunc } } -func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { +func NewPlayAction(p *Player, c *Card, args ...any) *PlayAction { a := &PlayAction{ ActionBase{ source: p, diff --git a/go/game/card.go b/go/game/card.go index 5ecce64c..72b32335 100644 --- a/go/game/card.go +++ b/go/game/card.go @@ -171,7 +171,7 @@ type Card struct { Type CardType BuyCosts *ResourceCosts PlayCosts *ResourceCosts - Values map[string]interface{} + Values map[string]any Impl cardImplementation } diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go index 5ccf181a..3b1e7cdb 100644 --- a/go/game/cardParsing.go +++ b/go/game/cardParsing.go @@ -160,10 +160,10 @@ func (impl *dynamicCardImplementation) parseFullAction(fullAction string) { } } -func parseUnitConstrain(constrain string) func(ctx interface{}, u *Unit) bool { +func parseUnitConstrain(constrain string) func(ctx any, u *Unit) bool { enemy := strings.Contains(constrain, "enemy") if enemy { - return func(ctx interface{}, e *Unit) bool { + return func(ctx any, e *Unit) bool { p := ctx.(*Player) return p.IsEnemy(e.Controller()) } @@ -174,7 +174,7 @@ func parseUnitConstrain(constrain string) func(ctx interface{}, u *Unit) bool { return nil } -func parseLocation(location string) func(interface{}, *LocalState) []*Tile { +func parseLocation(location string) func(any, *LocalState) []*Tile { r := -1 var what string if strings.Contains(location, "on") { @@ -209,7 +209,7 @@ func parseLocation(location string) func(interface{}, *LocalState) []*Tile { if strings.Contains(what, "unit") { constrainFunc := parseUnitConstrain(what) if constrainFunc != nil { - return func(ctx interface{}, s *LocalState) []*Tile { + return func(ctx any, s *LocalState) []*Tile { origins := s.Map().FilterTiles(func(t *Tile) bool { if t.Permanent != nil && t.Permanent.Card().Type == CardTypes.Unit && diff --git a/go/game/costs.go b/go/game/costs.go index da8993db..bb6562ea 100644 --- a/go/game/costs.go +++ b/go/game/costs.go @@ -51,7 +51,7 @@ func (c *ResourceCosts) Costs(s *LocalState, choosenVariadicCosts ...int) int { return costs } -func ParseCardResourceCosts(_costs interface{}, effects []string) *ResourceCosts { +func ParseCardResourceCosts(_costs any, effects []string) *ResourceCosts { switch c := _costs.(type) { case int: return &ResourceCosts{fixed: c} 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") || diff --git a/go/game/trigger.go b/go/game/trigger.go index b8eb28c0..34caf9b1 100644 --- a/go/game/trigger.go +++ b/go/game/trigger.go @@ -56,8 +56,8 @@ func (e eventType) String() string { type Event struct { eventType eventType - sources []interface{} - affected []interface{} + sources []any + affected []any } func (e Event) String() string { @@ -72,31 +72,31 @@ func newEotEvent() Event { return Event{eventType: eot} } -func newTargetEvent(source interface{}, targets *Targets) Event { - affected := make([]interface{}, 0, len(targets.ts)) +func newTargetEvent(source any, targets *Targets) Event { + affected := make([]any, 0, len(targets.ts)) for _, t := range targets.ts { affected = append(affected, t.sel...) } - return Event{eventType: target, sources: []interface{}{source}, affected: affected} + return Event{eventType: target, sources: []any{source}, affected: affected} } type Trigger interface { - Source() interface{} + Source() any String() string Card() *Card trigger(*LocalState, Event) ([]*TriggeredAction, bool) } type triggerBase struct { - source interface{} + source any condition func(*LocalState, Event) (bool, bool) resolveFunc ActionResolveFunc costFunc ActionCostFunc desc string } -func (t *triggerBase) Source() interface{} { return t.source } -func (t *triggerBase) String() string { return t.desc } +func (t *triggerBase) Source() any { return t.source } +func (t *triggerBase) String() string { return t.desc } func (t *triggerBase) Card() *Card { switch t := t.source.(type) { case *Card: @@ -122,7 +122,7 @@ func newTargetedTrigger(p Permanent, singleshot bool, resolveFunc ActionResolveF t := triggerBase{source: p, resolveFunc: resolveFunc, desc: desc} t.condition = func(_ *LocalState, event Event) (bool, bool) { c := event.eventType == EventTypes.Target && - slices.Contains(event.affected, p.(interface{})) + slices.Contains(event.affected, p.(any)) remove := singleshot && c return c, remove } |
