> From what you say I imagine you have something like a matrix
> or table, something with rows and columns that form cells.
> And you want to be able to grab the contents of one cell and move
> it around to another cell.
Andre, that statement captures all I intend to achieve.

This is what I wanted to do in clojure, have solver for a checker game. I
started off with the below codes.
(defstruct aount :h1 :h2 :h3 :h4)
(def row1 (ref  (struct aount "x" "x" "x" "x")))
(def row2 (ref  (struct aount "x" "x" "x" "x"))) ;;Till row ten.

In order to move a piece from one row to the other, I added.
(defn extract-num [sand key]
(let [n (Integer/parseInt (re-find #"\d+$" (name sand))) m (Integer/parseInt
(re-find #"\d+$" (name key)))]
(remake-row  n  m)))

;;I have not added the code to check if the intended space in occupied or
not.And it can only move diagonally in the left side.
(defn remake-row [i k]
(if (and (with-in-range i bin)(with-in-range k ban))
((eval(call-row  i))(call-key k))

(defn call-key [m]
(keyword (str "h"(inc m))))

(defn call-row [m]
 (symbol (str "row" (inc m))))

(defn with-in-range [m k]
 (and (>= (dec m) 0) (<= (inc m) k)))

I

A simple *move* involves sliding a piece one space diagonally forwards (also
diagonally backwards in the case of kings) to an adjacent unoccupied dark
square. A *jump* is a move from a square diagonally adjacent to one of the
opponent's pieces to an empty square immediately and directly on the
opposite side of the opponent's square, thus "jumping directly over" the
square containing the opponent's piece. An uncrowned piece can only jump
diagonally forwards, but a king can also jump diagonally backwards.
 For details check out this link http://en.wikipedia.org/wiki/Checkers.




Emeka

On Fri, May 8, 2009 at 11:05 PM, André Thieme
<splendidl...@googlemail.com>wrote:

>
> On 4 Mai, 17:01, Emeka <emekami...@gmail.com> wrote:
> > Hello All,
> > I want to arrange objects in rows and also being able to manipulate them.
> By
> > manipulation I meant, I could move one object from one row and use it to
> > replace another object in another. Should I use Map or something else? I
> > need your opinions here
>
> From what you say I imagine you have something like a matrix
> or table, something with rows and columns that form cells.
> And you want to be able to grab the contents of one cell and move
> it around to another cell.
> I don't know how much that fits your plan. But if it is similar
> then one idea could be to have your objects being keys of a hashmap
> and let the values be vectors of two numbers: for the row and column.
> If you want to change the position of an object then you should dissoc
> it from its current [r c] (the key) and assoc it to its new [r c] key.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to