Skip to content

Add a game visualizer using the PTN-Ninja API#6

Open
ViliamVadocz wants to merge 6 commits intoMortenLohne:masterfrom
ViliamVadocz:visualizer
Open

Add a game visualizer using the PTN-Ninja API#6
ViliamVadocz wants to merge 6 commits intoMortenLohne:masterfrom
ViliamVadocz:visualizer

Conversation

@ViliamVadocz
Copy link

  • New --visualize flag that will enable visualization
  • Each game gets a separate window and can run concurrently
  • The moves are played live using PTN-Ninja's embed API

The code is quite hacky, and I also pull in 3 dependencies, so no worries if you do not want to merge.

How it works

  1. The main thread starts a WebSocket server which awaits WebSocket connections. This thread also has a Receiver that will be used to receive a per-game Receiver<visualizer::Message>.
  2. Each game thread opens a browser running visualizer.html which contains a PTN-Ninja embed.
  3. Once PTN-Ninja is loaded, the window creates a WebSocket connection to the server and is ready to receive PTN-Ninja API messages that it forwards to the embed.
  4. The WebSocket connection on the server triggers a creation of a new thread (let's call it a sub-thread) which soon receives a Receiver<visualizer::Message> from a game thread.
  5. The game thread talks to to this sub-thread over this channel that was sent over, and it sends a Message::Start, and afterwards Message::Ply for the moves in the game.

Telephone game

PTN-Ninja iframe
🠕 contentWindow.postMessage()
visualizer.html
🠕 WebSockets (JSON)
WebSocket Server sub-thread
🠕 Receiver<visualizer::Message>
game thread

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.

1 participant