boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10k stars 706 forks source link

Feature Request: Define loser #45

Closed airtoxin closed 6 years ago

airtoxin commented 6 years ago

Some games have both of winning condition and losing condition, but boardgame.io support winning condition only.

If game have only losing condition, developer can use victory condition to define loser. Otherwise, may need implementation of new feature.

nicolodavis commented 6 years ago

What's an example? Just want to make sure there isn't too much feature creep (I don't want to add API support for every single game type if it is possible to handle some cases in a custom way using G).

airtoxin commented 6 years ago

Yavalath is good example https://boardgamegeek.com/boardgame/33767/yavalath

Players strive to make a straight line of 4 pieces of their colour, but lose if they make a line of 3 before doing so.

airtoxin commented 6 years ago

Sorry, I found way to define loser, returning object containing loser's id in victory function.

victory: (G, ctx) => {
    if (isDefeat(G.cells)) return { loser: ctx.currentPlayer };
    if (isVictory(G.cells)) return { winner: ctx.currentPlayer };
    return null;
  }

But victory naming is bit bad :(

nicolodavis commented 6 years ago

victory is a very familiar concept for most games, and I think it's OK to overload it for cases like this too. Let me know if you need any help or run into other issues while developing Yavalath!