SlideShare a Scribd company logo
go-man API
Learning go-lang & writing a game
Why?
 By day: I am architect/developer hacking
at Java based api’s
 By night: Still harboring a passion for
video games and regularly write small
games to try out new tech on my daily
commute (rarely finish them…)
Fusion
Why not combine both pursuits to retain a
level of interest?
Goals:-
 Better understanding of go-lang
 Maybe and actual finished skunkworks
project?
Dissecting the game
 Broke the idea of “pac-man” down to a
series of API calls.
 Create game
 Add player(s)
 Move players
 Repeat to fade
Concurrency
 Lightbulb moment!
 Multiple players in same game =
concurrency
Parallelism
 Multiple games in single server =
parallelism
Caveats
 Probably not the best way to do this
 First golang code I’ve developed
 Highly inefficient
 Websockets would’ve been MUCH better
 BUT, it’s fun to try it
Starting the game
HTTP POST request to create a new game with
following parms:-
 Game name
 Max number of GoMen
 Max number of GoGhosts
 Time to wait for players
What happens?
 Creates new game on server
 Creates golang process waiting for timeout to start
game.
 Creates a single channel to listen for player
updates
Add players to game
HTTP PUT request to add a player to a
game with parms:-
 Game id
 Player name
 Player type (GoMan/GoGhost)
If total players reached game will begin
otherwise game waits for players
Time up
If wait time expires, game server adds
remaining players as CPU controlled players.
Creates new golang process for each missing
player
Dumb AI:
Wait for ¼ second.
Pick random number between 0-3
Send move request to game channel
repeat…
Game States
“new” – just created
“waiting” – waiting for players to join
“playing” – game active
“over” – all GoMan players have died
“won” – all pills eaten
Power Pills
If a player eats a power pill a separate
golang process is submitted that waits for
duration of pill. At end of timer game reverts
to normal.
Game Client
Originally I started developing a separate
client in go-lang.
Stopped development of this because I
wanted people to try the game easily on the
web.
Switched to JavaScript based client as this
was the most likely client to consume the
API.
Game Client - technology
 HTML5 + JavaScript
 Twitter bootstrap
 HTML5 canvas
 Ajax calls to RESTful API
Game Client - features
 List games
 Create new game
 Join existing game
 Play game
Game Server
Server implements MVC pattern:
Models = game board + players
View = JSON representation of game state
Controller = RESTful API calls to perform
CRUD on a game instance.
Game Server - technology
 Standalone golang executable or
 Google app engine app
Uses:
 Gorillamux (for http routing)
 Game state stored in memory
Game Server – lessons learned
Things I learned during development:-
Started using filesystem as simple datastore for
games. Got tired of serialisation / deserialisation and
realised it was unnecessary for my simple demo.
Originally modeled board cells as a 2d byte array.
But these force client to have to deal with Base64
encoded binary data (nasty). Changed definition to a
2d array of “runes” for an easier life.
BoardCells [][]rune
Game Server – logic
 All game logic resides on server. Game
state / player state etc.
 Game clients are completely dumb.
 Weakness in API is that players are not
authenticated so they could easily fake
each others moves by using the other
player’s GUID.
Game Server – concurrency
 Game controller writes PlayerMove
requests to a single channel (one per
game)
 This prevents concurrent updates to same
board (two players eaten same pill etc.)
 PlayerMove request includes a unique
response channel, to return response
back to original requester
Game Server – concurrent requests
move me
Game
request
channel
Players can be either remote web players
or local CPU controlled players on server
Game Server – concurrent responses
Players receive a new instance of the
Game board after their move
Bad move
Game Server – stats
golang is FAST!
 Normal game 1 goman & 4 goghosts runs
in browser @ 60fps
 5 x 60 (300) requests per second.
Average 3k per response. 1MB per sec
traffic.
 Running locally it is handled with ease
80+ players in a single game
 DO NOT PLAY ON MOBILE PHONE
