8 queen/game of life

Ken Seehof kens at sightreader.com
Fri Jun 16 02:24:43 EDT 2000


I did an ultra-generalized life program in python a couple years ago.  I haven't
touched it in about that long, but I can try to dig it up for you.  It allowed
/any/ set of rules imaginable, and I had implemented a couple kinds of
tri-colored hexagonal life, 3-D life (using OpenGL), and of course the
original.  I wasn't interested in speed, I just used it to learn python and
prototype some life variant ideas.

If you want to do a high speed implementation of life in python, try using a
blitter (though that would not be a beginners programming task).

Eight by eight matrix is:

>>> M = [[0]*8]*8

Usage is:

>>> M[7][7]=1
>>> M[7][7]
1

root wrote:

> newbie question.
>
> has anyone wrote the 8 non-attacking queen problem and conway's game of life
> in python? i try but face a few newbie problems.
>
> 1. conway's game of life:
>    how to have a matrix in python?
>    the following is not good;
>
>            r0=[0,0,0]
>            r1=[0,0,0]
>            ........
>
>            m=[r0,r1,....]
>
>    the matrix is fixed, which is not good. my solution use dictionary (i
>    know this is not the right way). the key is a tuple of the matrix
>    indices. the value is '0'. then base on game of life rule, update the
>    dictionary and print for next generation.
>
>            m={}
>            m[(0,0)] = 0, m[(0,1)] = 1,....
>
> 2. 8 non-attacking queen.
>
>    use backtracking. the function call itself back. how to do recursive call
>    in python? roughly, the C program I study look like this;
>
>    queen_count = -1
>
>    main()
>    {
>      addqueen();
>    }
>
>    addqueen()
>    {
>    queen_count++
>    if queen_count != 8
>         addqueen()
>    else
>         print result
>    }
>
>    how to pass a global variable (queen_count) to a function?
>
> many thanks in advance.
>
> zamri
>

--
Ken Seehof
kens at sightreader.com
starship.python.net/crew/seehof
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!


-------------- next part --------------
A non-text attachment was scrubbed...
Name: kens.vcf
Type: text/x-vcard
Size: 343 bytes
Desc: Card for Ken Seehof
URL: <http://mail.python.org/pipermail/python-list/attachments/20000615/4ebeac2b/attachment.vcf>


More information about the Python-list mailing list