
A multiplayer board game in Rust and WebAssembly - lukastyrychtr
http://www.mattkeeter.com/projects/pont/
======
nurettin
The best part of having the same language on both the server and the client is
that you can have the same code running client side validations and do the
same move on the server to avoid cheating. If validations are only done on the
client, they will just send a winning board state.

~~~
filleduchaos
There's zero need to have any validations[0] on the client in a turn-based
online multiplayer game. If your state and logic aren't pretty much entirely
on the server for that, you're doing it wrong.

[0] Of course, for smoothness/convenience one could do some basic checks on
the client.

~~~
reitzensteinm
I run my logic on the client and the server, and I'm not doing it wrong.

Your techniques may work for you but don't make the mistake of thinking
they're universal.

~~~
filleduchaos
I didn't say they were universal. I do stand by what I actually said: for this
category of games, running logic on the "client" isn't the best of
architectures.

~~~
reitzensteinm
I run it on both. If you need to provide some UI context, being able to reach
in to the state and query it is a life saver.

Imagine Advance Wars. Their unit movement is very subtle.

You can choose the path the units travel, which can turn in to a forced action
if you stumble onto an ambush unit. When you reach the end it tells you the
outcome of your battle before you confirm you want to engage in it.

Doing logic only on the server and sending down a list of possible moves is
going to get pretty heavy. Querying for each square of movement is going to be
a latency nightmare.

Edit: actually, I think the movement ambush is from a clone. Although the
arrow movement from the original is still complicated. That doesn't weaken the
argument: imagine getting half way in to dev and realizing you can't add that
feature with your architecture.

~~~
filleduchaos
I haven't played Advance Wars, so that definitely affects my answer, but by
looking at it and reading a couple of reviews it seems rather like chess (and
was directly compared to it) - and chess is something I've implemented like I
describe with no problem. It's surprising how far you can get by putting some
thought into the data interchange format between your client and server.

~~~
reitzensteinm
Chess with potentially thousands of moves per unit.

~~~
jbperry
On any given turn there really isn't that many possible moves.
[https://chess.stackexchange.com/questions/4490/maximum-
possi...](https://chess.stackexchange.com/questions/4490/maximum-possible-
movement-in-a-turn)

~~~
peterstensmyr
They are describing Advance Wars, not chess.

------
mkeeter
Original author here, happy to answer any questions.

I also appreciate the load testing! For the curious, we're at 30 open rooms,
and I'm seeing:

\- 0.0 server load

\- 2.6 MB of RAM used by nginx + its worker process

\- 4 MB used by pont-server

~~~
silasrude
Will the rooms stick around if people leave the page in the middle of a game?
My wife loves the game btw. I enjoy it as well but I appreciate the stack
behind it more. Ty for your efforts.

~~~
mkeeter
I'm glad that your wife enjoys the game! At the end of the day, it's meant to
be played and shared, rather than just existing as an interesting software
artifact.

The rooms persist as long as there's at least one connected player in them.
Exiting + rejoining a room under the same name will let you continue to
accumulate points under that name.

(Rejoining isn't perfectly seamless: you won't necessarily be dealt the exact
same hand, and if you exit + rejoin while it's your turn, your turn will be
skipped)

~~~
dpc_pw
Some persistence timeout even without any players would be nice.

------
HugoDaniel
> "Is there a Rust + wasm version of Svelte yet?"

Here is a Svelte starter template for Rust (webasm) + Svelte:

[https://github.com/HugoDaniel/svelte-
template](https://github.com/HugoDaniel/svelte-template)

~~~
chrismorgan
OP is asking for a Rust port of Svelte, rather than using Svelte itself and
adding WASM code alongside.

I started such a thing a while back, but progressively decided the design
wasn’t right for Rust, and so headed in a somewhat different direction, and
then shelved the project after deciding to implement what I had had in mind
differently.

~~~
HugoDaniel
how much better can it be than doing

`import module from './crate/Cargo.toml'`

from Svelte directly, and get Hot Module Reloading for free ?

------
nicolodavis
Nice!

I'm using a very similar architecture for
[https://boardgamelab.app/](https://boardgamelab.app/).

The WebAssembly performance boost will make a difference once I've implemented
MCTS bots for the platform.

------
kriro
Very nice. How do you auto generate the bots from the game rules? I'm assuming
you just have them play the game a lot against each other and use genetic
algorithms/reinforcement learning (you'd need some rules about scoring)?

Do you have the option to generate different bot difficulty levels?

~~~
nicolodavis
I'm assuming that you're asking about Boardgame Lab (from the other comment).

The basic version just uses Monte Carlo Tree Search and the game's victory
condition to play the game. This won't result in a very strong bot for most
games, but is a reasonable opponent to play your game against (which is very
useful when designing a game).

Options to make the bot stronger involve giving it hints and shorter term
objectives.

------
mroche
> The game server using async Rust, which was... exciting

As someone interested in Rust but not currently using it, what is the state of
async? An expansion on the bullet points following regarding runtime scope
would be interest.

~~~
k_bx
I’m using Tokio and Async_std (Actix Web, redis, reqwest ), everything’s great
and feels pretty mature, except for the scary part of no warning when using
sync code from it.

------
ludston
Cute game.

You can get into a state where there are no valid moves though:
[https://imgur.com/1WLufcx](https://imgur.com/1WLufcx)

~~~
mkeeter
It's true!

I considered adding some kind of fix for that, but a fresh game is a mere
refresh away, and I liked the opinion on Board Game Geek [1]:

> It's probably also worth noting that if this happens then all players
> involved need to re-visit some ideas of basic strategy.

[1] [https://boardgamegeek.com/thread/861192/if-game-stuck-
perfec...](https://boardgamegeek.com/thread/861192/if-game-stuck-
perfectly-6x6-grid-then-what)

------
mrunkel
Very nice.. I am probably going to containerize this, would you be interested
in a pull request?

~~~
mkeeter
Thanks for the offer!

I'd rather not have it in the main repo, since I won't be maintaining it. If
you make your own pont-docker repo that contains the Dockerfile, I'd happily
accept a PR that links to it in the README.

~~~
mrunkel
I'd be happy to do that.

------
cozuya
Do you have the license or permission from the original creators to duplicate
their IP?

~~~
pjfin123
At least in the U.S. game rules aren't covered by copyright even though the
art and any expressions of the rules are.

[https://www.copyright.gov/fls/fl108.pdf](https://www.copyright.gov/fls/fl108.pdf)

------
otachack
This is great stuff. Thanks for sharing it, I'll be checking it out to learn
more!

------
baby
I’ve been thinking about writing a boardgame with websockets a lot. The
technology is here, the current climate for online boardgame is here, but
weirdly it’s not happening.

~~~
grammarnazzzi
That's great. Really awesome. Thanks for sharing

