Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-16 Thread WolfRage
On 01/12/2015 04:47 PM, Mark Lawrence wrote: I haven't looked carefully at your code but there's always a smell in Python when you see structure[x][y]. Can you change the grid so you always write something like:- for row in grid: for cell in row: process(cell) I say this as I'm

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
Updated the code to now allow for a fill_rows optional argument for Grid, that determines how many rows are filled with values. I have also added some experimental code to invert the dropping, as in all of the values can float to the top. Other code is even more experimental and not yet working

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
On 01/12/2015 05:00 PM, Alan Gauld wrote: __str__methodf of the grid. Then the draw method becomes print(self) And you can also just use print(aGrid) etc. Implemented with some other improvements using the same idea but applied to several of the other functions, that provide output. Now I

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
On 01/12/2015 05:00 PM, Alan Gauld wrote: Sorry, no time to read the detail, but one thing I thought might be handy is to convert the draw method to return a string and make it the __str__methodf of the grid. Then the draw method becomes print(self) And you can also just use print(aGrid) etc.

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
I haven't looked carefully at your code but there's always a smell in Python when you see structure[x][y]. Can you change the grid so you always write something like:- for row in grid: for cell in row: process(cell) I say this as I'm all for short term pain, long term gain, esp

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread Alan Gauld
On 12/01/15 20:28, WolfRage wrote: anyone has any improvements or things to think about, I would love to hear it. Sorry, no time to read the detail, but one thing I thought might be handy is to convert the draw method to return a string and make it the __str__methodf of the grid. Then the d

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread Mark Lawrence
On 12/01/2015 19:35, WolfRage wrote: So I was write as I suspected; the grid is not actually being built like I thought it was. Sure the ID's print fine but when the grid positions are procedurally accessed the program fails with IndexError. python3 test1.py | 19 | 5 | 5 | 5 | | 11 | 6 | 19

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
I fixed the other functions to again work as expected. But the procedural access of the self.grid and self.transposed_grid also function correctly. That is good because now I can again do lookups if I need to. Although I do not have a need to at this time. Can anyone see anything wrong with th

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
Now I have the output that I expect and procedurally they output matches the id of the Node/Tile. But I am thoroughly confused as to why my by_id functions use the opposite grid to get the correct output? # Output python3 test1.py | 6 | 20 | 19 | 11 | 11 | 20 | 5 | 11 | | 20 | 19 | 20 | 11 |

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-12 Thread WolfRage
So I was write as I suspected; the grid is not actually being built like I thought it was. Sure the ID's print fine but when the grid positions are procedurally accessed the program fails with IndexError. python3 test1.py | 19 | 5 | 5 | 5 | | 11 | 6 | 19 | 11 | | 6 | 6 | 11 | 19 | | 11 |

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-11 Thread WolfRage
Ok, now the code works as expected to drop the non zero values. But I think there exist an error in the naming and display of the col and row variables at least from with in the GameTile() class, looking into that now. All Suggestions Welcome! Thank You All. import random class GameTile():

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-11 Thread WolfRage
I had an issue in my logic and again my named variables provided for confusion, so I had to add some comments to clarify. I got much closer by editing my code like this: def drop_floating_nodes0(self): i = self.rows # first_zero_row serves as memory for how far to drop non-zero

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-11 Thread WolfRage
On 01/05/2015 06:21 PM, Danny Yoo wrote: SNIP if total in (17, 21, 28, ...): Implemented, thanks. SNIP The other comment I'd make is to start thinking about how you'd _test_ your program automatically. SNIP You are right, I should. But I am fighting with myself on this topic. I have been

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-05 Thread Danny Yoo
Apologies; haven't had time to look at this thread carefully yet. Busy start of the new year. :P Minor comment: you can improve this snippet: if total == 17 or total == 21 or total == 28 or total == 29 or \ total == 31 or total == 42 or total == 45 or total == 46 \ or

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-05 Thread Mark Lawrence
On 03/01/2015 18:15, WolfRage wrote: On 01/03/2015 06:58 AM, Dave Angel wrote: self.transposed_grid = zip(*self.grid) zip() sounds confusing. But I am going to try this and see what it gives me. But Somehow I think it will require me to understand yield, which I still do not totally get how to

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-04 Thread Steven D'Aprano
On Sat, Jan 03, 2015 at 09:57:20PM -0500, Dave Angel wrote: > On 01/03/2015 06:10 PM, WolfRage wrote: > >On 01/03/2015 04:42 PM, Dave Angel wrote: > >>self.transposed_grid = list( zip(*self.grid) ) > >This results in the same thing with or with out the list() wrapper. Using > >Python 3.4.0 (default

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Dave Angel
On 01/03/2015 06:10 PM, WolfRage wrote: On 01/03/2015 04:42 PM, Dave Angel wrote: self.transposed_grid = list( zip(*self.grid) ) This results in the same thing with or with out the list() wrapper. Using Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux In Python 3, zip() retu

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 06:46 PM, Steven D'Aprano wrote: On Sat, Jan 03, 2015 at 06:10:31PM -0500, WolfRage wrote: On 01/03/2015 04:42 PM, Dave Angel wrote: self.transposed_grid = list( zip(*self.grid) ) This results in the same thing with or with out the list() wrapper. Using Python 3.4.0 (default, A

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Alan Gauld
On 03/01/15 23:10, WolfRage wrote: On 01/03/2015 04:42 PM, Dave Angel wrote: self.transposed_grid = list( zip(*self.grid) ) This results in the same thing with or with out the list() wrapper. Are you sure? Try inserting print(self.transposed_grid) immediately after the assignment and see i

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Steven D'Aprano
On Sat, Jan 03, 2015 at 06:10:31PM -0500, WolfRage wrote: > On 01/03/2015 04:42 PM, Dave Angel wrote: > >self.transposed_grid = list( zip(*self.grid) ) > This results in the same thing with or with out the list() wrapper. Using > Python 3.4.0 (default, Apr 11 2014, 13:05:11) > [GCC 4.8.2] on linux

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 04:42 PM, Dave Angel wrote: self.transposed_grid = list( zip(*self.grid) ) This results in the same thing with or with out the list() wrapper. Using Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux ___ Tutor maillist -

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 04:42 PM, Dave Angel wrote: On 01/03/2015 04:22 PM, WolfRage wrote: On 01/03/2015 06:58 AM, Dave Angel wrote: To transpose a grid, you want to use the zip() function. self.transposed_grid = zip(*self.grid) I see this gives me a list that is the column. Thus it solves the col

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Dave Angel
On 01/03/2015 04:22 PM, WolfRage wrote: On 01/03/2015 06:58 AM, Dave Angel wrote: To transpose a grid, you want to use the zip() function. self.transposed_grid = zip(*self.grid) I see this gives me a list that is the column. Thus it solves the column iteration problem, because now I can fe

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 06:58 AM, Dave Angel wrote: To transpose a grid, you want to use the zip() function. self.transposed_grid = zip(*self.grid) I see this gives me a list that is the column. Thus it solves the column iteration problem, because now I can feed it to my checking and elimination fun

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Alan Gauld
On 03/01/15 16:14, WolfRage wrote: def check_total_and_eliminate(self, first, second, third): Steven said: I think this method does too much. I would prefer to see it split into two methods, one to check the total, and the other to eliminate the cells if needed: Yes, another example

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 06:58 AM, Dave Angel wrote: self.transposed_grid = zip(*self.grid) zip() sounds confusing. But I am going to try this and see what it gives me. But Somehow I think it will require me to understand yield, which I still do not totally get how to use. Also from the documentation, wil

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 10:09 AM, Steven D'Aprano wrote: On Fri, Jan 02, 2015 at 09:00:22PM -0500, WolfRage wrote: Python3.4+ Linux Mint 17.1 but the code will be cross platform (Mobile, Windows, Linux, OSX). First an explanation of how the game works: The game is a simple matching game but with a twist.

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/03/2015 06:58 AM, Dave Angel wrote: My error. Since nodes are GameTile objects, not values, converting to a tuple is a little trickier: values = tuple( [node.value for node in nodes] ) if values in table: do-something I will try an implement this after I s

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread WolfRage
On 01/02/2015 10:21 PM, Dave Angel wrote: This code is way too complex for what it accomplishes. See below. Yes, that it why it needs to be optimized. It is unfortunate that my first goes at many tasks are not the most efficient. But hopefully that will get better as I learn from all of you.

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Steven D'Aprano
On Fri, Jan 02, 2015 at 09:00:22PM -0500, WolfRage wrote: > Python3.4+ Linux Mint 17.1 but the code will be cross platform (Mobile, > Windows, Linux, OSX). > > First an explanation of how the game works: The game is a simple > matching game but with a twist. Instead of matching a straight 3 in a

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-03 Thread Dave Angel
On 01/02/2015 10:21 PM, Dave Angel wrote: On 01/02/2015 09:00 PM, WolfRage wrote: Python3.4+ Linux Mint 17.1 but the code will be cross platform (Mobile, Windows, Linux, OSX). First an explanation of how the game works: The game is a simple matching game but with a twist. Instead of matching a

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-02 Thread Dave Angel
On 01/02/2015 09:00 PM, WolfRage wrote: Python3.4+ Linux Mint 17.1 but the code will be cross platform (Mobile, Windows, Linux, OSX). First an explanation of how the game works: The game is a simple matching game but with a twist. Instead of matching a straight 3 in a row, we have some rules tha

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-02 Thread Dave Angel
On 01/02/2015 09:38 PM, Alan Gauld wrote: On 03/01/15 02:00, WolfRage wrote: What is "breaing"? I think he meant breaking I'm afraid some keys currently stick, and 'k' is one of them. Every so often I lose a key. -- DaveA ___ Tutor mailli

Re: [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-02 Thread Alan Gauld
On 03/01/15 02:00, WolfRage wrote: Dave sorry for not posting a new thread correctly, I did not realize the list was so smart. Take a look at the mail headers (More actions->View source in TBird) Specifically the References header. It links each message to all those above it in the thread. If

[Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-02 Thread WolfRage
Python3.4+ Linux Mint 17.1 but the code will be cross platform (Mobile, Windows, Linux, OSX). First an explanation of how the game works: The game is a simple matching game but with a twist. Instead of matching a straight 3 in a row, we have some rules that only certain combinations will resul

[Tutor] Improving My Simple Game Code for Speed, Memory and Learning

2015-01-02 Thread WolfRage
First an explanation of how the game works: The game is a simple matching game but with a twist. Instead of matching a straight 3 in a row, we have some rules that only certain combinations will result in an elimination. In general 2 of the same value in a row with with 1 of 2 other possible va