Darwinbots Forum

General => Off Topic => Topic started by: Shasta on December 16, 2011, 03:44:33 AM

Title: BitLife
Post by: Shasta on December 16, 2011, 03:44:33 AM
Hey guys, thought some of you might be interested in this. Myself and a classmate wrote an artificial life sim in a few of days. It uses slightly modified version of Sunweaver (DNA library from DB3), and is based around a hex grid as a world. We were in a bit of a hurry, so stuff isn't very polished, it works though, for the most part. Mutation rates and costs are incredibly finicky, I would recommend keeping them low.

List of sysvars:
Code: [Select]
move ' direction to move, goes from 1-6 in order listed for the eyes below
eat ' direction to eat, goes from 1-6 in order listed for the eyes
eatval ' ammount of energy to try and eat
repro '  works like you expect, store % of energy to give to child

 ' eyes have a value > 0 if something is there, number correlates of type (only one type implemented)
eyeul ' up left
eyeur ' up right
eyel ' left
eyer ' right
eyedl ' down left
eyedr ' down right
focuseye ' current eye to focus for the ref and in/out commands goes in order listed above 0-5

myenergy '  current energy
mypain ' ammount of energy lost in a cycle, cant remeber if it works
mypleasure ' amount of energy gained in a cycle cant remember if it works.
myage ' current age

refenergy ' energy the bot under the focuseye has
refage ' age of the bot under the focuseyey

in1 ' in#/out# work just like in DB2, uses focuseye
in2
out1
out2

mkchlr ' # of chloroplasts to create, 10 energy per I think
mychlr ' # of choloplasts you have, 20 at max, which is a dumb limit, but oh well

Source code:
https://bitbucket.org/Shasta/bitlife

Requires .net 4 to run and Visual Studio 2010 (any version, express should work) to build.

Executable attached in zip

Edit: The program should actually work now.
Title: Re: BitLife
Post by: Numsgil on December 16, 2011, 04:47:00 PM
Ah, cool that you're borrowing DB3 code :)  Yay for modularity.  I'll pretend you did that because it's great code an not because you were in a hurry.  It is sexy to see some (simple) bots written in the new language.

...

The attachment link wasn't working in my Firefox, but it's fine in Chrome.  Not sure what that's about.

...

I think there's a x86/x64 type issue.  When I try to start a sim I get a "this program has performed an illegal operation" windows box.  Debugging it, I see this exception:

"Could not load file or assembly 'Sunweaver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."  I think that means you built Sunweaver in x86 (All DB3 projects are set to x86 because of XNA compatibility issues right now), but your main program was built with "Any CPU".
Title: Re: BitLife
Post by: Numsgil on December 16, 2011, 05:13:38 PM
On the subject of exceptions, you might want to wrap the entire program in a try/catch block and spit out a dialog box with exception information if one gets thrown.  Makes debugging in the wild slightly easier.
Title: Re: BitLife
Post by: Shasta on December 16, 2011, 08:31:42 PM
Ah, cool that you're borrowing DB3 code :)  Yay for modularity.  I'll pretend you did that because it's great code an not because you were in a hurry.  It is sexy to see some (simple) bots written in the new language.
Well, I did get approval from the professor to use the library quite early on in the quarter. The fact that we ended up doing our quarter long project in a couple of the days was entirely unrelated :P Everything actually went really smoothly though, we definitely wouldn't have been able to crank it out as fast as we did with out Sunweaver. Ran into a couple of snags, but they were manageable; fun one: != can not be parsed currently, but hey, = not does the same thing.

Quote
The attachment link wasn't working in my Firefox, but it's fine in Chrome.  Not sure what that's about.
Works fine here, will poke around for what may be the cause though.

Quote
I think there's a x86/x64 type issue.  When I try to start a sim I get a "this program has performed an illegal operation" windows box.  Debugging it, I see this exception:

...
Well that's rather embarrassing, I had just specifically fixed that problem, and then I upload the wrong files :wacko: Check the top post for an updated zip.

On the subject of exceptions, you might want to wrap the entire program in a try/catch block and spit out a dialog box with exception information if one gets thrown.  Makes debugging in the wild slightly easier.
Even better, in WPF you can set a property on your Application: DispatcherUnhandledException that raises an event when an exception is unhanded. I threw a window I wrote for that purpose a while back in to the new version.
Title: Re: BitLife
Post by: Numsgil on December 16, 2011, 11:36:02 PM
If you can make a list of snags with Sunweaver while it's fresh in your mind that would be great.  I'm not going to get it in to DB3 for a while.

...

