[Tutor] Help Designing a simple Program called Life

2012-02-22 Thread leo degon
Hello All,
My name is Leo. I'm just beginning to learn python. I am
learning on my own and have no previous programming experience. I decided
to create a version of john conway's game of life as a personal project.

I've been wondering what GUI to use.
 I've been using Tkinter so far but I've not gotten very far. So far I've
started the basic window but now I'm kinda of stuck in how to proceed.

My idea is when the program initializes to have a root menu with a series
of options.
 Accepting these options under the  new game launches a window where you
can set the initial state of the board to the correct dimensions, colors,
rules, name and initial distribution of live cells. Accepting that window
would launch a window containing the game board and the in-game options. I
would like to be able to pause the game, run it at different speeds, and
add new live cells to the board. I would like to have multiple boards able
to run at once, and I would like the option to save a board and its rules
to load at a later time.

I'd like any ideas on how to approach this project in general and specific.

I'll post the code that I already have later today.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Game of python, help please.

2012-04-08 Thread leo degon
Hello all, Im trying to learn python and programming in my free time, and
I'm trying to do a little personal project to trying and gain some skills.
Im trying to do version of John conways game of life. I have a working
version of the game. Written for 3.2.2 on a mac to be accessed through
terminal. I'm trying to give it a number of options. it dimensions, the max
number of turns, initial set up, and boundary conditions. The dimensions
and turns were pretty easy to include. The boundary conditions more
difficult, and now I'm getting stuck on the initial set up options. I can
set it up randomly but Im having problems implementing a checker board
pattern.


'''displays: the text of the game of life for a set number of X x Y for a
set of R turns.

[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]

Get X,Y,T, Initial value

Create a data space X x Y
Assign initial value
print initial value and the text' initial value'

do while turns

iam.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Game of python, help please.

2012-04-17 Thread leo degon
Ok so I've done a bit of work on the program and rewrote it. I tried to
take everyones advice. I've used more functions, I've made it so that it is
a list of lists each containing an integer instead of another list with a
single entry.

Im am having problems thinking of how to simply and elegantly calculate the
surrounding cells.I could brute force it as i did originally, but I'd like
some pointers of how to avoid that. As of now, the script is finished for
that 'small' detail. I have it so that instead of actually calculating the
surrounding cells, that functions says that all the cells on the board are
surrounding by three cells. Therefore setting the entire board alive after
the turn zero. I am still trying to include three different versions of the
boundry conditions.

Boundary conditions, what happens when a cell on the edge of the board
tries to calculate the number of surrounding live cells.
Dead- Those nonexistent cells add nothing.
Live-Those nonexistent cells add one per cell. So add 5 to the corners, and
one to edges.
Bound- The dimensions are bound. So you get to the end and loop around.


the script follows

#leoslife.py

# John Conways Game of Life.
plan='''displays: the text of the game of life for a set number of X x Y
for a set of R turns.

[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]

Get X,Y,T, Initial Values, Boundry conditions

Create a data space X x Y
Assign initial value
print initial value and the text' initial value'

do while turns3):
return(0)
else:
if space[i][j]==1:
return(1)
else:
return(0)

#get x,y,t initial value, boundry condition

x=getnum('How many rows?')
y=getnum('How many columns?')
t=getnum('How many turns?')

