For something like a turn-based card game, you can model the game with
functions like:

    (update state & args) => new-state

I'm not familiar with Samurai Sword, but I have played Bang!, which is
supposedly similar. To model this in a functional language, consider how
you'd describe the state of the game at any instance in time.

At a minimum, players will typically have some life counter and a set of
cards in their hand. So one might imagine the game state to look something
like:

    (def state
      {:players
       {:alice {:life 4, :hand [:bang! :bang! :miss]}
        :bob   {:life 3, :hand [:bang! :miss :miss]}}}

Now you just need a function that will take the current game state and
return a new state:

    (play state :alice :bang! :bob)
    => {:players
        {:alice {:life 4, :hand [:bang! :miss]}
         :bob   {:life 2, :hand [:bang! :miss :miss]}}}

- James


On 23 June 2014 20:54, Majen Ful <majen...@gmail.com> wrote:

> Hello all,
>
> First, thank you all for your contribution and your help. I just follow
> Clojure's news and groups, and I'm really impressed by how this community
> is pleasant and helpful.
>
> Well, I am new to Clojure world, I do programming as a hobby (I'm not pro)
> and I don't have advanced knowledges. However I really enjoy programming
> and I like games. In a "classic" language, as Ruby or Java, I can use
> mutable states and objects so it is "easy" to reason. In Clojure, I
> understand how immutability works, but I still miss some reflexes.
>
> My goal is to build a little card game like
> http://boardgamegeek.com/boardgame/128667/samurai-sword
> A lot of things to do, but I have some difficulties at beginning.
>
> For example, I can define cards, I can define some function (isdead,
> attack)... But how can I save the state of the game ? When a player attacks
> another player, the second player must have its life reduced. At this
> point, my OO reflexes are went back and don't find a solution.
>
> Could you give me some tips and lead me to the right things to do.
>
> Thanks by advance :-)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to