Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    Otakon is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default Need help with "constructing" Game of Life

    First of all, I would like to apologize if I'm asking too much but, I'm simply not qualified for Java.

    We were given a task to make a Game of Life, however, our teacher had only one thing to say : "Google"... (makes me wonder why do I bother coming to class)
    So, the problem is I don't know how to go through with this so if possible, could you give step by step instructions?

    I believe the first step is creating the board so my question is; what do I use?
    Please make it as blunt as possible.
    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Otakon View Post
    First of all, I would like to apologize if I'm asking too much but, I'm simply not qualified for Java.

    We were given a task to make a Game of Life, however, our teacher had only one thing to say : "Google"... (makes me wonder why do I bother coming to class)
    So, the problem is I don't know how to go through with this so if possible, could you give step by step instructions?

    I believe the first step is creating the board so my question is; what do I use?
    Please make it as blunt as possible.
    Thanks
    Whew. Yes, when it comes to "step by step instructions", I think you're asking too much.

    Some general steps though:

    1) study the Wikipedia entry for Conway's Game of Life. It will explain the rules.
    2) Think of the non-GUI objects you'll need for this simulation. "Cell" and "Board" come to mind.
    3) Brain-storm, search this forum and others and study what others have done. This is a fairly common assignment and has been discussed several times here and in the other major Java fora.
    4) Try to create your program -- but not willy-nilly. You'll want to think and plan before committing code to screen.
    5) Come on back with your code and any specific questions you may have.

    Much luck!

    edit: this statement does bug me though:
    I'm simply not qualified for Java.
    Certainly through diligence and effort, you can change this, right? If not, then perhaps...
    6) Drop the course and preserve your sanity.
    Last edited by Fubarable; 01-17-2010 at 11:58 PM.

  3. #3
    Otakon is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    Thanks, will try.
    I actually tried my own version of this; I used buttons and "If" statements (it is a VERY long code) and it works but we have to use the "traditional" means.

    edit: this statement does bug me though:
    I'm simply not qualified for Java.
    Certainly through diligence and effort, you can change this, right? If not, then perhaps...
    6) Drop the course and preserve your sanity.
    The main problem is that our teacher isn't being very helpful and insists we do it by ourselves which has its drawbacks and the fact that I didn't learn much kinda brings me down but since I came this far, I might as well go through with it.
    Thanks for the thought.

  4. #4
    justin1980 is offline Member
    Join Date
    Jan 2010
    Location
    Wisconsin
    Posts
    20
    Rep Power
    0

    Default

    I had a C# teacher that was just like that. It was his last semester and it seamed like he didn't really want to teach anymore. That class was almost all a waste of time but I ended up having some really good teachers the next year, so just hang in there and read the book. At least you can still learn a lot of whats in the book.
    Last edited by Fubarable; 01-18-2010 at 03:54 AM. Reason: signature removed

  5. #5
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    I'm just not qualifed in java
    what kind of attitude is that?
    Evryone can do it... some better than others but evryone can.
    when you don't understand questions ask it here on the forum these people are really helpful.
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    I wrote one of these actually -- a fun exercise. I implemented the exact rules described on the wiki. The trickiest part was the really long if/else structure that made up the logic of wether or not a cell should live, die, or regrow. I think my implementation was about 4 pages of java.

    One thing I discovered which I had not initially thought of was this:
    When performing the logic on each cell, you need to make sure that you do not actually kill or bring a cell back to life until you have run the logic on all cells. This meant for me that I had two arrays - the original and then a new one I populated with the information for the next life cycle. Once all the logic had finished, I replaced the original array with the new one and began the next cycle.

    In other words, if a given cell is brought back to life immediately, then the logic for the adjacent cell is wrong. This game works as if every cell on the board follows the rules simultaneously, but in reality, we are performing logic one cell at a time. So, we need a place to store the results one cell at a time without the results affecting the logic on the next cell to be calculated.

    I also found that its quite SLOW for java to refresh the screen when its trying to draw 1000x1000 cells - I found that the OpenGL bindings for java (JOGL) worked very nicely at accelerating the drawing (from about 5fps to 140fps after jogl).

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    BTW, my complete code including whitespace and a JOGL drawing implementation (which adds a good sized chunk of code) is only 420 lines. This includes user input of cell count, amount of initial seeding, speed of animation, etc. I think you could do a simple version in 200 lines or less.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by quad64bit View Post
    I also found that its quite SLOW for java to refresh the screen when its trying to draw 1000x1000 cells - I found that the OpenGL bindings for java (JOGL) worked very nicely at accelerating the drawing (from about 5fps to 140fps after jogl).
    Most people fall in that trap: they calculate the dead/alive state for every cell in the matrix; this isn't necessary: Keep two maps of Points; the first map represents the current generation and contains only those coordinates (Points) of the living cells for that generation.

    The next map has to be constructed and it contains all coordinates (Points) of the living cells of the next generation.

    Construct that second map as follows: it's a Map<Point, Integer> and first it contains all the neighbours of all the Points in the first map and the entries are associated with an int, counting how many cells have this cell as their neighbour.

    When this step is done the Integer represents the number of living cells that are a neighbour of this particular point. If is easy to remove the cells that have too many or too few living neighbours.

    When the last step is done the new map contains the next generation. Throw away the map of the now old generation and repeat. This simple scenario is so much faster than a naive implementation. I implemented it in my own functional, interpreted language and had to introduce wait-states between the drawing of the generations. It just went vooooom! ;-)

    kind regards,

    Jos

  9. #9
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    wow this sounds really complicated. What class is this? Right now I'm in AP Computer Science A in high school.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  10. #10
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    I built one with a JPanel that takes up the whole screen. It is very as long as most of cells are dead but I tried setting the intial state for each cell randomly and it took a while (like 50ms/gen). Jos, that is a great idea I'm going to try to implement that now. Also, Lil_Aziz, you are so lucky you have AP computer science at your HS...

  11. #11
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    How come? It's only AP Comp Science A. Wish my school at least offered the AB exam. Not trying to show vanity or anything, but I'd rock the AB exam.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  12. #12
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Not trying to show vanity or anything, but I'd rock the AB exam.
    You do know that if you play the money, you can take any AP test whether you took a class or not. Also, if you have a Junior College nearby, you can take classes there and pass off college classes like you would if you passed the AP test.

  13. #13
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Ooo. So when I register for my college classes next school year, I could pass out of Computer Science 241 (I think that's basically AP Computer Science AB) by passing the exam? I'm a senior in high school right now.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  14. #14
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Yeah, but you have to pass the exam... If you aren't taking the class then you should probably get some books or something to make sure that you will pass.

    Also, you might want to read about it on college board, for some reason they don't have anything on CS AB, just A. they also have something where you can look up what school you are going to and see hier AP credit policy.
    http://collegesearch.collegeboard.co...licy/index.jsp
    Last edited by collin389; 01-19-2010 at 04:06 AM.

  15. #15
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    The book we were given in comp. science A tells us what part is AB. Which is like handling exceptions instead of ignoring em (which is what we do in A), Iterators, and I don't think there is any Applet/GUI/Swing/Concurrency stuff on there.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  16. #16
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Ok, well Good Luck then.

  17. #17
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    ... I could pass out of Computer Science 241
    I really really don't recommend that unless...

    you have a strong command of java/c++ and know about data structures (Dynamic Vectors, Linked Lists, Trees [BST, Red Black, etc], Graphs [traversals, recursive functions, Djikstra's, etc], Stacks, Queues, Dequeues, SSL, DLL, Sets, Heaps), Generic types, serialization, sorting algorithms (Bubble, Selection, Insertion, Quick, Shell, Merge, Heap, Counting, Radix, Bucket, Comb), Big O notation and its implications, algorithm analysis and some real hands on projects (like coding an arbitrage scenario, huffman encoder (primitive zip-it engine), client/server applications, traveling salesman problems, infix to postfix converters, etc...). Not to mention a very strong understanding of OOP and UML. All of this stuff is covered in 241 and sometimes more depending on your school.

    If you really feel like all that stuff is cake or at the very least you have done it before and it wasn't a huge deal, by all means test out of 241. However, I'd be surprised if your high school managed to cover all of that already in any detail. Thats my $.02, I think that going into 310 (Data Structures) without all the above would be a mess - My university has an 80% attrition rate for computer science for a reason (its not because the professors are mean :), and it never hurts to be well prepared.

  18. #18
    Otakon is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    Yo, sorry It took so long.

    Anyway, thanks for the tips.
    I just spoke with the teacher and he said we should make the game in Command Line.

    We should use a constructor, next() method, position(x,y)->for checking and selecting "fields" but I am a bit lost here; I searched the net for details but it's nothing like we have to do.

    So far, this is what I have:

    Java Code:
    public class Life3
    {
        public static void main(int x, int y, double z)
        {
    
            Life life=new Life (20,5,0.2);
        }
    }
    I know, it's bad but, I don't know what next...
    Also, it seems that the "new Life" part has an error.
    Help?

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Otakon View Post
    So far, this is what I have:

    Java Code:
    public class Life3
    {
        public static void main(int x, int y, double z)
        {
    
            Life life=new Life (20,5,0.2);
        }
    }
    I know, it's bad but, I don't know what next...
    Also, it seems that the "new Life" part has an error.
    Help?
    We're not allowed to use our crystal balls here so you have to at least show us the code for your constructor(s) of your Life class ...

    kind regards,

    Jos

  20. #20
    Otakon is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    I thought THAT was the constructor.

    This is driving me nuts...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 05:49 AM
  2. Replies: 2
    Last Post: 10-09-2009, 12:28 AM
  3. Replies: 2
    Last Post: 01-24-2009, 07:56 PM
  4. Replies: 1
    Last Post: 10-20-2008, 08:35 AM
  5. Roll 2-Dice "Pig" Game Help
    By King8654 in forum AWT / Swing
    Replies: 7
    Last Post: 04-07-2008, 07:58 PM

Posting Permissions

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