Guest User

Untitled

a guest
Jul 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. let loopLymphocytes = function () {
  2. ...
  3.  
  4. // update each creature
  5. let lymphocytes = world.lymphocytes;
  6. let bacterias = world.bacterias;
  7. lymphocytes.forEach(function (creature) {
  8. // move
  9. let input = [];
  10. for (let i in bacterias) {
  11. input.push(bacterias[i].location.x);
  12. input.push(bacterias[i].location.y);
  13. input.push(bacterias[i].velocity.x);
  14. input.push(bacterias[i].velocity.y);
  15. }
  16. let output = creature.network.activate(input);
  17. creature.moveTo(output);
  18.  
  19. // learn
  20. let learningRate = .3;
  21. let target = [targetXLymphocyte(creature), targetYLymphocyte(creature), targetAngleLymphocyte(creature)];
  22. creature.network.propagate(learningRate, target);
  23.  
  24. // draw
  25. creature.draw();
  26. });
  27. if (true)
  28. setTimeout(loopLymphocytes, 1000 / fps);
  29. }
Add Comment
Please, Sign In to add comment