> As far as I can see, these routines give me the results
> I'm looking for. I get a distribution of four negative numbers,
> four positive integers in the range 10 to 110, and nothing
> is placed in room 6 or room 11:

I'll throw a couple of thoughts out there since I know that you appreciate 
to see many points of view.

> #!/usr/bin/python
>
> import random
>
> #print "\n"*30
>
> table= [[ 0, 2, 0, 0, 0, 0, 0],    # 1
>        [ 1, 3, 3, 0, 0, 0, 0],    # 2
>        [ 2, 0, 5, 2, 0, 0, 0],    # 3
>        [ 0, 5, 0, 0, 0, 0, 0],    # 4
>        [ 4, 0, 0, 3,15,13, 0],    # 5
>        [ 0, 0, 1, 0, 0, 0, 0],    # 6
>        [ 0, 8, 0, 0, 0, 0, 0],    # 7
>        [ 7,10, 0, 0, 0, 0, 0],    # 8
>        [ 0,19, 0, 0, 0, 8, 0],    # 9
>        [ 8, 0,11, 0, 0, 0, 0],   # 10
>        [ 0, 0,10, 0, 0, 0, 0],   # 11
>        [ 0, 0, 0,13, 0, 0, 0],   # 12
>        [ 0, 0,12, 0, 5, 0, 0],   # 13
>        [ 0,15,17, 0, 0, 0, 0],   # 14
>        [14, 0, 0, 0, 0, 5, 0],   # 15
>        [17, 0,19, 0, 0, 0, 0],   # 16
>        [18,16, 0,14, 0, 0, 0],   # 17
>        [ 0,17, 0, 0, 0, 0, 0],   # 18
>        [ 9, 0, 0,16, 0, 0, 0]]   # 19

Hard-coded. That means you have to change the program to change the game. It 
would not be difficult to store this/read it in from a file, making the same 
program suddenly handle an infinite number of games. (well not infinite, but 
at least 19*7*2147483647)

> # Distribute the treasure
> J = 0
> while J <= 3:
>        T = int(random.random()*19)+1
>        if T == 6:
>            continue
>        if T == 11:
>            continue
>        if T == 13:
>            continue
>        if table[T-1][6] != 0:
>            continue
>        b = range(10,110)
>        treasure = random.choice(b)
>        table[T-1][6] = treasure
>        J += 1
>
> # Place androids/aliens in rooms
> J = 4
> while J > 0:
>        T = int(random.random()*19)+1
>        if T == 6:
>            continue
>        if T == 11:
>            continue
>        if T == 13:
>            continue
>        if table[T-1][6] != 0:
>            continue
>        table[T-1][6] = -J
>        J -= 1

Those two block of code above are SO similar that sure they can be combined 
into one, or at least the first parts of them.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to