diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-22 13:02:31 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-24 12:22:10 -0400 |
| commit | fdd7d39e52a772ef4fc328cd3a4d5eda8457f6b4 (patch) | |
| tree | 08129d549b93dc60fefa2f4ed057c549b6bbee44 | |
| parent | 982049a3a8463d6abcf78517c5f3f41cc2a45501 (diff) | |
| download | muhqs-game-fdd7d39e52a772ef4fc328cd3a4d5eda8457f6b4.tar.gz muhqs-game-fdd7d39e52a772ef4fc328cd3a4d5eda8457f6b4.zip | |
implement reporters if there exist possible target options
| -rw-r--r-- | go/game/targets.go | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/go/game/targets.go b/go/game/targets.go index b33b8895..236b4850 100644 --- a/go/game/targets.go +++ b/go/game/targets.go @@ -222,6 +222,16 @@ func (t *Target) Options() (options []interface{}) { return options } +// HasOptions reports if there is at least one possible target. +func (t *Target) HasOptions() bool { + for _, candidate := range t.candidates() { + if err := t.constraint(candidate); err == nil { + return true + } + } + return false +} + func (t *Target) CheckSelection(s *LocalState) error { if t.RequireSelection() { return fmt.Errorf("Number of selected targets and required ones does not match") @@ -267,10 +277,23 @@ func (t *Targets) NoSelections() bool { } return true } -func (t *Targets) Options() (options []interface{}) { return t.ts[t.idx].Options() } -func (t *Targets) Cur() *Target { return t.ts[t.idx] } -func (t *Targets) Next() { t.idx++ } -func (t *Targets) Targets() []*Target { return t.ts } + +// Options returns the options of the current target. +func (t *Targets) Options() (options []any) { return t.ts[t.idx].Options() } + +// HasOptions reports if each target has at least one possible target option. +func (ts *Targets) HasOptions() bool { + for _, t := range ts.ts { + if !t.HasOptions() { + return false + } + } + return true +} + +func (t *Targets) Cur() *Target { return t.ts[t.idx] } +func (t *Targets) Next() { t.idx++ } +func (t *Targets) Targets() []*Target { return t.ts } func (t *Targets) CheckTargets(s *LocalState) error { for _, target := range t.ts { @@ -282,6 +305,7 @@ func (t *Targets) CheckTargets(s *LocalState) error { return nil } +// RequireSelection reports if any of the targets require a selection. func (targets *Targets) RequireSelection() bool { for _, t := range targets.ts { if t.RequireSelection() { @@ -292,6 +316,7 @@ func (targets *Targets) RequireSelection() bool { return false } +// AllowSelection reports if any of the targets allow a selection. func (targets *Targets) AllowSelection() bool { for _, t := range targets.ts { if t.AllowSelection() { |
