zond / godip

A dippy adjudicator in Go.
GNU General Public License v3.0
27 stars 22 forks source link

Options[Move] also contain movements via convoy #120

Closed Wulfheart closed 3 years ago

Wulfheart commented 3 years ago

Given the following setup function:

func scaffoldVariant(t *testing.T, variantName string) (s *state.State) {
    variant, found := variants.Variants[variantName]
    if !found {
        t.Fatal("Variant", variantName, "not found")
    }
    s, err := variant.Start()
    if err != nil {
        t.Fatal(err.Error())
    }
    fleet := godip.Unit{
        Type:   godip.Fleet,
        Nation: godip.France,
    }
    army := godip.Unit{
        Type:   godip.Army,
        Nation: godip.France,
    }
    s.SetUnit("eng", fleet)
    s.SetUnit("mid", fleet)
    s.SetUnit("wal", army)
    s.SetUnit("pic", army)
    s.SetUnit("bur", army)
    s.SetUnit("ruh", army)
    return
}

I would expect the s.Phase().Options(s, godip.France)[godip.Province("wal")][godip.OrderType["Move"] to contain only the orders for the provinces which are reachable without a convoy. Currently I can't see a way to distinguish between convoy-movements and normal movements. E.g. it is possible in this case to move from wal to lon with and without convoy from eng. Do you know a solution for this problem?

zond commented 3 years ago

First of all, the State type also has an Options function that returns all options for all provinces for a given nation. It might be useful for you, if nothing else as an example.

Second, move orders are valid for destinations that need a convoy, which is why they return those options. If you don't want that I guess it would be possible to patch the code somehow, but I don't have a plan ready for that.

Wulfheart commented 3 years ago

So this behavior is desired?

So s.Options() will return the same result like the other one?

From the move options I’d like to get an indication if a province is reachable by convoy or by normal movement. Is that possible with a little workaround? One option could be to go through the graph and rule all out which are not adjacent but this feels not right.

zond commented 3 years ago

In diplicity it is, yes - I don't see why it wouldn't be.

Yes, State.Options just handles the iterations over provinces and order types.

I'm sure it could be handled somehow, but why?

Wulfheart commented 3 years ago

But state.Options has the signature func (self *State) Options(orders []godip.Order, nation godip.Nation) (result godip.Options) which is different from the signature of state.Phase().Options which is func (Phase) Options(Validator, Nation) Options. What does belong in the []godip.Orders?

zond commented 3 years ago

Ah, sorry - it doesn't automatically pick order types - it just iterates over provinces and the provided orders. Maybe it wasn't such a help after all :/

Wulfheart commented 3 years ago

Ok. Thank you.