shanive / bgu-ailab-bandits

bandits expiriment
6 stars 0 forks source link

create instance by class name #60

Closed shanive closed 12 years ago

shanive commented 12 years ago

David,

When we implemented tournament on python, we got the agents' class names from command line and used a "getattr" function. Is there any way of doing this on c++, that you know of? otherwise i will have to use "if" statement on every agent we have.

Thanks, Vered.

dtolpin commented 12 years ago

there is a way to use some sort of reflection (that is, accessing classes by name), but it is awkward.

what you want is an agent factory that gets the name of an agent and creates an agent. The factory may use a map from from agent names to agent creating functions, and a method like registerAgent(name, creator) that registers all agents on startup.

or any other way you find usable.