<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jul 6, 2013 at 3:54 AM, Felix Gallo <span dir="ltr"><<a href="mailto:felixgallo@gmail.com" target="_blank">felixgallo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the mutable world, you might structure it as a hashtable of hashes, or hashtable of sets etc., and use the coordinate tuple {x,y} as a key into the hash table, then mutate the list. addtocell(Coordinate, Value) and removefromcell(Coordinate, Value) are very small, easy, and extremely fast (sub-second for a million iterations of addtocell()).</blockquote>
</div><br>In a game, you will get into trouble with this representation alone. You need to have locational information about what are in the cells. In other words, given a thing in a cell, you must know, quickly what are adjacent or close to that cell in order to quickly asses what to do and so on.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra" style>The trick in a game is spatial separation. In other words, you break the world into regions and then you handle each region by its own, gaining locality. The same is true in Erlang. You need to break your big array into a spatial structure, probably controlled by a process tree which handles each area of the whole world. In turn, this enables parallel execution and it also simplifies local decisions which can be made process-local.</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>Take a look into stuff like K,d-trees, octrees and so on for ideas on how to approach the problem in a more general fasion.</div><div class="gmail_extra" style>
<br></div><div class="gmail_extra" style>A blind grid can be made in ETS: {{X, Y}, Content}. But this runs the risk of having to copy Content to and from a process on each access and it is also not safe from races on insertion. Think is, this is not a trivial problem.</div>
<div class="gmail_extra" style><br></div></div>