aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go/game/targets.go33
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() {