|
Hi peoples! This is my first post here, and hopefully not my last.
Anyway, I'll skip the intro and the backstory, and just tell you my problem- I have an aLife simulation in which there will be several 'creatures' which need to 'think' every frame. Originally, each would be controlled by an evolvable program, but due to time constraints in obtaining results from the simulation, I'm now planning a system whereby each section of the thinking method has several options, determined by the 'genetic code' of the creature.
An example, to clarify: There may exist several methods for choosing a target within a creature's visual field; the creature may want to focus on the brightest object, the fastest moving object, the object most like itself, the tastiest looking object, etc. etc.. Each of these strategies would be coded a slightly different way, and depending on what gene a particular creature has for 'target choosing' a different piece of code would need to be executed.
So, basically, I have a method, which I want to insert different snippets of code into, at runtime. My question is: what is the best method of achieving this? I have considered three possibilities so far:
1. A very big switch statement. It would simply choose which bit of code to execute depending on what the value of the gene for a particular thing is. This method would work, and would work well, but it would be a nightmare to maintain and is just a bit crap really!
2. Hard code the snippets as functions somewhere in another file, and store pointers to those functions in the creature objects- call the functions with the appropriate parameters in the 'think' method. This is tidyer, but is still not an elegant solution, and I can see problems developing in not knowing numbers of parameters and whatnot beforehand.
3. Some kind of clever plugin system, whereby each snippet of code is pre-compiled and able to be linked in and used at run-time. Very extensible, very slick, but really hard to do, a lot of work (since it'll be cross platform, a lot of compiling will need to go on I guess), and I'm not sure if it's really necessary, or particularly diferent from option number 2.
Hopefully one of you chaps will be able to suggest a mystery 4th option, I'm hoping for something similar to option 2 but a bit more elegant and robust! Thanks in advance for your help, folks!
|
|
|
|
|
Something like no 2:
Declare a helper class which is a gene repository. Any new gene (methods) which you want to add register themselves with this repository. All genes inherit from a pure virtual base class, so they have to implement an interface which allows your think procedure to interact with them.
Once you have the repository, you have to create a standard interface through which you need to access these genes. In your case you do not know in advance what parameters they are going to need, this means that you probably need to pass a pointer to an object which allows query access to the "world state"/"creature state" so that gene can make its decisions.
You can ask the repository for a list of the registered genes and store a pointer to the selected on in your creature class. You can then call functions on it.
We do something very similar to this to handle printing of reports where report sections register themselves with a repository, and we ask them if they apply to your document. If they do, they get added to a list which is used to generate the final report.
If you vote me down, my score will only get lower
|
|
|
|
|
Well, I've been thinking this whole idea through and I've come to another stopping point... Let me fill you in on the wider picture:
There are actually three 'types' of genes in my implementation; Code genes (like the ones I've been taking about), variable genes (which code for just that, a variable- be it a bias, a weight for something, the number of legs the creature has, whatever), and 'enabler' genes (which are a boolean, and an integer specifying how many genes after that gene are to be skipped or not). The genetic code is pretty much static- that is, during the lifetime of a creature, the individual positions in their genetic code will always mean the same thing, and the code will not get bigger or smaller. What will change is the values held at each position in the genetic code.
I need some way of storing what each position codes for (which type of gene), and also the section of code to be executed, should a particular position call for it. I figure that a base 'gene' class is a sensible start. I also figure that 'VariableGene', 'EnablerGene' and 'CodeGene' should inherit from this 'Gene' class. Finally, each of the snippets of code should be in classes of their own which inherit from 'CodeGene'.
Now, where it starts getting hairy is here: There are many positions that code for each of these types of genes, so that suggests to me that I should create an instance of the appropriate gene type for each position in the code, to store in the manager. So, I have a gene for the maximum speed of a creature, I create an object of type 'VariableGene', and add it to the manager. There will also be many positions which code for a particular thing the creature has to think about, so it makes sense to create an instance of the 'CodeGene' class for each of these. The tricky bit is that these instances need to somehow store the set of possible code snippets the creature can run for this gene (alleles, if you're into genetics).
It would be all too easy to have a static, self-registering class for each and every gene, but this wouldn't be a very nice solution- there would be a lot of redundancy, and a lot of arbitrarily named classes ("EnablerGene12" etc.).
My first question is: can instances of classes be registered automatically? If I recall correctly, only static classes can do things automatically at program instantiation.
My second question is: How would I go about storing a list of cope snippets (functions, if you will) in the instances of 'CodeGene', and more importantly, how would I get these code snippets to automatically register themselves? I could have a list of function pointers or somesuch, but that seems a bit hacky. Really, a class for each code snippet seems a good idea.
An example of how I envisage the system working: Some part of the program wants to know how many code snippets there are for a given gene. It queries the gene manager about a given slot in the genetic code, and the manager consults what is stored there. It finds an object of type 'CodeGene', and queries that object as to how many code snippets it can code for. The CodeGene object returns that number down the chain back to whichever part of the program needed to know.
Now, if anyone can suggest to me a better way of doing this, or give me a clue as to how to implement this (my C++ skills are a little rusty), then I'd be very appreciative indeed! Thanks for your help so far, and thanks in advance for your replies!
|
|
|
|
|
Hi all,
I need to do the following with my C++ MFC program:
1. I want to download a webpage from the internet (http://www.mysite/mypage.html), this is done through the CHtmlview::Navigate method
2. when it finishes loading, I need to programitically fill a form in that page, lets say that the page contains elements button1, text1,... then how would I get/set their contents in my c++ program?????
any answers are welcome, source code is very preferable,
Thats all
Mohammad Gdeisat
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
|
http://secure.metawerx.net/resources/code/chtml.htm
check this link
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Something really weird is happening to me. I run the next code snippet:
<br />
int pos = File.GetPosition();<br />
File.ReadString(str1);<br />
File.Seek(pos, CFile::begin);<br />
File.ReadString(str2);<br />
str1 is different from str2 - str2 is read from a few bites earlier in the file. what's even wierder is that the difference between str1 and str2 is changing when I try this code on different locations in the file.
the file is unicode, hebrew and I'm running visual c++ 6.0, if it matters.
|
|
|
|
|
CStdioFile::ReadString() performs reading line-by-line (reading is stopped by the first newline character; the '\n' character is removed from the string). You do not use Seek for text files where information is stored on a line-by-line base.
Some information concerning the unicode staff in your case can be found here, at CP:
http://www.codeproject.com/file/utf16.asp[^]
SkyWalker
-- modified at 15:58 Sunday 20th November, 2005
|
|
|
|
|
I still don't get it - if the file pointer is located at the same point in both instances, why does it matter what order do I use to read?
is there a way to 'bookmark' a location and then read using readstring? is there a way to go back in the file?
|
|
|
|
|
I wanna convert my MFC application to C#. Please help with suggestions and/or tools?
-- modified at 8:47 Monday 21st November, 2005
|
|
|
|
|
thats the tough task... I believe you have to do that manually
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I decided to rewrite the application.
For the UI conversion there is a tool RC Convertor from www.dudelabs.com but I cannot find any other tool which can convert my business logic code from C++ to C#.Will keep you posted with my progress.
|
|
|
|
|
:-DMy operating system is windowXP,and programming language is Vc++6.0.I want to begin to learn to use Directx 9 in my program .Do I need to install Microsoft DirectX 9.0 in my computer?Which Head file do I need to include in my program?
Anyway,How to establish the programming enviroment to begin my DirectX program?
Thank you very much for your answer!
sude
|
|
|
|
|
|
In VS .NET 2003 one used the following:
#import "libid:a155fa04-fade-491b-b007-fb9379ea47db" raw_interfaces_only named_guids
#import "libid:233ADBAD-405A-4249-AA0B-828093D57184" raw_interfaces_only named_guids
#import "libid:238B5186-2429-11D7-8BF6-00B0D03DAA06" raw_interfaces_only named_guids
to make use of the VCCodeModel, VCProjectModel and VCProjectEngine. However when changing to VS 2005 these libids are incorrect and I can't find the corresponding ones for VS2005. Does anybody know where I can find them?
I am the handsome one in the crowd.
|
|
|
|
|
Hello
As i told in earlier post that i am using MFC to read a file from a floppy that is using linux ext2 file system. Mr. Kaken told me that i could use CreateFile(...). Does CreateFile returns an handle to inode of that file?
Thanks.
We Believe in Excellence
-- modified at 3:04 Sunday 20th November, 2005
|
|
|
|
|
Hello again.
CreateFile returns a HANDLE (to the volume in this case). You use that handle to read from and write to the volume.
The HANDLE (AFAIK) doesn't mean anything outside Windows itself, it's just a unique identifier to use for file/stream operations.
When you open a volume, you get all the sectors of that volume as a contigous "file", kind of.
From there, it's up to you how to handle each and every sector. Just remeber, the smallest bit of information you can deal with is one sector.
|
|
|
|
|
Can anybody tell me how can i acces the first bytes at the entrypoint of an exe. I know the PE layout, format, but i don't know how i can translate the entrypoint to fileoffset and how i read those bytes?
-- modified at 2:25 Sunday 20th November, 2005
|
|
|
|
|
i developed one testmfc OCX control with GUI
when i tried to invoke OCX through create intance
hret = test.CreateInstance(__uuidof(TestOCX));
its creating successfully but no GUI parrt is showing.
any kind of help appreciated.
thanx ..
reagrds
Rajesh
|
|
|
|
|
Hi ...
I am new to VC++ though i have written a few C++ programs back in the day when u did not need a PHD in computer science to use a microsoft IDE.
Every .NET FORMS application i create using the wizard, terminates with a runtime error R6029 ... "This applicatoin cannot run using the active version of the .NET Runtime. Please contact the application's support team for more information."
That second sentence is a real laffer.
Even the simplest example in the VC++ 2003 tutorial has the same problem. It compiles and links just fine, but gives that message soon after the F5 key is struck.
I've never been a microsoft fan, and this crap just entrenches that dislike.
Any ideas or suggestions?
Thanks.
|
|
|
|
|
|
Thank you Graham ... it worked.
i had seen this b4 but i did not know how to apply it ... now i do. Besides, I culd not comprehend how THIS could apply to my shiny new VC++2003 system:
"R6027: An application built with /clr and the Visual C++ .NET 2003 (7.1) compiler is being run on a machine that only has version 3705 of the common language runtime, which is the runtime version that shipped with Visual C++ .NET 2002 (7.0)."
WHAT!!!!!
This solution raises lots of questions: Why does VC++2003 ship with the 2002 runtime library and NOT the 2003 version? Why does the 2003 compiler/linker generate code that does not run with the SHIPPED runtime?
Most important ... HOW ON EARTH WOULD ANYONE KNOW THEY SHOULD INCLUDE "/clr:initialAppDomain" TO SOLVE THE PROBLEM? Why didn't the build wizard include it if micro$oft KNEW of this ridiculous situation?
UNBELIEVABLE ... typical micro$oft ... maybe for ANOTHER TEN BILLION ...
GRRRRRRRRRRRR!
Thanks, Graham
|
|
|
|
|
I did a dialog to display the bmp picture. Then i add some coordinates and text using pDC.
But i don't know how to save this bitmap with what i have added as a bmp file?
Does any one can give me some tips?
Thanks!
|
|
|
|
|
Hi,
Capture the client area and save it.
HDC hdc = ::GetDC(hWnd);
CDC dc, memDC;
dc.Attach(hdc);
memDC.CreateCompatibleDC(&dc);
CRect rc;
::GetClientRect(hWnd, &rc);
CSize sz(rc.Width(), rc.Height());
CBitmap bm;
bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);
CBitmap *pOldbm = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, 0, 0, SRCCOPY);
// now you can do what you need to with bm.m_hObject
memDC.SelectObject(pOldbm);
bm.Detach();
::ReleaseDC(dc.Detach());
Bye
Cool Ju
Dream ur Destiny
|
|
|
|
|
Hello, everyone,
I want to copy a dialog from one program's resource file to
other program's resource file?
I tried , but failed.
Who can tell me the right method to do this, Thanks a lot!
|
|
|
|
|