On Jan 30, 2008 12:46 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > bhaaluu wrote: > > > # distribute positive numbers 10 to 109 > > # place in last element of 4 random lists > > # nothing is placed in list 6 or 11 > > cnt=0 > > while cnt <= 3: > > a = range(1,20) > > room = random.choice(a) > > room = random.randint(1, 19) is simpler. > > > if room != 6 and room != 11 and travelTable[room-1][6] == 0: > > b = range(10,110) > > treasure = random.choice(b) > > Use randint() here too. > > > travelTable[room-1][6] = treasure > > else: > > cnt -= 1 > > cnt += 1 > > This use of cnt is a bit strange. Why not increment only in the > successful 'if' and get rid of the 'else' entirely? > > Rather than repeating the loop until you get three distinct, valid > random numbers, you could do something like this: > > # Change 7 rooms, not room 6 or 11 > changeableRooms = range(1, 20) > changeableRooms.remove(6) > changeableRooms.remove(11) > > roomsToChange = random.sample(changeableRooms, 7) > > # First three get something good > for room in roomsToChange[:3]: > travelTable[room-1][6] = random.randint(10, 119) > > # Last four get something bad > for i, room in enumerate(roomsToChange[3:]): > travelTable[room-1][6] = -i-1 > > > print " 1:", travelTable[0][6] > etc - use a loop and string formatting: > > for i, room in enumerate(travelTable): > print ' %s: %s' % (i+1, room[6]) > > Finally, you might consider putting a dummy entry at travelTable[0], or > number the rooms from 0, so you don't have to adjust the indices all the > time. > > Kent >
Thank you Kent! All of these look like very useful suggestions. What I'm trying to do is implement an old Text Adventure Game that was written c.1983. I'm trying to keep the flavor of the game as close as possible to the original. I'm not old enough, in computer years, to remember the "Glory Days" of Text Adventure Games on computers like the Apple ][, Atari, Commodore 64, IBM PC, VIC 20, and so forth. As a result, I don't know anything about Text Adventure Games. So this is a real learning experience for me in more ways than just learning Python. The book I'm using as a reference is at: http://www.atariarchives.org/adventure/ Creating Adventure Games On Your Computer. The author was Tim Hartnell. http://en.wikipedia.org/wiki/Tim_Hartnell Most of the problems so far stem from the old line-numbered BASIC's GOTO [line-number] statements. There are other problems as well, but _that one crops up regularly. Nevertheless, it has been fun, so far. I'm a Hobbyist programmer, so even if I don't succeed at making a Retro-game, I'm having fun trying. At least I'm getting a good idea of what an old-timey Text Adventure Game is all about. The only thing I can think of of, is that it must have been quite a challenge to get one of those old computers to do anything at all.... so if someone could get a TAG working, it must have been quite a thrill! 8^D Happy Programming! -- b h a a l u u at g m a i l dot c o m "You assist an evil system most effectively by obeying its orders and decrees. An evil system never deserves such allegiance. Allegiance to it means partaking of the evil. A good person will resist an evil system with his or her whole soul." [Mahatma Gandhi] _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor