Home | Community | Message Board

Cannabis Seeds - Original Sensible Seeds
This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Shop: PhytoExtractum Kratom Powder for Sale   Unfolding Nature Unfolding Nature: Being in the Implicate Order   Bridgetown Botanicals Bridgetown Botanicals   Kraken Kratom Red Vein Kratom   Myyco.com Golden Teacher Liquid Culture For Sale   Original Sensible Seeds Autoflowering Cannabis Seeds

Jump to first unread post Pages: 1
Invisiblewolfiewolfie
Just wingin' it.
Male User Gallery

Registered: 06/16/15
Posts: 2,177
Loc: Australia Flag
Need help with an emergence simulator I'm writing in C# * 2
    #26531954 - 03/13/20 12:28 AM (4 years, 2 months ago)

"Emergence: Seemingly simple, innocuous actions build up
in a system day-by-day, until eventually some critical configuration triggers
a new level of behaviour. In evolution, this could be a cell forming from a
collection of molecules: the new object is at a completely different level, both
in terms of spatial scale, and newly available properties and behaviour."

Hey guys,

I'm in the process of making an emergence simulator in C#, loosely based off Conway's Game of Life. It is currently very early stages and I have a few issues/questions if anyone could shed some light.

Basically so far the program generates a number of 'entities' at random locations that can move around their environment. Whenever two of these entities come into contact with eachother, they will merge and 'evolve' into a next generation entity (visually doubling in size and changing colour).

The next step is to give the first generation some initial, simple 'rules' or 'behaviors'. The issue is that i am storing the 'entities' as points in a list:

IList<Point> entities = new List<Point>();

This makes it easy to control movement and collisions, however it doesn't give me anywhere to store behavioural data.

One solution could be to store the entities as a string with the location data ie.

IList<string> entities = new List<string>();
entities.add(Location.X.ToString() + "," + Location.Y.ToString() + "," + BehaviouralData);

However to me it seems messy and time consuming having to extract the data from a string every time.

If anyone can think of a better solution, please let me know. I'll leave my other issues/questions for now.

Here is the code so far:
https://docs.google.com/document/d/12rJTnxoQre73qX9-Z59mW55raUqmVspHoZTc7AhHtFw/edit?usp=drivesdk

And here is what it looks like visually


Thankyou!


--------------------


The only reason why T-rex's can't walk backwards is because they're extinct, which perfectly explains why there are no headaches in the rainforest; The parrots eat 'em all.

My Drawings

Edited by wolfiewolfie (03/13/20 12:32 AM)

Extras: Filter Print Post Top
Invisiblepsi
TOAST N' JAM
Male User Gallery

Registered: 09/05/99
Posts: 31,617
Loc: 613 Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: wolfiewolfie]
    #26532225 - 03/13/20 07:36 AM (4 years, 2 months ago)

This is cool, I love this kind of stuff.

Quote:

One solution could be to store the entities as a string with the location data ie.

IList<string> entities = new List<string>();
entities.add(Location.X.ToString() + "," + Location.Y.ToString() + "," + BehaviouralData);

However to me it seems messy and time consuming having to extract the data from a string every time.

If anyone can think of a better solution, please let me know




I think it makes the most sense to define an Entity class, so that instances of Entity will have attributes containing each piece of data relevant to an entity.

Extras: Filter Print Post Top
Invisiblewolfiewolfie
Just wingin' it.
Male User Gallery

Registered: 06/16/15
Posts: 2,177
Loc: Australia Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: psi] * 1
    #26532563 - 03/13/20 11:35 AM (4 years, 2 months ago)

Quote:

psi said:
I think it makes the most sense to define an Entity class




Perfect! That's exactly what I was looking for. This would also allow the randomisation of the initial entities attributes (size, colour, speed etc ).

So my new Entity class currently stores attributes as follows:

Entity(int posX, int posY, int generation, int speed, Brush color, int size).

What kind of behaviours do you think I should assign to the initial entities?

Also, how would I make these behaviours dynamic?


--------------------


The only reason why T-rex's can't walk backwards is because they're extinct, which perfectly explains why there are no headaches in the rainforest; The parrots eat 'em all.

My Drawings

Extras: Filter Print Post Top
Invisiblepsi
TOAST N' JAM
Male User Gallery

Registered: 09/05/99
Posts: 31,617
Loc: 613 Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: wolfiewolfie]
    #26532584 - 03/13/20 11:50 AM (4 years, 2 months ago)

I don't know too much about C# other than that it is similar to Java, but in most of these object oriented languages functions can be manipulated like any other object. So for example you might have a list of functions that represents a sequence of steps an entity might take on each clock tick or something like that.