WITH DATA CONTRACT!!!
Game Models - GameBoard
type GameBoard struct {
Id string
Name string
PillsRemaining int
Players map[string]*Player
MaxGoMenAllowed int
MaxGoGhostsAllowed int
WaitForPlayersSeconds int
State GameState
PowerPillsActive int
CreatedTime time.Time
LastUpdatedTime time.Time
GameStartTime time.Time
BoardCells [][]rune
}
Game Models - Player
type Player struct {
Location Point
Id string
Type PlayerType
State PlayerState
Name string
cpuControlled bool
Score int
Lives int
}
Game Models - GameState
const (
NewGame GameState = "new"
WaitingForPlayers = "waiting"
PlayingGame = "playing"
GameWon = "won"
GameOver = "over"
)
Game Models - PlayerState
const (
Alive PlayerState = "alive"
Dying = "dying"
Dead = "dead"
Spawning = "spawning"
)
Game Models - PlayerMove
Request interface
type PlayerMove struct {
GameId string
PlayerToMove Player
ResponseChannel chan (PlayerMoveResponse)
}
Response interface
type PlayerMoveResponse struct {
Board GameBoard
Error error
}
Response written back to channel passed in request
ASCII Client
HTML5 Canvas Client
Demo
Client: http://go-man-client.herokuapp.com/
(Hosted as simple static site)
Source: https://github.com/telecoda/go-man-javascript-client
API: http://go-man-app.appspot.com
(Hosted on single GAE instance)
Source: https://github.com/telecoda/go-man-app
Wiki: https://github.com/telecoda/go-man-app/wiki
About me
robbaines@gmail.com
@telecoda

More Related Content

What's hot

Final presentation
Final presentationFinal presentation
Final presentation
rabman
 
Desktop Application In Linux
Desktop Application In LinuxDesktop Application In Linux
Desktop Application In Linux
Kunchana Mathota Arachchi
 
Local development environment
Local development environmentLocal development environment
Local development environment
John Dorner
 
GNU Backgammon vs eXtremeGammon - my favourite features
GNU Backgammon vs eXtremeGammon - my favourite featuresGNU Backgammon vs eXtremeGammon - my favourite features
GNU Backgammon vs eXtremeGammon - my favourite features
Wayne Joseph
 
Remastering of ubuntu
Remastering of ubuntuRemastering of ubuntu
Remastering of ubuntu
Amit Karpe
 
Emulation: Machines Within Machines
Emulation: Machines Within MachinesEmulation: Machines Within Machines
Emulation: Machines Within Machines
School
 
warp engine - an open source realtime push engine
warp engine - an open source realtime push enginewarp engine - an open source realtime push engine
warp engine - an open source realtime push engine
David Pichsenmeister
 
Installing Japanese environment(mozc) on Debian 8 + Mate
Installing Japanese environment(mozc) on Debian 8 + Mate Installing Japanese environment(mozc) on Debian 8 + Mate
Installing Japanese environment(mozc) on Debian 8 + Mate
Ikuru Kanuma
 
Squash that Bug!
Squash that Bug!Squash that Bug!
Squash that Bug!
Stefan Fodor
 
Amazon Ec2
Amazon Ec2Amazon Ec2
Amazon Ec2
Keiichi Daiba
 
Developing Multiplayer Games in Unity3D
Developing Multiplayer Games in Unity3DDeveloping Multiplayer Games in Unity3D
Developing Multiplayer Games in Unity3D
Adrian Popovici
 

What's hot (11)

Final presentation
Final presentationFinal presentation
Final presentation
 
Desktop Application In Linux
Desktop Application In LinuxDesktop Application In Linux
Desktop Application In Linux
 
Local development environment
Local development environmentLocal development environment
Local development environment
 
GNU Backgammon vs eXtremeGammon - my favourite features
GNU Backgammon vs eXtremeGammon - my favourite featuresGNU Backgammon vs eXtremeGammon - my favourite features
GNU Backgammon vs eXtremeGammon - my favourite features
 
Remastering of ubuntu
Remastering of ubuntuRemastering of ubuntu
Remastering of ubuntu
 
