Super Simple Generic Algorythm, need help.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

Super Simple Generic Algorythm, need help.

Post by Joelrodiel »

I just recently started getting interested in Genetic Algorythms, and decided I would make my own really simple one. My vision is for it to be 4 squares (or people like i call them) that spawn in a maze and go in random directions, recording all the X and Y coordinates where there are walls. Then when those die, the spawns of them remember all the coordinates of their previous people and avoid those certain spots, everytime getting closer to the end.

The problem Ive run into is that in my Movement Function, when more than one block is spawned at the same time, they start losing the avility to collide. What can I do? Ive commented my code so its easy to follow, and I would really appreaciate if anyone could look at it and suggest something. My best guess is that it has to do alot with for loops, as Im not good at them. So yeah.

Controls:
Spacebar to spawn one people (Max 4)
Return to delete everything once someobodys one

Thanks in advance.
Attachments
game.love
(3.54 KiB) Downloaded 136 times
User avatar
partnano
Prole
Posts: 20
Joined: Sat Jun 11, 2016 4:53 pm
Location: twitter.com/partnano
Contact:

Re: Super Simple Generic Algorythm, need help.

Post by partnano »

Heyhey!

So, the main issue of your collision problems stems from the function testMap(). It essentially boils down to the fact, that you are testing the collision on all of the entities at once, which can only lead to strange behaviour. What you want to do instead is to move every entity by itself (that, you are doing in movement already) and check only the currently moving entity for collision.

I quickly wrote this function and replaced the testMap()s in blocks.movement with it (with this it works, though I didn't test in depth):

Code: Select all

function check_collision (x, y, entity)

   -- a block is 32 pixels wide / high, so to get the array coords divide through 32
   
   -- entity coordinates
   e_x, e_y = entity.grid_x / 32, entity.grid_y / 32
   
   -- select location we want to check for collision (entity coords + direction)
   if currentmap[e_y + y][e_x + x] == 1 then
      return false
   end

   -- if nothing was hit, movement in this direction is fine
   return true
   
end
Hope this helps for now :)
Post Reply

Who is online

Users browsing this forum: Todespreis and 81 guests