Many languages will also have some means of generating a function object at runtime that was not defined ahead of time. I have not looked over this article in detail but it looks like that kind of stuff is doable in C#.

https://www.simplethread.com/c-closures-explained/

Extras: Filter Print Post Top
Invisiblepsi
TOAST N' JAM
Male User Gallery

Registered: 09/05/99
Posts: 31,617
Loc: 613 Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: psi] * 1
    #26533586 - 03/13/20 10:13 PM (4 years, 2 months ago)

As far as ideas for behavior, here are a few thoughts:

Presumably each entity should consider the positions of other entities in deciding what to do based on what you've said. If it was to consider the position of every other entity though, with sufficiently large numbers of entities you would see major slowdowns. For n entities, if each one considers every other entity, you're running your "consider this other entity" code n(n-1) times per clock tick. For sufficiently large values of n, the -1 part becomes insignificant, so we can say the number of considerations is n2 more or less.

Now maybe this tradeoff is fine, and the whole system displays cool behaviors because every entity considers every other entity. But let's say that instead we want each entity to consider only its nearest neighbors so that we can have larger numbers of entities before things slow down to a crawl, and maybe see some different cool behaviors. A brute force approach to find them would be to do the sqrt((x2-x1)2 + (y2-y1)2) thing on the position of each other other entity, but that brings us back to the n2 thing we were trying to avoid. If we had one list that had all entities (or references to them/unique ID numbers) ordered by x coordinate, and another that had them ordered by y coordinate, that might help narrow it down and reduce the number of distance calculations. And there are sorting algorithms that run in n log n time even in the worst case, which is better than n2 (see https://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms). If we use the order from the last tick and sort that based on the updated coordinates, maybe we'll see closer to the best case because the order won't have changed all that much. Or, maybe we could always keep both lists sorted, updating when anything changes. As a side note we may also be able to ditch the square root operation in sqrt((x2-x1)2 + (y2-y1)2) if we only care about which distances are smaller.


As to how to take into account the position of some other entity of interest, most languages will have an atan2 function that will give you the angle in radians (regular atan takes only one parameter and is not as useful). If on every clock tick I turn towards you, turn 90 degrees (π/2 radians) to the left, and then walk one step forwards, my path will more or less be a circular orbit around you if you remain motionless. If I do the same thing but turn less than 90 degrees, I will spiral towards you. For further complexity, maybe I consider distance in deciding how much to turn.

Another similar thing that's pretty cool is if you take the angle to some other point, multiply by 2, and use that as your heading, there is a magnetic field like effect.

For combining the influence of different entities we're considering, adding vectors together is a simple way of doing this. To go from an angle to a vector I think cos gives you the x and sin gives you the y.

This is an old project of mine that touched on some similar stuff like the magnetism thing. Though the entities don't consider each other's positions. Requires python 3 and the pygame library. Haven't looked at it in a long time and I don't recall many details about the implementation, which files may not be used, etc.

https://github.com/pjm0/slopefield

Edited by psi (03/14/20 05:20 PM)

Extras: Filter Print Post Top
Invisiblewolfiewolfie
Just wingin' it.
Male User Gallery

Registered: 06/16/15
Posts: 2,177
Loc: Australia Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: psi] * 1
    #26542076 - 03/18/20 06:23 AM (4 years, 2 months ago)

I just want to say thankyou for your help so far, it is much appreciated.

In regards to "searching for neighbours", I tried a few different approaches only to find, like you said, with large numbers it would cause a lot of lag.

Initially I was using the position of each entity to search for its surrounding neighbours (ie. Entity.positiin.x-1 for left etc ). However, I have now come up with a solution that works and with very large numbers on a low end machine, causing no noticeable lag.

Instead of using X and y positions for the entities, they are stored as 'cells' in a List. Before the simulation can be run, the user must define 1. a cell size (ie. 5 means 5 pixels X 5 pixels) and 2. A grid size (ie. 50 means a grid 50 cells wide X 50 cells high) and 3. Number of seeds (initial alive cells).

This would give us a total of 50x50=2500 cells / entities. Now when we want to search for neighbours, we are only searching a list instead of searching points on the GUI then matching them to an entity in a list.

For example, let's say we have a 10x10 grid (grid=10), and we want to search all 8 neighbours for entity number 15.

xxxxxxxxxx
xxxxOxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx

We would search the list as follows:
Left
Cell.Index-1
Right
Cell.Index+1
Up
Cell.Index-grid
Up left
Cell.Index-grid-1
Up right
Cell.Index-grid+1
Down
Cell.Index+grid
Down left
Cell.Index+grid-1
Down right
Cell.Index+grid+1

This allows not only to search for all 8 neighbours but to also query each of their attributes while maintaining excellent performance.

Furthermore, originally I had an entities 'isAlive' attribute being stored as a Boolean (true/false), in which case I would have to find all 8 neighbours, query their isAlive attribute and keep a tally of the trues and falses. I have now sinply changed the isAlive attribute to an integer with 0 being dead and 1 being alive.

Now when searching for an entities neighbours, at the same time I can simply add up all 8 of their isAlive attributes and be left with an integer showing how many neighbours are alive and how to behave accordingly.

These are the basic behaviours I have at the moment which I've copied from Conway's Game of Life

(Semi pseudo code)
foreach (entity I in the list)
{
n = number of alive neighbours
    if (n < 2)
    {
        I.isAlive = 0 (the entity dies, undercrowded)
    }
    else if (n > 3)
    {
        I.isAlive = 0 (the entity dies, overcrowded)
    }
    else if (n == 3)
    {
          I.isAlive = 1 (the entity remains alive or is brought to life if previously dead) 
    }
             
}


--------------------


The only reason why T-rex's can't walk backwards is because they're extinct, which perfectly explains why there are no headaches in the rainforest; The parrots eat 'em all.

My Drawings

Edited by wolfiewolfie (03/18/20 06:24 AM)

Extras: Filter Print Post Top
Invisiblewolfiewolfie
Just wingin' it.
Male User Gallery

Registered: 06/16/15
Posts: 2,177
Loc: Australia Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: wolfiewolfie] * 1
    #26542082 - 03/18/20 06:30 AM (4 years, 2 months ago)

Here is what it looks like visually:


This is currently only working with a single generation. My next step is to implement new generations (perhaps if a cell dies then comes back to life, it does so as a next generation or aomething) with different colours and behaviours and, we'll see what happens I guess lol.


--------------------


The only reason why T-rex's can't walk backwards is because they're extinct, which perfectly explains why there are no headaches in the rainforest; The parrots eat 'em all.

My Drawings

Edited by wolfiewolfie (03/18/20 06:31 AM)

Extras: Filter Print Post Top
Invisiblewolfiewolfie
Just wingin' it.
Male User Gallery

Registered: 06/16/15
Posts: 2,177
Loc: Australia Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: wolfiewolfie]
    #26542085 - 03/18/20 06:34 AM (4 years, 2 months ago)

Also, if I am understanding your magnetic field idea correctly, is it similar to boids flocking behaviour as demonstrated here: https://www.red3d.com/cwr/boids/ ?

I am looking through your code now. If I find anything I can use, with your permission, I will credit you accordingly within my own code.


--------------------


The only reason why T-rex's can't walk backwards is because they're extinct, which perfectly explains why there are no headaches in the rainforest; The parrots eat 'em all.

My Drawings

Edited by wolfiewolfie (03/18/20 06:42 AM)

Extras: Filter Print Post Top
Invisiblepsi
TOAST N' JAM
Male User Gallery

Registered: 09/05/99
Posts: 31,617
Loc: 613 Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: wolfiewolfie]
    #26542251 - 03/18/20 08:31 AM (4 years, 2 months ago)

Yeah the grid thing is a good solution to the "too many neighbors" thing for sure. Hex grids can be a cool variation.



Quote:

wolfiewolfie said:
If I find anything I can use, with your permission, I will credit you accordingly within my own code.




Sure, that sounds fine.

I have heard of that "boids" thing before but had not looked into the details too much. While there are similarities in the big picture behavior, the individual elements in my project are not actually aware of each other at all, they are all just subject to the same forces and that is why they swarm similarly. If you are able to run the code, it's the green lines with red at the tips that show the direction of the force for a given part of the map. The way I set it up, force field functions output only an angle rather than a vector, which is not necessarily ideal because there is no magnitude element to the function outputs.

Initially what that project grew out of was a simulation I made to test AI ideas for a project for school that involved a Lego robot that was supposed to play soccer, or, initially, just take a penalty kick at least. So for that application, the robot was just considering its own position, the position of the ball, and the position of the goal. The strategy was to try to take a circular arc from the current position to the position behind the ball such that the robot would be pointing in the right direction to take a shot on the goal when it arrived. So an entity knows where it is, where it's trying to end up, and what direction it wants to be pointing in when it arrives, and it wants to know what its current heading should be to be on a circular arc that meets those constraints. So it's kind of a stateless form of planning, the robot doesn't care about anything that happened before and won't need to remember its current plans later.

