
Boardgame.io: State management and more for turn-based games - ingve
https://google.github.io/boardgame.io/
======
dwaltrip
This is awesome. It's great to see a lot of projects coming out in this area.

I've been working on a similar project for over a year now. It's essentially
this exact concept turned into an entire platform for designing/creating board
games and then publishing the game so others can play it directly on the
platform. Think of heroku or squarespace for board games.

I have a very rough, working prototype of the editor and game engine. There is
a ton left to do (I could write pages about what I'd like to
implement/improve). But, I'm at least finally getting _somewhere_ with it.

At the risk of utterly destroying my server... for anyone who is interested, I
have a demo site for the game editor prototype. A game can be test played from
the editor by clicking "game play tester" in the upper-left menu. There are no
docs or anything. But there are several games already implemented on the demo
server.

    
    
      url: http://strat-city-demo.herokuapp.com
      username: demo
      password: password
    

Please be kind to the demo server. I just threw it up to show a few people --
it's not robust at all.

I would love feedback! My e-mail is dwaltrip77@gmail.com.

Note: the interface for editing the "Game UI" is going to be completely redone
so that it uses the same type of visual programming code-blocks as found in
the "Core Logic" editing interface. Right now the game UI code format is
simply javascript that becomes a react.js render function.

~~~
arghbleargh
Looks very interesting! I don't completely understand how to use it (and I
guess not everything works yet?), but the UI looks nice, and it looks like it
has some really cool features.

I have a project along these lines as well:
[https://github.com/zhaizhai/turnbase](https://github.com/zhaizhai/turnbase) .
That's a somewhat cleaned-up version that I put on github recently; I actually
started it almost five years ago. You can see an example implementation of
Battleship here:
[https://github.com/zhaizhai/turnbase/blob/master/games/battl...](https://github.com/zhaizhai/turnbase/blob/master/games/battleship/battleship.iced)

I once had visions of a "code-blocks" interface like you're doing, but you've
certainly gotten a lot farther than me on that front. I'd love to find out
more about what you're doing and if any of my code can help (will send you an
email). I don't actually have time to work on this project seriously, so I'm
happy to share whatever experience I've gained so that it doesn't go to waste
:).

~~~
dwaltrip
Thanks for the e-mail! We should definitely chat sometime.

------
scrollaway
Oh man that's interesting. Clearly a WIP, but there's a lot of potential
there.

