Re: Mancala Strategy
- Posted by Undetermined origin c/o LISTSERV administrator Aug 12, 2000
- 446 views
--------------E19CF263675061D79FFAD6CF ck lester wrote: > Can somebody translate the C program at the following page into EUPHORIA: > > http://lrcwww.epfl.ch/cours-java/adv-strat/node4.html > > It's a program that analyzes moves for the game Mancala. > > Thanks! > ck > > __________________________________________________ > Do You Yahoo!? > Talk to your friends online with Yahoo! Messenger. > http://im.yahoo.com I've attached my version. It's untested, since I've forgotten how to play mancala. Note that positions on the board start at 1 instead of 0. Jeff Fielding --------------E19CF263675061D79FFAD6CF name="mancala.ex" Content-Disposition: inline; filename="mancala.ex" constant invalid = 0, again = 1, done = 2 function play(sequence b, integer me, integer you, integer here) integer i, left if not b[me+here] then return {invalid} end if left = b[me+here] b[me+here] = 0 while left do if i = 15 then i = 1 end if if i = you+6 then i = me end if b[i] += 1 left -= 1 i += 1 end while i -= 1 if i = me+6 then return {again, b} end if if i > me and i < me+6 and b[i] = 1 then b[me+6] += b[6-1-(i-me)+you] b[6-1-(i-me)+you] = 0 end if return {done, b} end function function move(sequence b, integer me, integer you, integer level) sequence v, temp integer value, best integer max, t max = b[me+6]-b[you+6] if not level then return {max, 0} end if best = -1 for i = 1 to 6 do temp = play(b,me,you,i) t = temp[1] if t = again then v = temp[2] temp = move(v, me, you, level) best = temp[1] value = temp[2] elsif t = done then v = temp[2] temp = move(v, you, me, level-1) best = temp[1] value = -temp[2] end if if t != invalid then if best = -1 or value > max then best = i max = value end if end if end for return {max,best} end function --------------E19CF263675061D79FFAD6CF--