Giter Site home page Giter Site logo

pokerman's Introduction

Pokerman

A simple GenServer and Agent implementation to show the difference between them and why you might want to use one or the other.

Each represents a poker player who would, presumably, part of a larger application that handles decision making and game management.

pokerman's People

Contributors

tdenkinger avatar desmondmonster avatar

Stargazers

Alexei Matveev avatar Wil Stephens avatar Mauricio avatar  avatar

Watchers

 avatar James Cloos avatar

pokerman's Issues

Cameron notes

Notes:

Changes I might make, in no particular order:

Things that are not named the same, that could be:

GenPlayer.buy_chips, Genplayer handles message :add_chips
GenPlayer.deal_to, vs :deal_cards

For messages that only require an atom, (:name, :stack, :cards), I would just send the atom, rather than wrapping it in a tuple

For the handle_calls that look into the state, such as handle_call({:stack}..) consider pattern matching to pull out the piece you're after:

def handle_call(:stack, _from, %{stack: stack} = pd), do: {:reply, stack, pd}
One other thing.  This may not be idiomatic, it might easily be something I just made up, but I really like having little state mutators, that take a state as the first param, and return a state, like this:

def add_chips(s = %{stack: chips}, amount), do: s |> Map.put(:stack, chips + amount)
def reply(state, return), do: {:reply, return, state}
def noreply(state), do: {:noreply, state}

now with those three, you can do this:

def handle_cast({:add_chips, amount}, state), do: state |> add_chips(amount) |> noreply

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.