Piotr Trochim

Ranch Hand
+ Follow
since Dec 29, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piotr Trochim

Hi

That has sense - thanks. I'll see what I can do with that.
Thanks man

Best regards,
Paksas
Hi


Nicholas Jordan wrote:

Robot is your base class. Since the Evil Robots may be smarter, equal, or dumber - there is some intrinsic which differentiates Good/Evil - perhaps that is a boolean, a BooLean or a Leaning Boo Lean, in any event it comes canned in the Robot and therefore is built in when the Robot is consturcted. So it's Robot(boolean);// Which may be done by reading a list from a file. A file is just a fancy terminology for an ordered sequence of bytes. You do not want Good robots to bite Evil robots, else the system goes into an irrecoveable state.


............

In other words, the EvilRobots battle the GoodRobots for food. To do that, it is needful that somehow the Robot has a Perceptron.



Ok - now I see why I didn't get you there for a sec. Your perception of the abstraction here is quite natural - each robot HAS some kind of behaviour.

The system I have to work with however has been modeled in a bit different way:
The robots are nothing more than just the figurines on the map - avatars if you wish.
The AI is a controler that moves the avatars. So the whole GoodRobot-EvilRobot kinda thing is actually resolved on the AI level, and the is visualised using the Robot figurines.

Now - you're proposing a Robot class that HAS-A behaviour - if I understand correctly, that's exactly the same thing Peer Reynders proposed a few e-mails ago with his MyRobot mediator.
I pointed out why this design is a flawed approach in this case.

But your approach is great - if I could create a new Robot class - my own class - that would have the behaviour, and then ADAPT the classes I have to this new design needs...

I'll try giving it a go and will get back to you with the results...



Ilja Preuss wrote:

I'm wondering what happened if you gave the serializer your own Robot implementation. Would it know how to handle it?



Nope. I's kinda dependent of the Robot class. As I mentioned before, I could extend the Robot class, incorporating the new behaviour there... Maybe that's a way to go.

Let me check and get back to you soon with the results...


Nicholas Jordan wrote:

Write crude implementations first, using code you can understand ~ then seek effectiveness. Not the other way around.



I've never done any piece of code in a different way - that's why I'm evolving this piece using TDD - and that's probably why I get so many obstacles thrown under my feet as I proceed.




Nicholas Jordan wrote:

