<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Jack L.</b> <span dir="ltr">&lt;<a href="mailto:jackjrabbit@gmail.com">jackjrabbit@gmail.com</a>&gt;</span><br>Date: Tue, Oct 11, 2011 at 7:58 PM<br>
Subject: Re: [Cs254f11] Help me fix this loop<br>To: Maxwell William Fair Levit &lt;<a href="mailto:mwl10@hampshire.edu">mwl10@hampshire.edu</a>&gt;<br><br><br>Running the second loop without the last bit works, e.g. ...<div>
<br></div><div><div class="im"><div>(loop [c 1 x (rand-int 19) y (rand-int 19)]</div><div> (if (and (&lt; c 3) (zero? (get @board x y)))</div><div>   (place-peice x y (if (even? x) 1 2))</div>
<div>   (recur c (rand-int 19) (rand-int 19)))</div></div><div> )</div><div><br></div><div>Lists all the positions but they&#39;re all 0. :)</div><div><br></div><font color="#888888"><div>Jack</div></font><div><div></div>
<div class="h5"><br><div class="gmail_quote">On Tue, Oct 11, 2011 at 7:13 PM, Maxwell William Fair Levit <span dir="ltr">&lt;<a href="mailto:mwl10@hampshire.edu" target="_blank">mwl10@hampshire.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Hey all, I&#39;m writing code that takes turns placing black and white (1 and 2)<br>
pieces on a Go board. I&#39;m running into trouble with the loop that is supposed<br>
to actually place a bunch of pieces.<br>
<br>
(def board<br>
  (atom<br>
    (zipmap<br>
      (reduce concat<br>
              (for [y (range 19)]<br>
                (map vector (repeat 19 y )<br>
                     (for [x (range 19)] x))))<br>
      (vec (repeat 361 0)))))<br>
<br>
;; defines a 19x19 board with all 361 entires set to 0.<br>
<br>
<br>
(defn place-peice<br>
  [x y z]<br>
  (swap! board update-in [[x y]] (fn [j] z) ))<br>
<br>
;;Sets the value of the space with coordinates [x y] to z.<br>
<br>
(loop [c 1 x (rand-int 19) y (rand-int 19)]<br>
  (if (and (&lt; c 3) (zero? (get @board x y)))<br>
    (do (place-peice x y (if (even? x) 1 2))<br>
        (recur (inc c) (rand-int 19) (rand-int 19)))<br>
    (recur c (rand-int 19) (rand-int 19))))<br>
<br>
This just crashes clooj, presumably because its going infinitely, since I set<br>
the number of iterations low enough that it shouldn&#39;t just be an efficiency<br>
issue.<br>
<br>
The other setup I had which gave me a &quot;Must recur from tail position&quot; error. was<br>
this.<br>
<br>
<br>
<br>
(loop [c 1 x (rand-int 19) y (rand-int 19)]<br>
  (if (and (&lt; c 3) (zero? (get @board x y)))<br>
    (place-peice x y (if (even? x) 1 2))<br>
    (recur c (rand-int 19) (rand-int 19)))<br>
  (recur (inc c) (rand-int 19) (rand-int 19)))<br>
<br>
Can someone tell me why these don&#39;t work and/or how to fix them?<br>
<br>
<br>
Thanks,<br>
<br>
-Max<br>
_______________________________________________<br>
Cs254f11 mailing list<br>
<a href="mailto:Cs254f11@lists.hampshire.edu" target="_blank">Cs254f11@lists.hampshire.edu</a><br>
<a href="https://lists.hampshire.edu/mailman/listinfo/cs254f11" target="_blank">https://lists.hampshire.edu/mailman/listinfo/cs254f11</a><br>
</blockquote></div><br></div></div></div>
</div><br>