Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
About Us Register FAQ Members List Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old November 28th, 2002   #1 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
The game of life 'C' Project

WARNING!!!
If you're not interested in C or programming, leave this thread now. This is for computer geeks only.

Anyway, the school I'm currently attending gave out a cool project in my CMSC 201 class where I had to make a "Game of life." For a complete project description, visit this page, http://www.csee.umbc.edu/courses/und...2/projects/p2/ . Now I'm not asking you guys to help me (besides, it's too late to give in the project). I just want to know if anyone can reproduce some nifty looking code using the program. BTW, you are gonna need a file full of ones and zeros. I want to see who can come up with the best algorithim.

Good luck! And don't go off-topic! (No pun intended)
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1

Last edited by AtomicFeline; November 28th, 2002 at 02:07.
AtomicFeline is offline   Reply With Quote
Old November 28th, 2002   #2 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
hehe... Can I get a moderator to move this to the Programming Section?
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1
AtomicFeline is offline   Reply With Quote
Old November 28th, 2002   #3 (permalink)
Administrator
 
Kellicros's Avatar
 
Join Date: Nov 2001
Location: Kuala Lumpur, Malaysia.
Posts: 7,686
>> hehe... Can I get a moderator to move this to the Programming Section?

Done.
__________________
Kellicros' DeviantArt
Kellicros is offline   Reply With Quote
Old November 28th, 2002   #4 (permalink)
Banned
 
Ninjaa's Avatar
 
Join Date: Oct 2001
Location: Soviet Canuckistan
Posts: 0
Looks interesting. If I hadn't spent 10 hours coding today already, I might be breaking out my compiler right now.

But alas, my assignment was due, and I spent a long time working on it. Now I am tired and sleepy.
Ninjaa is offline   Reply With Quote
Old November 28th, 2002   #5 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
Would it help if I posted my completed code?

[EDIT] - How would I go about attaching it?
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1

Last edited by AtomicFeline; November 28th, 2002 at 14:23.
AtomicFeline is offline   Reply With Quote
Old November 28th, 2002   #6 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
Nevermind. I found out. And don't be afraid to look at the code; it's well commented.
Attached Files
File Type: zip life.zip (5.4 KB, 37 views)
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1
AtomicFeline is offline   Reply With Quote
Old November 28th, 2002   #7 (permalink)
Single
 
SnakeBite's Avatar
 
Join Date: Apr 2002
Location: Norway
Posts: 667
is this something like that ooooold game/application called "GenLife" for Windows 3.1? looks very similar... and interesting...
__________________
This is my new improved sig.
SnakeBite is offline   Reply With Quote
Old November 28th, 2002   #8 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
Actually, yes. The "game of life" has been made a billion times, but it is still fun to make. You may have heard it by the name of Lifegen, NextGen, or simply the "game of life." I want to see if someone can make some mean looking code.
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1

Last edited by AtomicFeline; November 28th, 2002 at 17:50.
AtomicFeline is offline   Reply With Quote
Old November 28th, 2002   #9 (permalink)
Single
 
SnakeBite's Avatar
 
Join Date: Apr 2002
Location: Norway
Posts: 667
yeah! it was called Lifegen! I knew I had heard that before...
__________________
This is my new improved sig.
SnakeBite is offline   Reply With Quote
Old November 28th, 2002   #10 (permalink)
Emu author
 
ammoQ's Avatar
 
Join Date: Mar 2002
Location: Vienna/Austria/Europe
Posts: 1,168
bad style:
<pre>
int boolean = FALSE;
</pre>

boolean is a type (like int or float) in other programming languages, should not be a variable name.

ValidateNeighbors does next to nothing, but takes a whole page on the screen.

AddNeighbors takes 73 lines for something that could be easily written in 2 lines.

Instead of using 2 arrays alternately, you copy the whole array for every iteration.

Sorry if this is a bit harsh, but it looks like someone was very busy creating lots of code, as if you were paid per line of code.

Look at ammoqlife.c: Granted, I was a bit lazy with comments, but it's a total of 91 lines.

I use 2 arrays alternately, so I don't have useless copy operations.
My arrays are larger so they include an invisible border of zeroes; this way I don't need range checking for the board.

Input is done in strings like that:
<pre>
X
X X
XXXX
</pre>
This way I can use the output of the game as an input for the next game. Maximum number of cycles and output interval are command line parameters. (You see, I arbitrarily changed the input format a little so a non-programmer cannot use it unmodified for your assignment. There is nothing wrong the way your program does the input.).
Attached Files
File Type: zip ammoqlife.zip (818 Bytes, 25 views)
__________________
If you think my English is bad, wait till you read my Polish.

Last edited by ammoQ; November 28th, 2002 at 23:00.
ammoQ is offline   Reply With Quote
Old November 28th, 2002   #11 (permalink)
Banned
 
Ninjaa's Avatar
 
Join Date: Oct 2001
Location: Soviet Canuckistan
Posts: 0
ooh.. I am afraid to compete with the master programmer now...
Ninjaa is offline   Reply With Quote
Old November 28th, 2002   #12 (permalink)
Emu author
 
ammoQ's Avatar
 
Join Date: Mar 2002
Location: Vienna/Austria/Europe
Posts: 1,168
100000 iterations on my machine (output to /dev/null)
AtomicFelineLife - 17,7 sec
ammoQLife - 5 sec
__________________
If you think my English is bad, wait till you read my Polish.
ammoQ is offline   Reply With Quote
Old November 29th, 2002   #13 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
Good job, AmmoQ. But then again, I'm still in college, and I haven't been in a course that teaches optimization.

BTW, the array with zeros as the boarders was probably the thing that sped up the program the most. By doing that, you had the right to simply add all the neighbors without checking.

I didn't get it when you use two arrays alternatly. Can you explain a little? (My class webpage said that the program required copying arrays. Although I wish I thought of several of the things you did.)

[EDIT] - Oh, I get it! You made the calculations and applied it right into the array that you are going to print. That way, you don't need to copy the changed array into another one. It makes me wonder why I got a good grade on the project. And you're right about the boolean thing. I at least have potential, right?
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1

Last edited by AtomicFeline; November 29th, 2002 at 14:33.
AtomicFeline is offline   Reply With Quote
Old November 29th, 2002   #14 (permalink)
Emu author
 
ammoQ's Avatar
 
Join Date: Mar 2002
Location: Vienna/Austria/Europe
Posts: 1,168
Hey, you did a good job! Your program works well and it is readable and well documented.
It's just that in some parts you wrote lots of code for very simple operations. But sometimes it takes a lot of experience to see the short way. Keep on learning, I'm pretty sure you have potential!
__________________
If you think my English is bad, wait till you read my Polish.
ammoQ is offline   Reply With Quote
Old November 29th, 2002   #15 (permalink)
Emu author
 
ammoQ's Avatar
 
Join Date: Mar 2002
Location: Vienna/Austria/Europe
Posts: 1,168
Quote:
Originally posted by AtomicFeline
Oh, I get it! You made the calculations and applied it right into the array that you are going to print. That way, you don't need to copy the changed array into another one.
Not only; in the next iteration, the roles of the two arrays are exchanged, so while in one iteration, I calculate Array 2 from Array 1, in the next iteration it's the other way round. So i never have useless copy operations for whole array.
__________________
If you think my English is bad, wait till you read my Polish.
ammoQ is offline   Reply With Quote
Old November 30th, 2002   #16 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
How do you know which array to display then? First you change one array using the original and then you change the original using the changed one, do you modulus the amount of times you use the algorithm by two and if it's one then display one array and if it's zero then display the other? (Sorry for reviving the thread, but I really want to understand).
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1
AtomicFeline is offline   Reply With Quote
Old December 1st, 2002   #17 (permalink)
Emu author
 
ammoQ's Avatar
 
Join Date: Mar 2002
Location: Vienna/Austria/Europe
Posts: 1,168
it's these lines:
<pre>
s=!s;
...
output(currentTime, b[s]);
</pre>

the first line toggles s between 1 and 0; the second generates the output from the array choosen by s.
__________________
If you think my English is bad, wait till you read my Polish.
ammoQ is offline   Reply With Quote
Old December 1st, 2002   #18 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
Interesting. If 's' is 1, then !s would be zero, right? Pretty cool.
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1
AtomicFeline is offline   Reply With Quote
Old December 1st, 2002   #19 (permalink)
Single
 
SnakeBite's Avatar
 
Join Date: Apr 2002
Location: Norway
Posts: 667
I was able to create something in Delphi. and it works! if anyone wants the source, then ask me. I added a random button to generate X-es (1's and 0's) at random.
__________________
This is my new improved sig.
SnakeBite is offline   Reply With Quote
Old December 3rd, 2002   #20 (permalink)
Registered User
 
AtomicFeline's Avatar
 
Join Date: Aug 2001
Location: Maryland USA
Posts: 569
Delphi? Never used it. Can you show a bit of the source code?
__________________
Feline

Visit my deviantart page:

http://atomicfeline.deviantart.com

1.4 Ghz T-Bird Athlon
PNY Geforce4 TI4400 AGP 128 Meg DDR
512 Megs DDR ram
Ensoniq Audio PCI
32X CD-ROM
Windows XP SP 1
AtomicFeline is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 19:09.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5