We use WPF for some stuff at work.  What's it's main difference vs. winforms?  I might look in to it at some point if I have time.  I'm actually doing a bit of UI work for DB3 right now.
Title: Re: BitLife
Post by: Numsgil on December 16, 2011, 11:48:17 PM
It seems to multithread pretty well (well, at least across 2 cores).  That's cool.

I notice that you're lock-stepping the drawing with the simulation.  If you copy the simulation into a buffer and draw things from the buffer, you can decouple the simulation and the graphics display.  That way you don't have to pause the display to ramp up the sim speed.  You don't even need everything from the simulation, just whatever you need to draw stuff.
Title: Re: BitLife
Post by: Shasta on December 17, 2011, 02:59:40 AM
It seems to multithread pretty well (well, at least across 2 cores).  That's cool.

I notice that you're lock-stepping the drawing with the simulation.  If you copy the simulation into a buffer and draw things from the buffer, you can decouple the simulation and the graphics display.  That way you don't have to pause the display to ramp up the sim speed.  You don't even need everything from the simulation, just whatever you need to draw stuff.
Yeah, the multithreading is a bit... interesting. I'll leave it at that. The simulation does run in another thread and should actually be fairly easy to entirely decouple it, if you turn off drawing there is a significant speed increase. WPF really just can't handle what we were trying to do to it (at least in that manner), the whole drawing section of code probably should be rewritten.

If you can make a list of snags with Sunweaver while it's fresh in your mind that would be great.  I'm not going to get it in to DB3 for a while.
Those were the only changes I made directly to Sunweaver, some of those things are specific to what I wanted at the time, not sure how they should actually be implemented. I'll go through and fix the bugs I found at some point during break here. I'm also planning on running a profiler over the initial loading of the simulation; it is really slow, not sure if that is caused by Sunweaver or myself.

We use WPF for some stuff at work.  What's it's main difference vs. winforms?  I might look in to it at some point if I have time.  I'm actually doing a bit of UI work for DB3 right now.
I would highly recommend using WPF over WinForms given the choice.
Title: Re: BitLife
Post by: Shasta on December 17, 2011, 03:17:46 AM
The attachment link wasn't working in my Firefox, but it's fine in Chrome.  Not sure what that's about.
Found what this was and applied a fix. Apparently SMF had a bug with the newest version of Firefox.
Title: Re: BitLife
Post by: Botsareus on January 21, 2012, 04:49:36 PM
I like the name "Sunweaver" how did Numsgil come up with that one?
Totally need a splash screen, it was loading for 3 minutes...

oh boy:

Object reference not set to an instance of an object.

   at Viewer.Board.refresh(Map m)
   at Viewer.MainWindow.background_worker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

ok, finally got it to work. The programs simplicity makes it cool.

Might wana look into program hangs a bit like after 1717 cycles.
Title: Re: BitLife
Post by: Numsgil on January 21, 2012, 09:05:06 PM
Making fun names for modules is the best part of coding! :P
Title: Re: BitLife
Post by: Shasta on January 21, 2012, 10:06:46 PM
Totally need a splash screen, it was loading for 3 minutes...

Hrm, that's odd, starting a simulation can certainly take a long time, but just loading the program should be very fast.

Quote
Object reference not set to an instance of an object.

   at Viewer.Board.refresh(Map m)
   at Viewer.MainWindow.background_worker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Fixing bugs in this is a fairly low priority for me now (got a grade and what not already  :P), but I may give it a go at some point.
Title: Re: BitLife
Post by: Botsareus on January 23, 2012, 04:48:37 PM
Quote
Making fun names for modules is the best part of coding! :P

err, sorry Numsgil there was no sarcasm (or attempted sarcasm) attached to why I wanted to know how you came up with "sunwhewer", I really just wanted to know. I guess it make sense because the sun makes things mutate.

Quote
Might wana look into program hangs a bit like after 1717 cycles.

Never mind, it was my cpu.

Quote
Fixing bugs in this is a fairly low priority for me now (got a grade and what not already  :P), but I may give it a go at some point.

I found two more bugs: When I try to load an existing simulation. Also, when after about a good 10 hours I tried to open a DNA I got a crash. Ouch. I had no way of saving my results of a zero bot sim. At least I will tell you about it:

Basically I put a whole bunch of zero bots , and set motion cost to nothing. I got all the robots on screen move top left except for the vegs. The vegs where set 48x1000x48x48.
Title: Re: BitLife
Post by: Numsgil on January 23, 2012, 06:44:33 PM
It's not that hard to come up with cool codenames.  Basically the criteria is:


examples:




Title: Re: BitLife
Post by: Numsgil on January 23, 2012, 07:05:39 PM
Oh also: Lima - Goddess of thresholds and doorways and also the name of a UI library for Darwinbots.
Title: Re: BitLife
Post by: Botsareus on January 27, 2012, 03:20:07 PM
KOOL