If the person who made this is around: I'm the author of Fireplace
([https://github.com/jleclanche/fireplace/](https://github.com/jleclanche/fireplace/)),
a Hearthstone simulator, and I worked a ton on the Hearthstone game state
protocol (docs: [https://hearthsim.info/docs/gamestate-
protocol/](https://hearthsim.info/docs/gamestate-protocol/)). Hit me up by
email (profile) or Discord (jleclanche @ [https://discord.gg/hearthsim-
devs](https://discord.gg/hearthsim-devs)), I bet we could have a really
interesting knowledge exchange :)

This is making me want to try to implement a Hearthstone prototype in it to
see if it's feasible. I've been _dying_ to implement a copy-on-write
Hearthstone simulator. Although this seems to tie the game logic with the
protocol quite tightly, which hopefully is fixable or can be worked around;
one of the designs I worked on with my simulator was a pluggable game state
protocol to allow separation of a game state server that dispatches the
gamestate data from the simulator itself that could then be implemented in any
language. Incidentally, this allowed our Hearthstone replayer (written in
React:
[https://github.com/HearthSim/Joust](https://github.com/HearthSim/Joust)) to
connect to "real" games and be a live client, in a way that is eerily similar
to this project's showcase.

~~~
jackstraw14
Just wanted to say thanks for the links to your docs. Games like Michael
Brough's (Imbroglio, 868-HACK) and Hoplite have really shifted my videogame-
playing interest to turn-based stuff lately, and being a bored dev I'm
naturally thinking about what's possible with these frameworks. I'm grateful
for devs like you who take the time to write about the stuff you've learned.
We're all learning and it's so much more fun to find documentation of how
similar stuff has been implemented. Seems like it more seamlessly syncs up
with the excitement and motivation when you find something like Boardgame.io.
Anyway I really appreciate it!

~~~
scrollaway
Thanks for the kind words! I've been passionate about the tech and data
science aspect of video games forever and I'm super lucky to have had the
opportunity to built a company out of it. HearthSim is a labour of love :)

------
afpx
I was so excited to see this. A year ago I tried to distill a bunch of popular
board games down to discrete rules that could be dropped into a generalized
framework. I wanted game designers to be able to quickly model and prototype
games. I also was interested in games where the players get to evolve the
rules over time.

However, it ended up being way harder than I expected. In fact, I tabled it
indefinitely because I started to believe that it was just intractable. (That
is, trying to conceptualize a game into a discrete rule set is often a lot
more work than just implementing it in code.)

I'm glad to see others trying to tackle this. But, I hope they try to
implement games that are significantly more complex and sophisticated than
tic-tac-toe though. The current code is so simplistic that I can't imagine
that it will help much. That is, if I used it, I'd still have to custom-code
99% of the logic. But, at least it's a start.

~~~
TheCowboy
It's tempting to take the "abstract all the things" approach when you take a
swing at board games. I started down that path, wanted the ability to
implement any variation, and it was much more difficult to contain even if
just focusing on the card-based "board game" genre.

I think if one truly took this approach to the logical end, they would end up
creating their own specialized board game programming language.

~~~
lfowles
> I think if one truly took this approach to the logical end, they would end
> up creating their own specialized board game programming language.

That's what I was planning on saying. A set of discrete rules detailed enough
to represent most board games would end up looking a lot like an interpreted
programming language.

------
rawnlq
Was totally expecting this to be a plug for firebase (google's realtime
database) but it actually comes with a koa server using websockets. Seems to
be built with redux under the hood. No fancy conflict resolution and does
syncing by serializing entire app state and sending it to each client after
each move.

~~~
julee04
i was expecting the same as well. glad it wasnt!

~~~
philsnow
why are you glad, because google bought them? rewind to before the acquisition
and there was a lot of positive sentiment towards things built using firebase.

~~~
TheAceOfHearts
It's closed source and there's no API-compatible self-hosted open source
version. Vendor lock-in is a big concern for many people.

------
JoeDaDude
I am intrigued, but is this an improvement over existing game-as-a-state
machine languages? I'm thinking of Stanford's Game Definition Language [1] and
AI-ai's Modular Game Language [2].

[1]
[http://games.stanford.edu/games/gdl.html](http://games.stanford.edu/games/gdl.html)

[2] [http://mrraow.com/index.php/aiai-
home/mgl/](http://mrraow.com/index.php/aiai-home/mgl/)

------
EGreg
This is excellent. That's the approach we have taken with the Qbix Platform,
taking care of all the syncing and realtime updates and offline notifications
and user accounts so you can just throw some tools on a page, make a new type
of stream or tool (such as _Chess /game_) and it just works across all
devices.

There is a lot that goes into this - for instance offline notifications must
be delivered to each user's preferred endpoints (in app notifications if they
installed cordova app, sms and email fallbacks if they didn't), you need to
fill templates, enforce access control (can I see a guy's last name or a
particular game / chat / etc?)

If you look at
[https://qbix.com/platform/features](https://qbix.com/platform/features) you
will see we went with Streams and Messages rather than syncing data
structures. This allows us to reason about explicit "moves in a game" or other
changes and whether they are authorized or not per Stream.

In short - I am happy to see others adopting similar goals. Most of what I
have seen til now has been syncing static data structures.

------
cokeeffekt
At the risk of being another shameless plug this is a subject i've dedicated a
good chunk of time to over the last 4 years in a project to simulate mechanics
of CCG / TCG card games. The goal is to give the user only what a table and
paper game would provide. [https://untap.in](https://untap.in)

It's all in browser, supports up to 6 player multiplayer card games, BYO cards
(user uploads card images). YES you can spectate games if you want to have a
look.

This has been a growing industry, i have noticed in the last 4 years people
like the idea of being in control of their game, playing on the mistakes their
opponents make and having the skill to think about the game with out the
computer doing the work for you like in most digital card/boardgames from
today.

Untap.in is a personal project, has about 100k registered users and 1600 daily
active, its a big community. All of this is being serviced by a sole dev
(myself) in my free time. The likes of these frameworks should make it
extremely easy to get board games through prototype and playable, its a great
thing.

------
IIAOPSW
I wish there were an English word for when you're happy something exists but
annoyed that someone else did it before you.

~~~
foobarian
"PhD student?" Not quite one word but describes it to a T ;-)

------
nikisweeting
Shameless plug, but at my company we had a similar set of requirements (game
synced between browsers in real time), but for poker instead of a board game
([https://oddslingers.com](https://oddslingers.com))! We tried a bunch of
different solutions, and ended up writing a pure functional, declarative,
animations framework for redux called redux time:
[https://github.com/Monadical-SAS/redux-time](https://github.com/Monadical-
SAS/redux-time).

It does similar things like server-time-synced animations across multiple
browsers, except the state is all managed by the backend.

------
tsukikage
Something similar I did back at uni:
[https://www.toothycat.net/wiki/wiki.pl?ToothyGDL](https://www.toothycat.net/wiki/wiki.pl?ToothyGDL)

This was an exercise in a toy language that was deliberately _not_ Turing
complete, yet expressive enough for boardgame rules.

Interesting to see how things have moved on

------
10-6
this is great, the docs/tutorial are pretty clear as well. shameless plug: I
made a js library [0] for creating and playing board games a while ago. It
allows you to focus on gameplay and logic without worrying about the user
interface so much. It allows you to create games like chess [1] and
simulations like game of life [2] pretty easily.

[0]
[https://github.com/danielborowski/jsboard](https://github.com/danielborowski/jsboard)

[1]
[https://danielborowski.github.io/site/jsboard/demo/demo8/](https://danielborowski.github.io/site/jsboard/demo/demo8/)

[2]
[https://danielborowski.github.io/site/jsboard/demo/demo9/](https://danielborowski.github.io/site/jsboard/demo/demo9/)

------
krab
This looks quite similar to Vassal -
[http://www.vassalengine.org/](http://www.vassalengine.org/)

~~~
mtremsal
I see a Bugzilla tracker, but I can't find the official git repo for Vassal.
Would you mind pointing me in the right direction?

~~~
trynewideas
Still a Sourceforge project AFAIK:
[https://sourceforge.net/p/vassalengine/svn/HEAD/tree/](https://sourceforge.net/p/vassalengine/svn/HEAD/tree/)

------
bbq
Frame your problem as a game, let AlphaZero take a shot. Now we just need the
AlphaZero part.

~~~
EGreg
That kind of deep learning (MCTS) only works if it can play against itself.

Many things require a human in the loop -- judging whether a joke is funny,
for instance, or clinical trials or educational apps.

What are some good AI learning things for that?

------
cableshaft
I've been playing around with coming up with my own system like this for
awhile. If you've saved me a bunch of time, then thank you. I design a lot of
simple board games, and I need something to make translating them into video
game form quicker and easier.

------
trsse
It looks like it uses sockets under the hood for client server communication
-- are there reasons it could not be used in a game with much quicker state
updates, like the plane game that was posted here earlier last week (think FPS
MMO in the browser)?

~~~
brianshaler
I'm pretty sure websocket is fifo with delivery guarantees and as far as I'm
aware cannot be used in the same manner as UDP. I haven't played around with
WebRTC, but that might be an option.

~~~
vvanders
Yeah, fifo and temporal updates generally tend to not mix well together.

~~~
sillysaurus3
Airmash uses two websockets and accepts updates from whichever arrives first.
It's still fifo, but if one experiences fragmentation the other might be fine.

It's an interesting design and I wonder how well it works.

~~~
jkarneges
Wow that multiple TCP connection trick is very interesting. Each additional
idle connection would theoretically be capable of firing off a single packet
instantly with no congestion control getting in the way. I'm getting
flashbacks of services that would allow multiple pending HTTP long-polling
requests at once, so the server could push faster than the round trip time.

I wonder what the ideal number of connections would be. It could certainly be
2 of course; I've never thought about this problem before.

~~~
sillysaurus3
Valve mentioned that in practice packets are dropped about 5% of the time, so
two connections might theoretically reduce that to 5%^2, or 0.25%. Meaning out
of every 1,000 seconds of playtime, only 2 seconds would be disrupted rather
than 50s.

It seems unlikely to be as clear-cut as this, since two connections from the
same host to the same endpoint will probably use the same route to get there.
So why would using two connections avoid retransmission? But it's worth
checking whether it works.

~~~
vvanders
It can be worse than that since TCP/IP will do exp backoff depending on your
packet loss. Which is awesome for file transfers but pretty awful for real-
time data.

There's a great article way back about X-Wing vs Tie Fighter and all the pain
they went through with TCP/IP[1].

[1]
[https://www.gamasutra.com/view/feature/131781/the_internet_s...](https://www.gamasutra.com/view/feature/131781/the_internet_sucks_or_what_i_.php?print=1)

------
nhooyr
The tutorial game seems to have a bug.

[https://google.github.io/boardgame.io/#/tutorial](https://google.github.io/boardgame.io/#/tutorial)

Sometimes, turns are repeated. E.g. if a square is clicked and marked 0, then
the next square that is clicked is also marked 0. Only happens sometimes
though and I have only produced it on the first turn. I'm not sure what the
cause is.

~~~
xhroot
Yeah, I filed
[https://github.com/google/boardgame.io/issues/9](https://github.com/google/boardgame.io/issues/9).
The source in github does check if the cell is filled [1] but the demo code
must be from an earlier version that didn't.

[1]
[https://github.com/google/boardgame.io/blob/master/examples/...](https://github.com/google/boardgame.io/blob/master/examples/tic-
tac-toe/tic-tac-toe.js#L81)

------
beshrkayali
Anyone knows why so many non-google product project (with a big disclaimer
that this is not google) are hosted on google's github?

~~~
jjn2009
I would guess these types are projects are ones done in 20% time at google.

~~~
kakarot
That guy who blasted Google on HN a while back (not the memo guy) said that
since new management has come in over the last few years, 20% time is as good
as dead. I couldn't find a link, sorry.

------
Jonovono
This is really cool. I'm working on a mobile app [1] that lets you play social
games with your friends over video chat. We built it in React Native and I was
envisioning creating something like this to build our games.

We havn't gotten there but are exploring other services for the backend like
Nakama [2] and Colyseus [3]. Right now we are just using Firebase for the
multiplayer sync and building raw RN components with no library essentially
and that's been working pretty good.

I'm gonna look into this library some more, looks promising :)

[1]: [http://gameroom.co/](http://gameroom.co/) [2]:
[https://heroiclabs.com/](https://heroiclabs.com/) [3]:
[https://github.com/gamestdio/colyseus](https://github.com/gamestdio/colyseus)

------
nibuen
Very cool! I have a site been building for earlier stages of prototyping:
[http://www.iterary.com/](http://www.iterary.com/) with the idea you might use
it during excel designs, etc. Still working on better integrations with
excel/google sheets.

------
purple-again
Thanks for sharing, this just inspired me out of my code funk and back into
developing!

------
avenoir
I'm not a gamer or a game developer, but this is absolutely brilliant. Very
clean API and I'm sure a lot to be done with this features-wise. Best of luck!

------
mofirouz
I'd love to explore how this framework can be applied to Nakama
([https://github.com/heroiclabs/nakama](https://github.com/heroiclabs/nakama)).
I'll see if I can find some time to experiment with it over Christmas.

~~~
racer-v
This looks pretty interesting. Could Nakama be used to build a federated,
decentralized application (let's say, game world) where each user self-hosts
on his own Docker instance?

~~~
novabyte
The way Nakama is designed right now would not lend itself well to a
decentralized game world right now. There's another project of ours which will
address what you have in mind but not until the new year.

Disclaimer: I work on Nakama. :)

------
dlhavema
looks like a cool framework.

are there any provisions for multiplayer games that have player-specific
knowledge? like cards or tiles that other players can't see? right now all
game state is sent over the wire every time... would you just only send
pertinent data to each player on their turn?

------
grenoire
I was confused on what was so exciting about it, but it comes with built-in
multiplayer!

------
chrisweekly
Brilliant! I'd love to combine this with terrific "Cheap-Ass Games" (like
"Kill Dr Lucky") ...

------
kylegalbraith
This is a really cool idea! I can't wait to see the kinds of games that could
be built out with this.

------
alikoneko
This actually confused me slightly. I'm working on a personal project called
BoredGaming.io.

------
amitport
a _Shameless plug_ :
[http://www.cardforest.com/Demos/War](http://www.cardforest.com/Demos/War)
(live editable card game logic written in coffescript, multiplayer is WIP)

------
adamnemecek
Is there a good resource on category theoretical or linear logical game
design?

~~~
mbrock
Check out Chris Martens' work, like her thesis "Programming Interactive Worlds
with Linear Logic":

[http://www.cs.cmu.edu/~cmartens/thesis/](http://www.cs.cmu.edu/~cmartens/thesis/)

(or some of the shorter papers on her website)

~~~
adamnemecek
Thx, I saw this on HN a while back but totally forgot it existed.

------
dogruck
Is there a list of some games that were built using this cool framework?

~~~
Jyaif
Here it is:

------
racer-v
I'd love to see the client-side state extended so that this could be a
framework for decentralized turn-based games, without using a centralized
server.

 _One concrete cause of centralization in today 's Internet is a difference in
programming costs between a closed centralized solution and an open
decentralized one. Let's say we're writing a tic-tac-toe app. In the
centralized design, the game board is one data structure. Your score and mine
are two variables. You'll be done in a couple of hours.

As an open decentralized solution, you're building a federated system. You
need a standard protocol for communicating tic-tac-toe moves. Maybe you should
work through the IETF to write an RFC for OTTTP: the Open Tic-Tac-Toe
Protocol. You might be done in 2018. When solving a problem the wrong way
takes two hours, and solving it the right way takes two years, it's going to
get solved the wrong way._

[https://www.youtube.com/watch?v=g1qroWiZF90](https://www.youtube.com/watch?v=g1qroWiZF90)

Note that I don't endorse the particular solution in this video - MirageOS is
perhaps a more viable alternative.

