Author Topic: Genetic Algo, Please help  (Read 6364 times)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Genetic Algo, Please help
« on: 2013-10-26, 08:46:12 PM »
Wrong section: but it's the only section that I can see:

Does anyone see any issue with this code?

http://cfrancis.heliohost.org/Tests/

(This isn't my homework, by the way, it's something unrelated)

It's supposed to be generating a series of triangles similar to this article:

http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/

I know the American flag is complex, I've tried it with a solid color image and it works well (Nearly perfectly), but trying it with an image of the American Flag, Darth Vader, or even a photo of Adam Sandler makes the program fail to work.

Thanks, SGDK2 Community.

EDIT: I've seemed to have found the heart of the problem!

But I don't understand why it's a problem.

I want to get/set the DNAA for a particular Polygon instance using this.DNAA and this.child.DNAA, but for some reason, JavaScript sets every DNA member to the value that I say for every Polygon Instance in the Population array when I do so, why is JavaScript doing this? In my fight() function, whenever I set the DNAA value of this.DNAA, the browser console is telling me that for all objects in Population, their DNAA is also being set to my value automatically.

My main question: Why is it that whenever I try to set the value of this.DNAA, it just ends up setting the value of all of the DNA arrays for every Polygon Object in my Population Array, rather than just setting it for the Polygon Object I'm trying to reference with, "this". I can get all other members of my Polygon Instance with "this.v1" or "this.red" but for "this.DNAA", it throws errors.

(DNAA is just an Array<Number> of size 3.. Once I can set the DNA for specific instances of Polygon, rather than using a shared DNA pool for all Polygons, I can end up with distinct colors, rather than a jumbled mess of all of the colors on the screen.)

I'm reading up and it says that JavaScript isn't good with instances, that there are only singletons in JavaScript. That's funny, because for every other member of my Polygon class, getting and setting instance-wise is working fine, but for DNA, it seems to be failing severely.

http://javascript.about.com/od/objectorientedjavascript/a/oop21.htm

Another area that I can't understand is why my Array.splice method doesn't work as expected. It's removing certain Polygon instances that honestly, shouldn't be removed from my list. The underlying code is right, but the splicer is splicing the wrong objects from my collection.
« Last Edit: 2013-10-27, 12:34:37 AM by v6v »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Genetic Algo, Please help
« Reply #1 on: 2013-10-27, 07:12:37 PM »
1) Are you unable to access the Off Topic section?

2) Have you tried to find/get an answer to your question on http://stackoverflow.com/

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Genetic Algo, Please help
« Reply #2 on: 2013-10-30, 09:56:10 PM »
The pages wouldn't load on this site, the sourceforge site wouldn't even load for me.
(I don't know what happens, it usually happens for the forum websites that I try to access)

I've eventually fixed it on my own :)

I'll try StackOverflow
« Last Edit: 2013-10-30, 10:08:27 PM by v6v »