[Piotr Trochim:] I don't want the user to save the state of the app, and then restore it only to find out that a good robot he's been playing before suddenly became an evil one. Do you want to save ( or display ) results of a run or aggregate datasets achieved by individual runs for mathematical analysis? ( Hint, save N - run()'s ... subject the results to mathematical techniques )




I just want the same AI to be attached to the same robots after deserialization. and I want to be able to serialize at any time I want.


Nicholas Jordan wrote:

We have plans for World Dominion, will you join us?



As you can see, I'm not that good at this World Domination thing, but sure... why not It's gonna be spectacular - either a success or a fiasco


Best regards,
Paksas
Hi


Ilja Preuss wrote:

What assumptions can you make about how the serialization mechanism works? What needs a Robot to do to be serializable? Would it suffice to implement the Serializable interface?



Actually I don't care how the robots get serialized and deserialized - I just send a list of them to the serializer I have and that's it.

If I was to implement the Serializable interface, I'd have to do that in a child of the Robot class, or I'd have to make a new class and adapt the Robot class to its interface - its feasible.


Nicholas Jordan wrote:

public static AI getInstance(){
int selector = Math.random();
if(selector > half){
return new AI(EvilRobot);
}
else return new AI(GoodRobot);//



That's randomizing the behaviour for a robot. I don't want that - I want the particular instances to have specific behaviour. Each robot is located on some coordinates.

I don't want the user to save the state of the app, and then restore it only to find out that a good robot he's been playing before suddenly became an evil one.



Peer Reynders wrote:

Now given the constraints that you are working under the following solution is a bit kludgey but workable:


Create a disassembler that serializes a List<MyRobot>.

* The disassembler generates a List<Robot> from List<MyRobot> with myRobot.getRobot(). Then it uses EntitiesSerializer to serialize the Robot instances.
* The disassembler generates a List<AI> from List<MyRobot> with myRobot.getAI(). Then it uses your own AI serializer to write a SECOND file of serialized AIs (in the same sequence).



Create an assembler the generates a List<MyRobot>.

* The assembler uses EntitiesSerializer to deserialize a List<Robot>.
* The assembler uses your own AI de-serializer to read the SECOND file of serialized AIs into a List<AI>.
* The assembler creates a List<MyRobot> from new MyRobot instances created by combining the Robot and AI found at identical positions of List<Robot> and List<AI> respectively.



I like the idea of a new layer of indirection - the MyRobot class.
It definately solves the problem.

The only problem is that I have lots of other code that uses the instances of Robot and instances of AI class.

The instances of those other classes are created also after the Robots are desrialized, at the same tame AI is created. I didn't mention them before because I'ms striving for a mechanism that will allow me to grab a created Robot class instance and plug it into all the other places I need it in.

Having it done through a mediator the MyRobot class is renders it very cumbersome.



Nicholas Jordan wrote:

How does the perceptor field of an Actor ( Robot / AI in poster's model ) hook on the environment at a time-cycle of Tn - Tn+1



Huh?



To All: Once again I need to express my utter greatfulness for your willingness to help me with this task. You're the best.


Best regards,
Paksas
Hi

Your remarks are very inspring.

The only problem is here:

Robot robot = new Robot(Behaviour);



It's not the robot that HAS the behaviour - it's actually the behaviour that HAS the robot:



Inversing that dependency s kinda difficult if you want to fit it into what I have...

However - the thing with the collections is not a bad idea.
Plus that it can go along with the properites. But check out the code I tried to put together based on your suggestions - how would you implement the parts I marked with a question mark?



What do you think about it?


Best regards,
Paksas
Hi


Well, you really only can't identify them if they provide a means to identify them. What does their interface look like?



This is the interface of the Robot class:



A robot can basically be moved from one position to another. That movement is realized in the implementation which is implemented using a 3D engine I'm using.



Oh, and who does serialize them? Could you add some information while serializing to identify the robots?



The serialization mechanism looks like this:




I know it's not rocket science. Like I mentioned before - I'm looking for a way to work with such a crappy and hard to handle implementation and combine it in an extensible object oriented manner.

Can you see a posibility here to make it happen?

Best regards,
Paksas
Hi

You're asking the correct questions


Are the ai engines classifiable by behaviour generated?
Are there many differing kinds and styles of ai engines?



I don't quite get the question, but I hope this will answer it:

There's a common interface for AI and I have different implementations of it. So for instance there's something like that there:



So we basically can make the players do the same actions, only those will be carried out in a different way.

Does it answer the question?


Is there a slew of Robots?


For the purpose of the example I have only two, but I expect there to be lots and lots of them.

Do the Robots need to have changeable ai engines after an allocation of a Robot instance is new'd?



Nope

Is it more important to get a baseline implementation working so that improvements may be contemplated and testing done or is it more important trying to design a general-purpose, widely-adaptable design that follows proven design principles that are known and reliable.



I want to learn how to assemble something from the existing solutions.
I'm not working on a deadline nor I want to design soemthing general-purpose.

What I want to see is how to take two "closed" pieces of code designed with some totally different purpose in mind, and then combine them in an extensible manner.


We may assume since the Robot is established design, the ai is pluggable and we are doing prototyping that matching an ai engine with a robot ( instance ) resolves to how to connect the Robot and the DrivingEngine.



That's exactly what I'm trying to figure out.

It is pretty simple actually, but if not done correctly we could get some strange behaving robots.



So far neither I nor anyone else was able to present such a solution.

The main problem for me is that I have a bunch of Robot class instances I can't really tell from one another, and I somehow need to match them to the AIs.

The reason I can't tell them from one another is that don't have any unique ids nor anything. You can think of them as of figurines, each looking exactly alike and being placed on a game board.

Now I want to plug them in into those AIs that will drive their steps from now on.

Each time I try to code it, I end up with a bunch of rubbish.

Can you please help?

Best regards,
Paksas
Hi




That doesnt quite add up - ass I mentioned before, I have different AIs I want to match onto specific instances of the Robot class.

Now I like the "properties file" approach - the only thing is how to do that without touching the existing interfaces of the Robot and AI?
Hi

I thought about that - it's not bad. But how would I identify an instance of the robot class?

I mean - the Robot class is pretty closed - I don't want to modify it just for that purpose.

So how would I map the instance of the robot class to an AI instance?

Best regards,
Paksas
Hi

Thank you guys for the responses.

However - there's a small problem




Everything looks fine, except for one thing - in the followng lines you actually execute AI commands:



I have classes that do that. And these classes I want to match onto the proper Robot class instances I retrive from a file - that's the actual mechanism that I want to build.


Do you have any ideas how to do that?

Best regards,
Paksas


Let's assume that I have two instances of Robot class:
- T800
- T1000

Now - the first one is a good guy chasing the other one around. The other one (T1000 that is) wants to destroy the world (I made it up myself - pretty neat, huh - not copying any well known move or anything .

So obviously I want T800 model to be navigated by the GoodAI class instance, and T1000 to be navigated by the EvilAI class instance.



Of course I want the solution to be flexible, so that if I decide to add an action twist, I can alwsays add a new robot and configure it with any of the AIs I have or may come up with...


Why do you want to do it this way?



Well - I'm not as good coder as one may think - the serialization mechanism for the robots - I already have it locked in a library. The worst part is that I can't enhance its code - it's kinda crappy, but does the job - if that's what you're asking for...

The bottom line is that I can't change the code that already works and does the job.

Can youo please help?

Best regards,
Paksas
Hi

Thank you for the responses.

An instance of the Robot class represents a robot - so if I want to display two robots, I need to have two distinct instances of it.

An instance of the AI class controls a robot.

How do you want to decide which AI to use for which Robot? And where exactly are you stuck?



That's exactly what I'm stuck with.

I have two instances of a Robot class created based on a contents of a serialized file.

Now I have two different AIs I want to connect the robots to.

What I'm stuck with is how to do that? I would like to come up with a mechanism that would take the created instance of a Robot class and use it to create a proper AI.

The problem is that I don't want to be serializing AI along with the Robot it uses.
I'd rather have Robots serialized independently, and then have something else creating AIs using the deserialized Robots.


Is that feasible?

Best regards,
Paksas
Hi

I have a class - Robot is its name. It represents a robot that can deal some serious damage

Now - if I want to take over the world, I need an army of robots (an army of two will do just fine for this example).

So I have my two robots and I have their whereabouts stored in a file, so whenever I start up my "Tak over the world" applications, the robots are loaded from a file.

Now - I've devised a bunch of AI algorithms that command the robots - each of them is created around a robot it's sipposed to command:




Now I have different AI implementations and when the app starts, I wnat to create these AI drivers and make them steer the robots I read from the file.

Can you please help me figure out how to do that?

Thank you very much.

Best regards,
Paksas
Hi

Here is one of the approaches I had - it's not that bad and I think it is a way to go, but if you could take a look at it and tell me what did I screw up, that'd be great.

A word of information - in the Red Phase I always use pseudocode to get my idea down onto the paper, then I translate it and make it work during the Green Phase.

Iteration 1, phase Red

I want to be able to create something on my scene - let that something be a terrain.



... hmmmm - how to test that... - I don't want to get the implementation of how I create a terain in a particualr 3d Engine involved yet...

... Yet another approach ....


.. ok - at least this time I had a clear testing point...

Iteration 1, phase Green

The shortest steps to get things working....



YEAH - IT'S WORKING

Iteration 1, phase Refactoring

I messed it up quite badly - the code smells.

The Terrain class is just a marker - it's used only in the test - I'll remove it for now



Ok - seems kinda clean. I have my scene definition captured in one class, the way it should be built in the other ... Let's move on.

Iteration 2, phase Red

I want to be able to add not only the terrain, but also the light to the scene.





Iteration 2, phase Green



Ok - it's working. Now for some refactoring...

Iteration 2, phase Refactoring

I don't like it - Open-Close principle's good name is being dragged throught the mud here.
I''m expecting all kinds of different entities here, and I can't keep adding methods each time a new one comes up...

One more thing - I noticed that I needed to introduce exactly the same change to the factory as the one I introduced to the SceneDefinition.
Maybe their responsibilities are not so well separated after all...


Basically, after applying DIP I get the following code, where instead of having a factory, I end up with a bunch of creators that can handle particular objects creation process.






Everything works, and now I don't have to worry about breaking the OCP any more.


BUT - what I ended up with - I mean the SceneDefinition - that's just a wrapping for a list - does nothing more but store the creators and run a create on them all - it resembles more of a Compound then some separate entity - so I'll evolve it towards that...




Ok - now that's more like it



So basically that's my story. I can now create those things dinamically based on some arbitrary representation using parsers etc..



What do you think? Is it ok?

Regards,
Paksas
15 years ago
Hi

I have the following story to implement - I need to be able to build a scene in a game based on its predefined representation.

On one hand I have my scene - that contains the definition of:
- the terrain
- lights
- cameras
- players

On the other hand, there's this factory that knows just how to "create" them in the 3D engine I'm using.

Now - I tried several approaches, and each time I finish the refactionring after the first iteration, I end up with stuff I started

Would somebody please be willing to show me how to evolve the whole thing through the tests?
If so, then start evolving the code from scratch - meaning that you should evolve the scene definition and the factory I mentioned as well.

Thank you so very much

Regards,
Paksas
15 years ago


Actually now you have a InstallDevice class that has to know about all the possible relationships between all engines and all devices



Ok - you're right - the code you posted really prooves your point - now I can create a command in one place and invoke it in a totally deifferent time and place.

Well, how and when were you planning to find out? The user command could tell you with "install MyDevice" - but you can only install "MyDevice" if you know what "MyDevice" is.



Maybe this test will tell what I had in mind:




The point is that I don't want to keep putting engine instance into every method call - that would model a driver that operates on many engines at once. I want to make a point that my driver operates one and only one driver.

This means that we have to delegate the moment of engine-device checking compatibility etc. till the moment when the driver executes the code.

The way I see it, the code of the AttachDevice command would contain the calls to that factory etc., wouldn't it?


And once again thanks for your help - I'm starting to understand this.

Thanks a lot

Regards,
Paksas