Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornell!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!uhog.mit.edu!bloom-beacon.mit.edu!gatech!howland.reston.ans.net!ix.netcom.com!netcom.com!bakul
From: bakul@netcom.com (Bakul Shah)
Subject: Re: bit manipulation operators in scheme?
Message-ID: <bakulCz9yCA.ACA@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
References: <3a0s1q$ej1@tweedledumb.cygnus.com> 	<BLUME.94Nov12114556@dynamic.cs.princeton.edu> 	<bakulCz7zK8.Cw@netcom.com> <2WIENBE.94Nov14173348@rzdspc74.informatik.uni-hamburg.de>
Date: Mon, 14 Nov 1994 20:31:22 GMT
Lines: 47

2wienbe@rzdspc74.informatik.uni-hamburg.de (Axel Wienberg) writes:

>I've actually written a version of TicTacToe once (my second or third
>scheme program, actually) that used a 3^N encoding for the game states
>(each field was 0=empty, 1=black or 2=white).  Probably not as fast as
>bit-fiddling, but I can't think of anything more compact. The entire
>game tree fit in about 70kB (using additional tricks like merging
>mirrored / rotated states).

>  ...ok, so I just like to tell storys...

One story deserves another :-) (with apologies to the
disinterested but I do think it is relevant to *efficient* set
operations).

Many years ago, when Pascal was the king and C just a rebel
leader and Scheme just being born, I wrote a program for the 3D
tic-tac-toe (you know, the one played on a 4x4x4 structure) in
Pascal.  The first version used the `cell[i][j][k]' idiom to
reference a cell.  This version was very slow and to provide a
reasonable response time I limited the number of plys to search
so severely that even I could beat the program.

So I thought a bit and changed the representation.  I mapped the
4x4x4 structure to integer range 0..63 and the current state of
the board by two sets: one for each player's placed tokens
(luckily, the version of Pascal on the KI10 had 72bit sets).  A
move to cell x for player A was valid if x was not a member of
either set A or set B.  In this case x is added to set A.  Notice
that all winning configurations can be represented by sets (for
example, {0,1,2,3}, {0,4,16,24} and so on).  Now an `N-winnable'
configuration is a subset of a winning set, with N fewer
elements.  A move x is better than move y, if A+{x} has more
1-winnable or 2-winnable sets as its subsets than A+{y} does.
With this change in representation the program was able to try
out many more plys and yet provide near instantaneous response.
I didn't bother with further optimizations because I never beat
it after that.  The representation chosen would have allowed a
straight forward extension to a multi-player 3D ttt but back then
I didn't figure out how to generalize the alpha-beta algorithm to
multi player games.

The moral of the story is that increased efficiency can allow you
to try out many more possibilities in alloted time -- makes your
program more `intelligent', if you wish.

Bakul Shah