#get boundry conditions
boundry=0
while boundry not in ("b","d","l"):
boundry=input("Press 'b' for bound dimenions, 'd' for dead boundry, or
'l' for live boundry. : ")

#get initial set up of space
initial=0
while initial not in ('r','c','g','e'):
initial=input("Press 'r' for random intitial set up, 'c' for a checker
board pattern, 'g' for a single glider, or 'e' for a pattern that repeats
infinitely. : ")

if initial=='g':
if x<5:
x=5
if y<5:
y=5
if initial=='e':
if x<6:
x=6
if y<6:
y=6
#create space

space = []
for i in range(x):
space.append([])
for j in range(y):
space[i].append(0)


#set intital distribution

if initial=='r':
for i in range(x):
for j in range(y):
space[i].__setitem__(j,random.randint(0,1))
elif initial=='c':
for i in range(x):
for j in range(y):
if (i+j)%2==0:
space[i].__setitem__(j,1)
else:
space[i].__setitem__(j,0)
elif initial=='g':
space[1].__setitem__(2,1)
space[2].__setitem__(3,1)
space[3].__setitem__(1,1)
space[3].__setitem__(2,1)
space[3].__setitem__(3,1)
elif initial=='e':
space[2].__setitem__(2,1)
space[2].__setitem__(3,1)
space[2].__setitem__(4,1)
space[3].__setitem__(1,1)
space[3].__setitem__(2,1)
space[3].__setitem__(3,1)


#show initial conditions of board on turn 0
print("---Initial Board---\n")
printset(space)

for turn in range(t):
#Create new empty space
new=[]
for i in range(x):
new.append([])
for j in range(y):
new[i].append(0)
#rewrite each space
for i in range(x):
for j in range(y):
surronding=findsurronding(space,i,j,boundry)
mortality=determinelife(surronding,space,i,j)
new[i][j]=mortality
space=new[:]
print('---Turn %s' %(str(turn+1)))
printset(space)

print("This is the end
  ")
On Tue, Apr 10, 2012 at 10:44 AM, bob gailer  wrote:

> On 4/9/2012 10:56 PM, Dave Angel wrote:
>
>> On 04/09/2012 10:33 PM, bob gailer wrote:
>>
>>> On 4/9/2012 2:26 AM, leo degon wrote:
>>>
>>>> Hello all, Im trying to learn python and programming in my free time,
>>>> and I'm trying to do a little personal project to trying and gain
>>>> some skills. Im trying to do version of John conways game of life. I
>>>> have a working version of the game. Written for 3.2.2 on a mac to be
>>>> accessed through terminal.
>>>>
>>> 
>>> These nested loops
>>>
>>>> for i in range(X):
>>>> SPACE.append([])
>>>> for j in range(Y):
>>>>

Re: [Tutor] Game of python, help please.

2012-04-17 Thread leo degon
Ok that was simple change. Dont know why but there was a small error
preventing that from working before. But the problem is with the creating
findsurrounding function

On Tue, Apr 17, 2012 at 3:14 PM, Alan Gauld wrote:

> On 17/04/12 19:23, leo degon wrote:
>
>> Ok so I've done a bit of work on the program and rewrote it. I tried to
>> take everyones advice. I've used more functions, I've made it so that it
>> is a list of lists each containing an integer instead of another list
>> with a single entry.
>>
>
> It still looks too complicated to me.
>
>
>  #set intital distribution
>>
>> if initial=='r':
>> for i in range(x):
>> for j in range(y):
>> space[i].__setitem__(j,random.**randint(0,1))
>>
>
> What's with the __setitem__ stuff? You should never normally need to call
> that directly. I would expect something like
>
>
>  for i in range(x):
>  for j in range(y):
>  space[i][j] = randint(0,1)
>
> Or, using list comprehensions:
>
>  for i in range(x):
>  space[i] = [randint(0,1) for j in range(y)]
>
> Or even:
>
> space = [[randint(0,1) for j in range(y)] for i in range(x)]
>
>
> Which, for x,y = 3,4 gives a structure like:
>
> >>> space
> [[1, 0, 0, 0], [1, 0, 1, 1], [0, 1, 1, 0]]
>
> >>>
>
>
>  elif initial=='c':
>> for i in range(x):
>> for j in range(y):
>> if (i+j)%2==0:
>> space[i].__setitem__(j,1)
>>
>
> Again I'd just use
>
> space[i][j] = 1
>
> HTH
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Game of python, help please.

2012-04-18 Thread leo degon
I actually just finished it, without the extra cells. I used a combiniation
of two functions and a some exception handling to do so.
Here is the script.


#leoslife.py

# John Conways Game of Life.
plan='''displays: the text of the game of life for a set number of X x Y
for a set of R turns.

[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]
[-][-][-][-][-]

Get X,Y,T, Initial Values, Boundry conditions

Create a data space X x Y
Assign initial value
print initial value and the text' initial value'

do while turns3):
return(0)
else:
if space[i][j]==1:
return(1)
else:
return(0)

#get x,y,t initial value, boundry condition

x=getnum('How many rows?')
y=getnum('How many columns?')
t=getnum('How many turns?')

#get boundry conditions
boundry=0
while boundry not in ("b","d","l"):
boundry=input("Press 'b' for bound dimenions, 'd' for dead boundry, or
'l' for live boundry. : ")

#get initial set up of space
initial=0
while initial not in ('r','c','g','e'):
initial=input("Press 'r' for random intitial set up, 'c' for a checker
board pattern, 'g' for a single glider, or 'e' for a pattern that repeats
infinitely. : ")

if initial=='g':
if x<5:
x=5
if y<5:
y=5
if initial=='e':
if x<6:
x=6
if y<6:
y=6
#create space

space = []
for i in range(x):
space.append([])
for j in range(y):
space[i].append(0)


#set intital distribution

if initial=='r':
for i in range(x):
for j in range(y):
space[i][j]=random.randint(0,1)
elif initial=='c':
for i in range(x):
for j in range(y):
if (i+j)%2==0:
space[i][j]=1
else:
space[i][j]=0
elif initial=='g':
space[1][2]=1
space[2][3]=1
space[3][1]=1
space[3][2]=1
space[3][3]=1
elif initial=='e':
space[2][2]=1
space[2][3]=1
space[2][4]=1
space[3][1]=1
space[3][2]=1
space[3][3]=1


#show initial conditions of board on turn 0
print("-Turn 0-\n")
printset(space)

for turn in range(t):
#Create new empty space
new=[]
for i in range(x):
new.append([])
for j in range(y):
new[i].append(0)
#rewrite each space
for i in range(x):
for j in range(y):

surrounding=findsurrounding(space,i,j,boundry,basesurrounding(space,i,j))
mortality=determinelife(surrounding,space,i,j)
new[i][j]=mortality
space=new[:]
print('---Turn %s' %(str(turn+1)))
printset(space)

print("This is the end
  ")

On Wed, Apr 18, 2012 at 12:53 PM, bob gailer  wrote:

> On 4/17/2012 2:23 PM, leo degon wrote:
>
> > Ok so I've done a bit of work on the program and rewrote it. I tried to
> take everyones advice. I've used more functions,
> > I've made it so that it is a list of lists each containing an integer
> instead of another list with a single entry.
>
> I'm glad to see you using some of my ideas!
>
>
> > Im am having problems thinking of how to simply and elegantly calculate
> the surrounding cells.
> > I could brute force it as i did originally, but I'd like some pointers
> of how to avoid that.
> > As of now, the script is finished for that 'small' detail. I have it so
> that instead of actually calculating the surrounding cells,
> >  that functions says that all the cells on the board are surrounding by
> three cells.
> > Therefore setting the entire board alive after the turn zero. I am still
> trying to include three different versions of the bounadry conditions.
>
> >Boundary conditions, what happens when a cell on the edge of the board
> tries to calculate the number of surrounding live cells.
> > Dead- Those nonexistent cells add nothing.
> > Live-Those nonexistent cells add one per cell. So add 5 to the corners,
> and one to edges.
> > Bound- The dimensions are bound. So you get to the end and loop around.
>
> [snip]
>
> I again recommend you add extra rows and columns around the space so you
> always use one formula for surround.
>
> For dead initialize the extra cells to 0
> For live initialize the extra cells to 1
> For bound - every time you change a boundary cell make the same change to
> the corresponding extra cell.
>
> I hope that makes sense. Does it?
>
> Also recall my condensed way of summing surrounding cells. I realize I
> made a mistake in my original pr

[Tutor] Question about lists

2012-09-21 Thread Leo Degon
I'm trying to create a class where the main focus is creating a list whose
elements are lists and the elements of those lists are collection of zeros
and ones. I am trying to create functions to rotate the list ninety
degrees, to reflect it. Having a few problems with the rotation.
get TypeError: 'list' object is not callable

def pset(n):
for i in n:
print(i)
class board():
def make(self,size):
b=[]
for i in range(size[0]):
b.append([])
for j in range(size[1]):
b[i].append(0)
return b

def rotate(self,board,size):
size[0],size[1]=size[1],size[0]
new=board(size)
lists=[]
for j in range(size[1]):
lists.append([])
for i in range(size[0]).__reversed__():
lists[j].append(board[i][j])
for i in range(size[1]):
for j in range(size[0]):
new.board[i,j]=lists[i,j]
return(new.board)
def __init__(self,size):
self.size=size
self.board=self.make(size)
y=[7,7]
x=board(y)
pset(x.board)
x.board[0][0]=1
print()
pset(x.board)
print()
x.board=x.rotate(x.board,x.size)
pset(x.board)
print()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reloading a module

2012-10-03 Thread Leo Degon
So Ive got code that i import a module to get certain saved variables,
where i edit the text file that comprises the module to edit those saved
variable. My problem is I cant reload the module to access those modified
variables.
I was wondering how can i reload or otherwise refresh the module.
python3 on linux

Thank you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor