AlecHsueh
How to implement different game rules?
I’m learning Elixir by myself for fun now. I have basic Python knowledge before. I think the best way to learn a new programming language is to do some real projects. I’m try to create a web based poker game. The basic unit of the game is the table. Different tables have different game rules. e.g. Texas Hold’em table, Omaha table. etc. But as a functional programming language, Elixir has no class no object no inheritance. My question is how to implement a structure that can associate with different game rules?
Most Liked
kelvinst
Just use different modules for different games. Maybe also create a basic module with @callbacks and use it as a @behaviour on the implementation modules, to define a common interface for them, and ensure they have the functions the base game module calls.
kokolegorille
If You like Poker with Elixir, there is an old post about it here https://tokafish.com/playing-poker-with-elixir-part-1/ You might need to adapt for newer version, but the post is nice.
Other games I often saw, Tic Tac Toe, Tetris…
I wrote a little game engine for go here elixir_go | Hex
For a more complete example, there is this video
axelson
I would take care not to link the game implementation (e.g. :card_played) to a GenServer. You can implement all of the logic with pure modules and functions.
To Spawn, or not to Spawn? by Saša Jurić gives a good overview about when and how to reach for processes and even talks about an implementation of a card game to boot (Blackjack).
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









