Post Reply 
Game of Life on HP Prime first try
03-13-2014, 08:51 AM
Post: #1
Game of Life on HP Prime first try
Hello

Just tried to program HP Prime (simulator). The program is a quite stright forward game of life without any optimization. What I notice is that the speed is not very high. For a 90 x 90 field the speed is about 300 ms / generation. Normally I would use arrays for the cells but I dont know if its possible/practical on the Prime.


Code:

Cells();
Start();

Xma,Yma;

EXPORT GOL()
begin
local X,Y,c,i,p,t1,t2;

Xma := 90; // Area
Yma := Xma;
Start();

for i from 0 to 800 do // Generations
t1 := TICKS;
for X from 0 to Xma do
for Y from 0 to Yma do

c := Cells(X,Y);
p := GETPIX_P(G0,X,Y);

if c < 2 AND p = #F8h then PIXOFF_P(G1,X,Y) end;
if (c = 2 OR c = 3) AND  p = #F8h then PIXON_P(G1,X,Y,RGB(0,0,255)) end;
if c > 3 AND p = #F8h then PIXOFF_P(G1,X,Y) end;
if c = 3 AND p = #F8F8F8h then PIXON_P(G1,X,Y,RGB(0,0,255)) end;

end;
end;

BLIT_P(G0,0,0,320,240,G1,0,0,320,240);

t2 := TICKS;
TEXTOUT_P("T = "+(t2-t1) + " ms",G0,242,5);// Time per generation
end;

end;

//Check neighbour cells

Cells(X,Y)
begin
local Xp,Xs,Yp,Ys,co;
co := 0;
Xp := X - 1;
Xs := X + 1;
Yp := Y - 1;
Ys := Y + 1;

if X = 0 then Xp := Xma end;
if X = Xma then Xs := 0 end;
if Y = 0 then Yp := Yma end;
if Y = Yma then Ys := 0 end;

if GETPIX_P(G0,Xp,Yp) = #F8h then co := co + 1 end;
if GETPIX_P(G0,Xp,Y) = #F8h then co := co + 1 end;
if GETPIX_P(G0,Xp,Ys) = #F8h then co := co + 1 end;

if GETPIX_P(G0,X,Yp) = #F8h then co := co + 1 end;
if GETPIX_P(G0,X,Ys) = #F8h then co := co + 1 end;

if GETPIX_P(G0,Xs,Yp) = #F8h then co := co + 1 end;
if GETPIX_P(G0,Xs,Y) = #F8h then co := co + 1 end;
if GETPIX_P(G0,Xs,Ys) = #F8h then co := co + 1 end;

return(co);
end;


Start()
begin
local X,Y,i,s;
DIMGROB_P(G1,320,240);
RECT();
s := Xma * 20;
for i from 1 to s do
// Set a random pattern
X := RANDINT(0,Xma);
Y := RANDINT(0,Yma);
PIXON_P(G0,X,Y,RGB(0,0,255));
end;

end;
Find all posts by this user
Quote this message in a reply
03-13-2014, 09:14 AM
Post: #2
RE: Game of Life on HP Prime first try
I wasn't sure if you had seen this related post a while back.

http://www.hpmuseum.org/forum/thread-555...me+of+life

By the end they had a really optimized version.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-13-2014, 10:18 AM
Post: #3
RE: Game of Life on HP Prime first try
I checked the first posts when it was new, have to check the rest....
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)