great thanks
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
For a class modeling the block puzzle I use nested lists as arrays.
Within this class there is a method for swaping elements. I have lots
of trouble with that method but can't figure it out. It has probably to
do with my unuseful approach to nested lists, but I don't want to write
the code
Some general remarks:
def getEmptySlot(self):
i = 0
j = 0
while i = self.dim-1:
while j = self.dim-1:
if self.elements[j][i] == -1:
return [j, i]
j = j+1
j = 0
i = i + 1
[EMAIL PROTECTED] wrote:
Hi,
why can't I do this:
dummy = self.elements[toy][tox]
self.elements[toy][tox] = self.elements[fromy][fromx]
self.elements[fromy][fromx] = dummy
after initialising my nested list like this:
self.elements = [[0 for column
[EMAIL PROTECTED] wrote:
Hi,
why can't I do this:
dummy = self.elements[toy][tox]
self.elements[toy][tox] = self.elements[fromy][fromx]
self.elements[fromy][fromx] = dummy
after initialising my nested list like this:
self.elements = [[0 for column in range(dim)] for
Hi, I'm using nested lists as arrays and having some problems with
that approach. In my puzzle class there is a swapelement method which
doesn't work out. Any help and comments on the code will be
appreciated. Thanks.
# Puzzle.py
# class for a sliding block puzzle
# an starting state of a 8
Diez B. Roggisch wrote:
[EMAIL PROTECTED] wrote:
Hi,
why can't I do this:
dummy = self.elements[toy][tox]
self.elements[toy][tox] = self.elements[fromy][fromx]
self.elements[fromy][fromx] = dummy
after initialising my nested list like this:
naturalborncyborg [EMAIL PROTECTED] wrote:
Hi, I'm using nested lists as arrays and having some problems with
that approach. In my puzzle class there is a swapelement method which
doesn't work out.
what happens, and what do you expect?
Any help and comments on the code will be appreciated
naturalborncyborg wrote:
Hi, I'm using nested lists as arrays and having some problems with
that approach. In my puzzle class there is a swapelement method which
doesn't work out.
What doesn't work out? On casual inspection that method seems to work:
p = Puzzle(2)
p.elements[0][0] = 1
Thanks for the code.
What I want to do is this:
I want to solve the block puzzle problem. The problem is as follows:
You have a nxn Array of Numbers and one empty space. Now you there are
up to four possible moves: up, right, down and left, so that each
neighbour of the empty slot can be moved
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
'Having trouble' is too vague to figure out. However, I would delete this:
def getEmptySlot(self):
i = 0
j = 0
while i = self.dim-1:
while j = self.dim-1:
if self.elements[j][i]
Diez B. Roggisch [EMAIL PROTECTED] wrote in message
And use xrange instead of range.
For small dimensions like 3,4,5, xrange is way overkill and perhaps takes
both more space and time. Since dim is a constant for a given puzzle, I
would set self._range = range(dim) in __init__() and use
Allright. What difference in runtime and space would it make using
dictionaries instead?
Do you have a pointer for me concerning runtime of standard
manipulations in Pythons?
Thanks for tip.
--
http://mail.python.org/mailman/listinfo/python-list
Allright. What difference in runtime and space would it make using
dictionaries instead?
Do you have a pointer for me concerning runtime of standard
manipulations in Pythons?
Thanks for the tip.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Allright. What difference in runtime and space would it make using
dictionaries instead?
is this for an interactive game? if so, the answer is none at all.
(on my machine, you can make about 600 dict[x,y] accesses per
second, compared to 750 list[x][y]
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
def setRandomState(self):
# container for the elements to pick from
container = [1,2,3,4,5,6,7,8,-1]
# create elements of puzzle randomly
i = 0
j = 0
while i = self.dim-1:
while j
Terry Reedy wrote:
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
def setRandomState(self):
# container for the elements to pick from
container = [1,2,3,4,5,6,7,8,-1]
# create elements of puzzle randomly
i = 0
j = 0
while i = self.dim-1:
while
[EMAIL PROTECTED] a écrit :
Thanks for the code.
What I want to do is this:
I want to solve the block puzzle problem. The problem is as follows:
You have a nxn Array of Numbers and one empty space. Now you there are
up to four possible moves: up, right, down and left, so that each
neighbour of
18 matches
Mail list logo