Emulation: Machines Within Machines
Emulation: Machines Within MachinesEmulation: Machines Within Machines
Emulation: Machines Within Machines
 
warp engine - an open source realtime push engine
warp engine - an open source realtime push enginewarp engine - an open source realtime push engine
warp engine - an open source realtime push engine
 
Installing Japanese environment(mozc) on Debian 8 + Mate
Installing Japanese environment(mozc) on Debian 8 + Mate Installing Japanese environment(mozc) on Debian 8 + Mate
Installing Japanese environment(mozc) on Debian 8 + Mate
 
Squash that Bug!
Squash that Bug!Squash that Bug!
Squash that Bug!
 
Amazon Ec2
Amazon Ec2Amazon Ec2
Amazon Ec2
 
Developing Multiplayer Games in Unity3D
Developing Multiplayer Games in Unity3DDeveloping Multiplayer Games in Unity3D
Developing Multiplayer Games in Unity3D
 

Similar to go-man API

Behind the Scenes: Deploying a Low-Latency Multiplayer Game Globally
Behind the Scenes: Deploying a Low-Latency Multiplayer Game GloballyBehind the Scenes: Deploying a Low-Latency Multiplayer Game Globally
Behind the Scenes: Deploying a Low-Latency Multiplayer Game Globally
James Gwertzman
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
Xie ChengChao
 
Making a game "Just Right" through testing and play balancing
Making a game "Just Right" through testing and play balancingMaking a game "Just Right" through testing and play balancing
Making a game "Just Right" through testing and play balancing
Julio Gorgé
 
Full stack development in Go
Full stack development in GoFull stack development in Go
Full stack development in Go
Yves Junqueira
 
GDC Next 2013 - Synching Game States Across Multiple Devices
GDC Next 2013 - Synching Game States Across Multiple DevicesGDC Next 2013 - Synching Game States Across Multiple Devices
GDC Next 2013 - Synching Game States Across Multiple Devices
David Geurts
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with Canvas
Pham Huy Tung
 
Proving correctness of a multiplayer game server
Proving correctness of a multiplayer game serverProving correctness of a multiplayer game server
Proving correctness of a multiplayer game server
IndicThreads
 
SuperStreamer: Enabling Progressive Content Streaming in a Game Engine
SuperStreamer: Enabling Progressive Content Streaming in a Game EngineSuperStreamer: Enabling Progressive Content Streaming in a Game Engine
SuperStreamer: Enabling Progressive Content Streaming in a Game Engine
Anand Bhojan
 
Dedicated Game Servers
Dedicated Game ServersDedicated Game Servers
Dedicated Game Servers
webhostingguy
 
Unit 20 - Game Platforms
Unit 20 - Game PlatformsUnit 20 - Game Platforms
Unit 20 - Game Platforms
Gulshan Golechha
 
Unit 20 - Game Platforms
Unit 20 - Game PlatformsUnit 20 - Game Platforms
Unit 20 - Game Platforms
Gulshan Golechha
 
Writing a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media playerWriting a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media player
Tikal Knowledge
 
Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf eu
Xie ChengChao
 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
slantsixgames
 
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
Amazon Web Services
 
Programming Language Final PPT
Programming Language Final PPTProgramming Language Final PPT
Programming Language Final PPT
Matthew Chang
 
GDC 2015 - Low-latency Multiplayer Gaming with AWS
GDC 2015 - Low-latency Multiplayer Gaming with AWS GDC 2015 - Low-latency Multiplayer Gaming with AWS
GDC 2015 - Low-latency Multiplayer Gaming with AWS
Nate Wiger
 
Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)
Noam Gat
 
Lessons Learned with Unity and WebGL
Lessons Learned with Unity and WebGLLessons Learned with Unity and WebGL
Lessons Learned with Unity and WebGL
Lior Tal
 
Lets Play Together
Lets Play TogetherLets Play Together
Lets Play Together
Amir H. Fassihi
 

Similar to go-man API (20)

Behind the Scenes: Deploying a Low-Latency Multiplayer Game Globally
Behind the Scenes: Deploying a Low-Latency Multiplayer Game GloballyBehind the Scenes: Deploying a Low-Latency Multiplayer Game Globally
Behind the Scenes: Deploying a Low-Latency Multiplayer Game Globally
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
 
Making a game "Just Right" through testing and play balancing
Making a game "Just Right" through testing and play balancingMaking a game "Just Right" through testing and play balancing
Making a game "Just Right" through testing and play balancing
 
Full stack development in Go
Full stack development in GoFull stack development in Go
Full stack development in Go
 
GDC Next 2013 - Synching Game States Across Multiple Devices
GDC Next 2013 - Synching Game States Across Multiple DevicesGDC Next 2013 - Synching Game States Across Multiple Devices
GDC Next 2013 - Synching Game States Across Multiple Devices
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with Canvas
 
Proving correctness of a multiplayer game server
Proving correctness of a multiplayer game serverProving correctness of a multiplayer game server
Proving correctness of a multiplayer game server
 
SuperStreamer: Enabling Progressive Content Streaming in a Game Engine
SuperStreamer: Enabling Progressive Content Streaming in a Game EngineSuperStreamer: Enabling Progressive Content Streaming in a Game Engine
SuperStreamer: Enabling Progressive Content Streaming in a Game Engine
 
Dedicated Game Servers
Dedicated Game ServersDedicated Game Servers
Dedicated Game Servers
 
Unit 20 - Game Platforms
Unit 20 - Game PlatformsUnit 20 - Game Platforms
Unit 20 - Game Platforms
 
Unit 20 - Game Platforms
Unit 20 - Game PlatformsUnit 20 - Game Platforms
Unit 20 - Game Platforms
 
Writing a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media playerWriting a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media player
 
Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf eu
 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
 
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
(GAM303) Beyond Game Servers: Load Testing, Rendering, and Cloud Gaming | AWS...
 
Programming Language Final PPT
Programming Language Final PPTProgramming Language Final PPT
Programming Language Final PPT
 
GDC 2015 - Low-latency Multiplayer Gaming with AWS
GDC 2015 - Low-latency Multiplayer Gaming with AWS GDC 2015 - Low-latency Multiplayer Gaming with AWS
GDC 2015 - Low-latency Multiplayer Gaming with AWS
 
Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)
 
Lessons Learned with Unity and WebGL
Lessons Learned with Unity and WebGLLessons Learned with Unity and WebGL
Lessons Learned with Unity and WebGL
 
Lets Play Together
Lets Play TogetherLets Play Together
Lets Play Together
 

Recently uploaded

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 