The "magfield" function in slopefield.py is the one that really looks like a magnetic field. Later I was working on piecewise functions such that you never have anywhere that the output value "jumps" with adjacent points, i.e. it's still continuous over its domain in a mathematical sense. The "g" function is an example of this.

Extras: Filter Print Post Top
Invisiblepsi
TOAST N' JAM
Male User Gallery

Registered: 09/05/99
Posts: 31,617
Loc: 613 Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: psi]
    #26542409 - 03/18/20 10:16 AM (4 years, 2 months ago)
Log in to view attachment

This was a thing I made in Scratch (programming thing for kids) that demonstrates some of the orbiting stuff I was talking about. If you extract the sb3 file from the attached zip file, you can load it in the online Scratch editor.

https://scratch.mit.edu/projects/editor/


Keyboard controls are space to clone existing bots, and c to delete all the bots. The original bowl with orange contents follows the mouse but not if it's too close, the empty wood bowl orbits around the first bowl, and all the other ones with contents (which don't exist until you've pressed space) orbit around the wood bowl. For the cloned bowls, the hue shows how much they turn after facing the wood bowl, and the size correlates to the minimum distance they have to be from the wood bowl in order to move.

Overall the whole thing demonstrates some pretty organic looking movement and fractal-like structure. Might be cool for a boss in a 2d game or something.

I reimplemented something similar as a web page using js and svg, might put it on github later but it looks like it's broken right now for some reason.

Extras: Filter Print Post Top
Invisiblewolfiewolfie
Just wingin' it.
Male User Gallery

Registered: 06/16/15
Posts: 2,177
Loc: Australia Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: psi]
    #26542493 - 03/18/20 11:06 AM (4 years, 2 months ago)

Awesome thanks, I'll check it out.

I've made my GUI a lot more user customisable, If you're interested in having a play around I've uploaded it in its current state here

https://drive.google.com/file/d/1bm63HsqxMROe6xdtotKc9mpJRb0kA_Hr/view?usp=sharing

In the zip file you will see WGOL.exe which 'should' be a standalone version you can just run. If it doesn't work, you'll have to run setup.exe to install it then run it. There's also a folder containing all the source code.

If you do decide to check it out, let me know if there are any issues/errors.


--------------------


The only reason why T-rex's can't walk backwards is because they're extinct, which perfectly explains why there are no headaches in the rainforest; The parrots eat 'em all.

My Drawings

Extras: Filter Print Post Top
Invisiblepsi
TOAST N' JAM
Male User Gallery

Registered: 09/05/99
Posts: 31,617
Loc: 613 Flag
Re: Need help with an emergence simulator I'm writing in C# [Re: wolfiewolfie]
    #26542534 - 03/18/20 11:34 AM (4 years, 2 months ago)

Cool I will check it out.


You might think about getting a github account, good way to share code, plus in general version control is good if you ever fuck things up and want to revert to an earlier version.

Extras: Filter Print Post Top
Jump to top Pages: 1

Shop: PhytoExtractum Kratom Powder for Sale   Unfolding Nature Unfolding Nature: Being in the Implicate Order   Bridgetown Botanicals Bridgetown Botanicals   Kraken Kratom Red Vein Kratom   Myyco.com Golden Teacher Liquid Culture For Sale   Original Sensible Seeds Autoflowering Cannabis Seeds


Similar ThreadsPosterViewsRepliesLast post
* index.dat Xochitl 659 2 08/21/03 01:54 PM
by Xochitl
* Federal Emergency Information Management Systems psilo25 810 4 03/08/03 06:55 AM
by windex
* ATI Radeon 9800PRO and "delayed write failed" errors... trendalM 620 3 07/24/04 03:07 PM
by daba
* Lost hardrive data Toddo 759 11 11/10/05 12:53 PM
by Microcosmatrix
* Microsoft's Really Hidden Files. Lana 7,926 18 07/11/02 02:14 PM
by Lana
* The Science of Synesthesia JssMthrFcknChrst 1,144 1 05/01/03 03:03 PM
by JeRiKo1
* The Inequality Taboo lonestar2004 721 2 10/13/05 11:02 AM
by Annapurna1
* comparing gentoo to debian ~ commands and configs automanM 999 0 08/30/05 06:01 PM
by automan

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: trendal, automan, Northerner
473 topic views. 0 members, 0 guests and 1 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2024 Mind Media. Some rights reserved.

Generated in 0.021 seconds spending 0.002 seconds on 12 queries.