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.

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.

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.

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

publicvoidtick() {

// For this entity to flip from 0 to 1, there must be at least 5 entities that are 1.intthreshold0To1 = 5;

// For this entity to flip from 1 to 0 there must be at least 3 entities that are a 0.intthreshold1To0 = 3;

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