go-man API

  • 1. go-man API Learning go-lang & writing a game
  • 2. Why?  By day: I am architect/developer hacking at Java based api’s  By night: Still harboring a passion for video games and regularly write small games to try out new tech on my daily commute (rarely finish them…)
  • 3. Fusion Why not combine both pursuits to retain a level of interest? Goals:-  Better understanding of go-lang  Maybe and actual finished skunkworks project?
  • 4. Dissecting the game  Broke the idea of “pac-man” down to a series of API calls.  Create game  Add player(s)  Move players  Repeat to fade
  • 5. Concurrency  Lightbulb moment!  Multiple players in same game = concurrency
  • 6. Parallelism  Multiple games in single server = parallelism
  • 7. Caveats  Probably not the best way to do this  First golang code I’ve developed  Highly inefficient  Websockets would’ve been MUCH better  BUT, it’s fun to try it
  • 8. Starting the game HTTP POST request to create a new game with following parms:-  Game name  Max number of GoMen  Max number of GoGhosts  Time to wait for players What happens?  Creates new game on server  Creates golang process waiting for timeout to start game.  Creates a single channel to listen for player updates
  • 9. Add players to game HTTP PUT request to add a player to a game with parms:-  Game id  Player name  Player type (GoMan/GoGhost) If total players reached game will begin otherwise game waits for players
  • 10. Time up If wait time expires, game server adds remaining players as CPU controlled players. Creates new golang process for each missing player Dumb AI: Wait for ¼ second. Pick random number between 0-3 Send move request to game channel repeat…
  • 11. Game States “new” – just created “waiting” – waiting for players to join “playing” – game active “over” – all GoMan players have died “won” – all pills eaten
  • 12. Power Pills If a player eats a power pill a separate golang process is submitted that waits for duration of pill. At end of timer game reverts to normal.
  • 13. Game Client Originally I started developing a separate client in go-lang. Stopped development of this because I wanted people to try the game easily on the web. Switched to JavaScript based client as this was the most likely client to consume the API.
  • 14. Game Client - technology  HTML5 + JavaScript  Twitter bootstrap  HTML5 canvas  Ajax calls to RESTful API
  • 15. Game Client - features  List games  Create new game  Join existing game  Play game
  • 16. Game Server Server implements MVC pattern: Models = game board + players View = JSON representation of game state Controller = RESTful API calls to perform CRUD on a game instance.
  • 17. Game Server - technology  Standalone golang executable or  Google app engine app Uses:  Gorillamux (for http routing)  Game state stored in memory
  • 18. Game Server – lessons learned Things I learned during development:- Started using filesystem as simple datastore for games. Got tired of serialisation / deserialisation and realised it was unnecessary for my simple demo. Originally modeled board cells as a 2d byte array. But these force client to have to deal with Base64 encoded binary data (nasty). Changed definition to a 2d array of “runes” for an easier life. BoardCells [][]rune
  • 19. Game Server – logic  All game logic resides on server. Game state / player state etc.  Game clients are completely dumb.  Weakness in API is that players are not authenticated so they could easily fake each others moves by using the other player’s GUID.
  • 20. Game Server – concurrency  Game controller writes PlayerMove requests to a single channel (one per game)  This prevents concurrent updates to same board (two players eaten same pill etc.)  PlayerMove request includes a unique response channel, to return response back to original requester
  • 21. Game Server – concurrent requests move me Game request channel Players can be either remote web players or local CPU controlled players on server
  • 22. Game Server – concurrent responses Players receive a new instance of the Game board after their move Bad move
  • 23. Game Server – stats golang is FAST!  Normal game 1 goman & 4 goghosts runs in browser @ 60fps  5 x 60 (300) requests per second. Average 3k per response. 1MB per sec traffic.  Running locally it is handled with ease 80+ players in a single game  DO NOT PLAY ON MOBILE PHONE WITH DATA CONTRACT!!!
  • 24. Game Models - GameBoard type GameBoard struct { Id string Name string PillsRemaining int Players map[string]*Player MaxGoMenAllowed int MaxGoGhostsAllowed int WaitForPlayersSeconds int State GameState PowerPillsActive int CreatedTime time.Time LastUpdatedTime time.Time GameStartTime time.Time BoardCells [][]rune }
  • 25. Game Models - Player type Player struct { Location Point Id string Type PlayerType State PlayerState Name string cpuControlled bool Score int Lives int }
  • 26. Game Models - GameState const ( NewGame GameState = "new" WaitingForPlayers = "waiting" PlayingGame = "playing" GameWon = "won" GameOver = "over" )
  • 27. Game Models - PlayerState const ( Alive PlayerState = "alive" Dying = "dying" Dead = "dead" Spawning = "spawning" )
  • 28. Game Models - PlayerMove Request interface type PlayerMove struct { GameId string PlayerToMove Player ResponseChannel chan (PlayerMoveResponse) } Response interface type PlayerMoveResponse struct { Board GameBoard Error error } Response written back to channel passed in request
  • 31. Demo Client: http://go-man-client.herokuapp.com/ (Hosted as simple static site) Source: https://github.com/telecoda/go-man-javascript-client API: http://go-man-app.appspot.com (Hosted on single GAE instance) Source: https://github.com/telecoda/go-man-app Wiki: https://github.com/telecoda/go-man-app/wiki