# Thread: A 1 week challenge!

1. Flk, take a look at my quick and dirty code, it draws direct on the form and is rather fast, for example, if you set the refresh code in yours to 20 (which was my required fastest speed) and ay a 40x40 grid, it basically never draws. it should be able to.

Im guessing that if you were to profile some of your code, SetAlive and SetNeighbours will be the 2 main areas of concern. If you look at how I address it in my quick and dirty one, maybe you'll have some ideas on where your time goes.

2. in fact

If you change the timer code to:

Code:
```procedure TForm1.Timer1Timer(Sender: TObject);

var tmpcells :tcells;
i,j:integer;
n : integer;
begin
setlength(tmpcells,XWIDTH,YWIDTH);
for i := 0 to XWIDTH-1 do
for j :=0 to YWIDTH-1  do
begin
n:=CountNeighbours(i, j);
if (((n=2) and cells[i,j]) or (n=3) ) then
tmpcells[i,j]:=true
else
tmpcells[i,j]:=false;
if cells[i,j]<>tmpcells[i,j] then
begin

if tmpcells[i,j] then
canvas.Brush.Color:=clred
else
canvas.Brush.Color:=Color;
canvas.FillRect(rect(i*(CELLWIDTH+1),j*(CELLWIDTH+1),(i*(CELLWIDTH+1))+
CELLWIDTH,(j*(CELLWIDTH+1))+CELLWIDTH));
end;
end;
cells:=tmpcells;
end;```
Its super fast as it only draws squares that change.

3. fik
Registered User
Join Date
Oct 2003
Posts
242
That's strange that it never draws for you. I asume you meant 400 X 400 as can't have 40 x 40. As for me it does at about 2 fps. All i did was set a flag while processing /drawing and in timer code skip call to reprocess cells if this not clear. so no matter how slow it processes still upates screen.
Looking at your code and mine to see what is cause of mine so slow as I use almost same method of updating screen as yours ( first not second ). As i am sure you can see it works out all cells alive then goes throuh array and sets or clears on screen.i seem to get next to no delay from screen finishing updating to next(even at full size suprizing really as it has to go through an array of 1 million+ cells and do cheaks on up to eight sides each one !) update it is just the displaying that takes time as you can see columns progressing on screen.

Edit: - I tried your quick and dirty example and it no faster than mine. I think i can now guess what you have done it's my crappy interface. i bet you press start after setting settings without pressing randomize first to set some cells or pressing draw then with shift held and moving mouse to draw some cells (ctrl &move mouse to erase ) then right clicking to start. Yes your second version is a lot lot faster.
However both of your codes and the others don't wrap cells around screen liie i have set mine to.
Last edited by fik; 10-24-2007 at 06:41 PM.

4. no flk, I deffinately pressed randomize, and I did set 40x40, I typed it in the boxes, and I set an update of 20 and it didnt move.. and no, mine doesnt wrap, it doesnt have to - as I said it was quick and dirty. However performance difference on my pc is huge. Its a nice fast pc graphics card is "ok" its not great, Orydes does the same kinda speed as my hack.

The exe you sent me, and I have recompiled to make sure, just doesnt seem to change speed, wether it say 20 or 400+ it seems the same speed.

PS you mentioned 2fps, yes you should be getting way more than that, oryde and I (if you set the timer to 20) both run around 50fps.. yours doesnt seem to change from that 2fps
Last edited by LizKimber; 10-25-2007 at 12:53 AM.

5. fik
Registered User
Join Date
Oct 2003
Posts
242
I see why now. You just found a bug in my program .
If you use up down arrows to set it seems to be ok but if you type numbers in it does not change. I was reading from the position property from the up/down control (to save converting ),which i had linked to edit box so i thought the link was both ways as it changes edit box numbers when used but changing edit box does not change position property.Wondered how you could have got 40 into setting as i set a minimum 50.
There you go i have learnt something which after all is what this was for.

6. it surely is

Join Date
Nov 2006
Posts
233
Damn, I was hoping to find time to attempt this challenge looks like I'll do it for fun at my leisure. Liz, is yours in C++ or C#? That is a very small binary for a Delphi application.

Well done to everyone btw, they are all great!

8. mine was c# but thats coz Im learning that in my lunch breaks at work, although Ive posted a delphi version in code here since posting the c# app, including a tweak to the delphi app to make it even faster.

Page 3 of 3 First 123

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•