AlecHsueh

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

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

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

axelson

Scenic Core Team

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).

Last Post!

Eiji

Eiji

This comment:

your code based on table rules (…)

does not mean that you need to write login directly in this place.

I believe that this is easiest example for board games (as far as I remember table in each game have only one event like card played) at same time + time for players in their rounds to think about next move.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement