Skip to content

Allowed moves as function#164

Merged
nicolodavis merged 11 commits into
boardgameio:masterfrom
jstacoder:allowedMoves_as_function
Mar 21, 2018
Merged

Allowed moves as function#164
nicolodavis merged 11 commits into
boardgameio:masterfrom
jstacoder:allowedMoves_as_function

Conversation

@jstacoder
Copy link
Copy Markdown
Contributor

Checklist

  • Use a separate branch in your local repo (not master).
  • Test coverage is 100% (or you have a story for why it's ok).

here it is only on the phase level, im having trouble getting it working on the top level in flow, i want to return all move names by default, or should it just stay undefined by default at the top level? any suggestions would be very appreicated

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 21, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 9b96f0e on jstacoder:allowedMoves_as_function into e5c567b on google:master.

Comment thread src/core/flow.js
* allowedMoves: ['moveA', ...],
* // List of moves or a function that returns a list of moves
* // that are allowed in this phase.
* allowedMoves: (G, ctx) => ['moveA', ...],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also make this available on a per-game basis (not just on a per-phase basis)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot to wait for this. No worries, I'll just add this myself.

@nicolodavis
Copy link
Copy Markdown
Member

Hijacking this thread for a moment to discuss something broader. We don't need to implement any of the following in this PR. One of us will follow up later:

We now have a few different mechanisms to disallow moves:

  1. allowedMoves
  2. canMakeMove
  3. Returning undefined in a move function.

1 is designed to handle disabling types of moves. 2 and 3 are designed to disable specific instances of a move (with a particular argument combination for example). Both are valuable, but I would recommend that we only use one out of 2 and 3 to do the latter. I'm leaning toward retiring 2 (i.e. not allowing the user to override canMakeMove).

Also, we should probably expose 1 through ctx so that it is a helpful hint to the UI to figure out what moves to highlight.

@Stefan-Hanke, what do you think?

@felizardo, this might also be useful for the AI code. Let's consolidate what we have there as well.

@jstacoder
Copy link
Copy Markdown
Contributor Author

I think exposing it to ctx is perfect, exactly what’s needed to make it work at the top level, and I like returning undefined from a move to specifically disallow it, but I was wondering if at the top level of the config should it maybe be a disallowedMoves array? Which is then checked, possibly overridden in the phase level allowedMoves? It just seems like the use case would be to disallow one or two moves, which would then conditionally be allowed in certain phases or specific parts of turns, but I can also see how maybe having the top level value and phase level value being different (disallowedMoves vs allowedMoves) could be confusing as well. Ideas?

@nicolodavis
Copy link
Copy Markdown
Member

nicolodavis commented Mar 21, 2018

Let's just use allowedMoves everywhere. It's much less confusing that way. About the semantics of the override, let's just have the phase level config override the global config whenever it is defined. We can use null to indicate that all moves are allowed (instead of undefined).

For example, if a game has three moves: A, B and C.

Game -> allowedMoves: ['A', 'B'],
phase 1 -> allowedMoves: null       // A B C allowed
phase 2 -> allowedMoves: ['A']      // A allowed
phase 3                             // A and B allowed
phase 4 -> allowedMoves: []         // nothing allowed

@nicolodavis nicolodavis merged commit 9324c58 into boardgameio:master Mar 21, 2018
@vdfdev
Copy link
Copy Markdown
Contributor

vdfdev commented Mar 22, 2018

@nicolodavis Sorry I've been a little bit busy IRL, so I lost a little bit the track of the changes, I will try to catch up this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants