Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Require aid refining a "Game Of Life"-esque project (Dead entities on the edges)  (Read 411 times)
0 Members and 1 Guest are viewing this topic.
Offline RyanMB97

Junior Member


Medals: 1
Projects: 1



« Posted 2013-08-23 16:42:28 »

   So, I started out this project trying to get some sort of RTS similarity, but it shifting half-way through from having AI hunt each other down, to just switching IDs back and forth based on neighboring "entities" (Similar to tiles). Some problems that I have are mostly that the "entities" around the edges don't change state, regardless of whether they are surrounded by opposite-ID'd entities. This may have something to do with my using a tile system to create them, and the edges are nulls.

   Anyways, I need help just refining this thing. It's just a mini side project for my spare time, but I can't seem to grasp this one thing. My project on Github is here: https://github.com/RyanMB97/Mini-RTS. Namely, the "EntityBehaviors" class, with a little bit of entanglement with the actual "Entity" class, which is used when creating them. They're generated in the "Game" class, and rendered and ticked like normal object/tiles would in any other game/project.

   This is getting rather long, but thanks in advance for help, it is much appreciated! Also, before I forget, the reason for the "Thread.sleep(500)" is so that I can watch the changes gradually.
Offline actual

JGO Coder


Medals: 23



« Reply #1 - Posted 2013-08-23 17:31:52 »

To stop having to check for null all the time what if you made the board with a strip of extra tiles. So if you want a 100-100 board, your tile array would be new Tile[102][102]. Then when you are checking entities for being surrounded you loop from 1 to 101.

A possible thought. It looks like you are modifying the board as you go. So when you are calculating the value of the current cell, you are using the current frame's value for half of the cells but the already updated values for the other half. This leaves the board in an in-between and inconsistent state. Ideally as you calculate the new states of the entities, you would ensure that you are only using the state of the current state to calculate the new values, and then update all of the values at the end.

EDIT: Another thought is that your entities may be getting into a pattern where entities are flipping back and forth because there is only a single set point (the same way a thermostat would constantly switch on and off around its set point). Hysteresis may be your friend here.
Offline RyanMB97

Junior Member


Medals: 1
Projects: 1



« Reply #2 - Posted 2013-08-23 18:17:31 »

   I can somewhat understand what you mean, but how would I go about implementing this? I already swapped the entities around to the 100x100 grid idea, and creating them this way. I loop from 0 to 99, which makes sense.

   The part of your reply that I don't quite understand is how I would go about changing my program from the "inconsistent" state that you mentioned. It might just be that I'm not seeing it clearly, or I'm just not looking closely enough. My current thoughts are looping the "viewSurroundingEntities" outside of the "Entity.tick" method, so that all the entities know their neighbors, and then switch the IDs depending separately. Is this what you mean?

   Anyways, thanks for the response, hopefully I can sort this out eventually.

   P.S. That Hysteresis looks interesting, and I can get a general idea of what it means, but I don't see where it can be applied to the project. I think it would fit into my "thresholdOfConversion" in the Entity class, but whatever.

   Edit: Pushed changes to Github
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline actual

JGO Coder


Medals: 23



« Reply #3 - Posted 2013-08-23 18:48:03 »

I think you would want to loop from 1-99 otherwise you will still have nulls along on edge.

The easiest to ensure you are working with values from the same board would be to simply have a "newID" field in your Entity class. Your update could be something like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void tick() {
   if (entitiesOfOppositeID(this, surEnt) >= thresholdForConversion) {
      if (ID == 0) {
         newID = 1;
      } else if (ID == 1) {
         newID = 0;
      }
   }
   else {
      newID = ID;
}

Then after you have run through the board you would then loop through and set ID to newID. There are probably more efficient ways to do this, but this should work fine.

Re: Hysteresis:

I wasn't sure if the problem you were having was that entities would flip, and then the threshold would be met, they would flip back, causing it to flip back as well, on and on... (your comment about IDs just switching back and forth). I wasn't sure if the the threshold changed depending on whether the ID is 1 or 0 would help. Something like:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public void tick() {

  // For this entity to flip from 0 to 1, there must be at least 5 entities that are 1.
 int threshold0To1 = 5;
 
  // For this entity to flip from 1 to 0 there must be at least 3 entities that are a 0.
 int threshold1To0 = 3;

   int oppositeIdCount = entitiesOfOppositeID(this,surEnt);

   if (ID == 0 && oppositeIdCount >= threshold0To1) {
         newID = 1;
      } else if (ID == 1 && oppositeIdCount >= threshold1To0) {
         newID = 0;
      }
   }
   else {
      newID = ID;
}


I'm not sure if it will do anything, it is just a thought I had while reading your problem and code.

On an unrelated note, do you anticipate having more than 0 or 1 as IDs? If not. what if you switched your Id type to a boolean? It might make some of your code easier to write.







Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!