diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-24 17:54:24 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:52:12 +0200 |
| commit | 19fb1a7e5c5883f49e944b6499fa1ced207a3e39 (patch) | |
| tree | 7bdb0e077d30a69e7936313ac3cdc269d10b9afc | |
| parent | 7ba220660983fe16355dc9a194d207d03d0d33e6 (diff) | |
| download | muhqs-game-19fb1a7e5c5883f49e944b6499fa1ced207a3e39.tar.gz muhqs-game-19fb1a7e5c5883f49e944b6499fa1ced207a3e39.zip | |
implement target disjunction and fix artifact constraint
| -rw-r--r-- | go/TODO | 3 | ||||
| -rw-r--r-- | go/game/cardImplementations.go | 4 | ||||
| -rw-r--r-- | go/game/targets.go | 44 |
3 files changed, 40 insertions, 11 deletions
@@ -6,9 +6,8 @@ * move * implement equipment actions * drop -* implement target disjunction * implement Pile UI hint -* implement spell target parsing / selection +* implement spell target parsing * implement triggers * implement target selection for triggers * implement draft diff --git a/go/game/cardImplementations.go b/go/game/cardImplementations.go index bc2f7414..1c4d07a5 100644 --- a/go/game/cardImplementations.go +++ b/go/game/cardImplementations.go @@ -5,7 +5,6 @@ import ( ) func adjustMelee(p Permanent, damage int) { - log.Println("adjusting melee") u, ok := p.(*Unit) if !ok { return @@ -99,8 +98,7 @@ func (*pioneerImpl) fullActions(u *Unit) []*FullAction { s := u.Controller().gameState a := newFullAction(u, resolvePrototype, "neutralize tile or artifact") - // TODO: add target disjunktion 'or' - a.targets = newTargets(newTarget(s, newTargetDesc("adjacent tile or artifcat"), a)) + a.targets = newTargets(newTarget(s, newTargetDesc("adjacent tile or adjacent artifact"), a)) return []*FullAction{a} } diff --git a/go/game/targets.go b/go/game/targets.go index 5bc6aa9f..1e80c06d 100644 --- a/go/game/targets.go +++ b/go/game/targets.go @@ -276,6 +276,20 @@ func noPreviousSelectionConstraint(targets *Targets, idx int) TargetConstraintFu } func targetConstraint(desc string, s *State, action Action) TargetConstraintFunc { + if !strings.Contains(desc, " or ") { + return singleTargetConstraint(desc, s, action) + } + + descs := strings.Split(desc, " or ") + constraints := make([]TargetConstraintFunc, 0, len(descs)) + for _, desc := range descs { + constraints = append(constraints, singleTargetConstraint(desc, s, action)) + } + + return disjunction(constraints...) +} + +func singleTargetConstraint(desc string, s *State, action Action) TargetConstraintFunc { constraints := []TargetConstraintFunc{} if strings.Contains(desc, "permanent") { constraints = append(constraints, parsePermanentTargetConstraint(desc, s, action)...) @@ -361,7 +375,7 @@ func rangeTargetConstraint(source interface{}, r int) TargetConstraintFunc { } } -func typeTargetConstrain[T any](typeDesc string) TargetConstraintFunc { +func typeTargetConstraint[T any](typeDesc string) TargetConstraintFunc { return func(t interface{}) (err error) { _, ok := t.(T) if !ok { @@ -371,12 +385,30 @@ func typeTargetConstrain[T any](typeDesc string) TargetConstraintFunc { } } +func cardTypeTargetConstraint(f func(CardType) bool) TargetConstraintFunc { + return func(t interface{}) (err error) { + p, ok := t.(Permanent) + if !ok { + err = fmt.Errorf("unexpected target type %T not Permanent", t) + return + } + + c := p.Card() + if !f(c.Type) { + err = fmt.Errorf("unexpected target card type %v", c.Type) + return + } + + return + } +} + var ( - permanentTargetConstraint TargetConstraintFunc = typeTargetConstrain[Permanent]("Permanent") - unitTargetConstraint TargetConstraintFunc = typeTargetConstrain[*Unit]("*Unit") - tileTargetConstraint TargetConstraintFunc = typeTargetConstrain[*Tile]("*Tile") - artifactTargetConstraint TargetConstraintFunc = typeTargetConstrain[*Artifact]("*Artifact") - cardTargetConstraint TargetConstraintFunc = typeTargetConstrain[*Card]("*Card") + permanentTargetConstraint TargetConstraintFunc = typeTargetConstraint[Permanent]("Permanent") + unitTargetConstraint TargetConstraintFunc = typeTargetConstraint[*Unit]("*Unit") + tileTargetConstraint TargetConstraintFunc = typeTargetConstraint[*Tile]("*Tile") + artifactTargetConstraint TargetConstraintFunc = cardTypeTargetConstraint(CardType.IsArtifact) + cardTargetConstraint TargetConstraintFunc = typeTargetConstraint[*Card]("*Card") ) func parsePermanentTargetConstraint(desc string, s *State, action Action) []TargetConstraintFunc { |
