This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes assembling a complex structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "assembling a complex structure" Watch "assembling a complex structure" New topic
Author

assembling a complex structure

Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35
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
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Where's the Controller Class? I would think on what I see so far that you really only need one Robot, just a slew of copies accorting to a Properties file that the Controller would have to read in and dispatch Robots as though a repetitive auto-pairing from one StandardTemplateRobot in a Loop constructing Robots according to some Rules.

Rules are established Computer Science. Ernest Friedman-Hill has a book on it I think. I have never done any work on Rules as I got stuck on 3.3 of Louden's book.

Each Robot has to map back to a ControllerClass, that may or may not be your Dispatcher.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Piotr,

I'm not yet totally sure about what you are trying to do. How do you want to decide which AI to use for which Robot? And where exactly are you stuck?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35
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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Piotr Trochim:
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.


How do you define "proper"?


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.


Why do you want to do it this way?
Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35


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
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Twisted Sister does it this way:
Andrew Laughlin
Greenhorn

Joined: Jan 02, 2007
Posts: 19
Forgive me if I've over done this a bit, I'm really trying to learn good design and I've got a long way to go yet. Critiques are welcomed.

If the code looks a bit like C# pay it no mind.


Best Regards,
Andrew


Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
This is good enough to consider writing a book on programming the psycotic killer bots from hell game in Java - that has never been done before using AI,... you will have to get permission from the Nice Robots Ancilliary Action Committee,.. along with paperwork, permits and so on.
Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35
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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
So one way would be to have a property file that contains the mapping between the robots and the AI, for example

T800=GoodGuy
T1000=BadGuy

You could read that property file, iterate through the deserialized robots and assign them the specified AIs.

Is that going in the right direction?
Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35
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
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by Piotr Trochim:
So how would I map the instance of the robot class to an AI instance?



[ June 04, 2008: Message edited by: Nicholas Jordan ]
Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35
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?
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Well it is a little short, it gives a general idea. For being able to change the ai engine on a Robot instance, there would be an instance method, such as PlugInNewAIEngine(AI ai){} which ..... the nomemclature is a little dicey and it is exteremly easy for me to concept but I don't want to go into neutron-spin on minor issues of nomenclature. Are the ai engines classifiable by behaviour generated? Are there many differing kinds and styles of ai engines? Is there a slew of Robots? Do the Robots need to have changeable ai engines after an allocation of a Robot instance is new'd?

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 am not trying to make it hard on you, nor swamp you with things to consider. 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.

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

Joined: Dec 29, 2006
Posts: 35
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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Piotr Trochim:
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


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

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

Joined: Dec 29, 2006
Posts: 35
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
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
[Piotr Trochim:] You're asking the correct questions   I have been doing a lot of reading and am trying to write questions which are useful. Questions were designed to pull the response you gave. Evil ai is driven by a chaotic attractor. Good ai has simple Gaussian distribution.

Thus, the - ahem - evil ... is not really true evil, just a pattern of behaviour. This chaotic, so called because that's what everything thinks it should be called, was originally discovered by a long-term Weather forecasting effort that studied large scale time series in weather patterns. This is where the El Ninio weather pattern was found.

[Piotr Trochim:] That's exactly what I'm trying to figure out.

Robot[] ribbetedRobots = new Robot[NUMBER_OF_ROBOTS];
for number of robots ...
ribbetedRobots[index] = new Robot(ArtificialSelection());

[Piotr Trochim:] So far neither I nor anyone else was able to present such a solution.   Yes, and those people also will tell you that it cannot be done. Do not spend a lot of time worrying about it, just keep you goal in mind and after some work you will have gained useable skills. At some point you can use any gains here on some project somewhere.

[Piotr Trochim:] 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.   I have woked on this problem many times, it resolves to using collections - you assign the behaviour during construction. Construction is done in a loop as building a bulky slew of robots - such as in an artificial intelligence study - would almost defacto be done in a loop. I suggest that because all Robots share Robot in common, we can make Robots a class because it is a is-a/has-a Because the Robot's behaviour is unchanging, it may be set in the construtor so that we do not have to wrestle with the GoodRobot / BadRobot design thing, this is called typing and is the bane of strongly typed languages. Untyped languages are popular in Artificial Intelligence, but I have about 32 kilobytes of code in Java trying to get ai running in Java.

[Piotr Trochim:] The reason I can't tell them from one another is that don't have any unique ids nor anything.   Acutally, they don't have to. Study Java Collections.

[Piotr Trochim:] You can think of them as of figurines, each looking exactly alike and being placed on a game board.   Distinguised only by their behaviour. You write an interface, Behaviour or AI or Movement. That interface does not in the code actually do anything. You have to implement the interface, so we could have a robot that 'moves', it is just how it moves that makes a diff. So we have a move() that checks a var set during construction. Thus, each Robot can act as an AutonomousAgent - An autonomous agent is a system situated in, and part of, an environment, which senses that environment, and acts on it, over time, in pursuit of its own.

[Piotr Trochim:] Now I want to plug them in into those AIs that will drive their steps from now on.   Robot robot = new Robot(Behaviour);

[Piotr Trochim:] Each time I try to code it, I end up with a bunch of rubbish.   I used to worry about that, do not worry about that. It is not tearing up $19.00 keyboards in frustration that is the mark of true masters. That happens about five years out.

[Piotr Trochim:] 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.
Piotr Trochim
Ranch Hand

Joined: Dec 29, 2006
Posts: 35
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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Well, that doesn't look too good.

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?
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
[Paksas:]Your remarks are very inspring.   I figured I could do some good, I recognize several points I have worked through repeatedly.

[Paksas:]It's not the robot that HAS the behaviour - it's actually the behaviour that HAS the robot:   I'll guess and let OO comment, AI has a robot. What this is actually is where typing ( the type of a thing ) becomes easily time consuming without effectiveness. If both are 'one and the same' then use the class Name to label the thing and get on with stuffing some variables and so on into it that will work with the function names you choose.


That will work.

[Paksas:]Inversing that dependency s kinda difficult if you want to fit it into what I have...
Consider having the Robot be a graphical. A manner of displaying the AI. You can describe the Robot in a file separate from the AI, thus remaining modular.



Don't get stuck here, stuff some more things in.
Code not designed to compile, notation for ideas only.
[ June 06, 2008: Message edited by: Nicholas Jordan ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Piotr Trochim:

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.



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.



But how would I identify an instance of the robot class?


If the serialization mechanism preserves the sequence of the robots in the list then you might be able to leverage that. If that was the case my first pass at a solution would be as follows:




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.


  • [ June 06, 2008: Message edited by: Peer Reynders ]
    Nicholas Jordan
    Ranch Hand

    Joined: Sep 17, 2006
    Posts: 1282
    How does the perceptor field of an Actor ( Robot / AI in poster's model ) hook on the environment at a time-cycle of T<sub>n</sub> - T<sub>n+1</sub>

    RE:
    Piotr Trochim
    Ranch Hand

    Joined: Dec 29, 2006
    Posts: 35
    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
    Nicholas Jordan
    Ranch Hand

    Joined: Sep 17, 2006
    Posts: 1282
    I wish to note before beginning that what you are tasking has been studied world wide by a hefty list of stellar names in computer science, along with slew after slew of people like us. There are several design problems that are either not solvable or will waste project resources on matters better left to staring up at the sky in the middle of summer.

    Actually, even night-time starting is productive. Recently a small team of Polish Astronomers made an anticipated discovery that NASA's billions had not, the linking of Gamma Bursts with Optical Event. Therefore, I will seek to retire some time-wasters.
  •   The thingamabob has to percieve, the is sometimes called a Perceptron.
  •   Many very routine assignments in the shop yield readily to the techniques of AI.
  •   Write crude implementations first, using code you can understand ~ then seek effectiveness. Not the other way around.
  •   Large, bulky populations in N-Dimensions, where N is non-trivial, do not yield to our level of skill. Much theory has been accomplished in telephony for that type of work, though we may study work of Masters such as Sui Sun Cheng ( PhD @ UC - Davis ) we should not bog trying to achieve that sophistication.
  •   All problems we can describe in runnable code are attackable, it is not necessary that all of them run to completion to detect patterns of behaviour.
  •   A simple state machine that starts in a known state and ends in a known state, including displaying a repeating pattern, differs from real-world conditions in a manner described by chaotics. If we discover a modeling more powerful than chaotics, we will all be in Moose Hall of Fame.

  • [Piotr Trochim:] To All nce again I need to express my utter greatfulness for your willingness to help me with this task.   We have plans for World Dominion, will you join us?
    [Piotr Trochim:] You're the best.   Tell Moose.

    Serializable interface may be tacked on anywhere you want. Saving state to disk may be done by crude methods util such time as nasty suprises are totally eliminated in code we do not understand.

    [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 )

    [Piotr Trochim:] ... 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.   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.

    [Piotr Trochim:] Huh? The operation of the system flows on a state transition from Time-One to Time-Two, then Time three and so on. This is notated in differing fields of study, what I intended here is describing the transition from a time, in which n denotes a definite clock-cycle, to the next clock-cycle - denoted n+1 Save us all a bunch of prior work by thousands and do a few thousand clocks for a run, then save the state to disk and let the next run be another § ( section ) - Leaving a gui to do the much needed human-eye observation of behaviours such as stymergy or pack-hunting.

    It is known that many behviours yield to a mathmatical technique known as the Sombrero Function, this is from the Free-Toe Bandito Empire and may be taken as an effective Corn-Dip in Fried-Beans tool. In other words, the EvilRobots battle the GoodRobots for food. To do that, it is needful that somehow the Robot has a Perceptron. Conventional AI uses what is called A-*, pronounced A-Star, to do a somewhat limited but very effective exploration of a neighborhood. In so doing, they discover what is called Hamiltonian Paths.
    Ilja Preuss
    author
    Sheriff

    Joined: Jul 11, 2001
    Posts: 14112
    I'm wondering what happened if you gave the serializer your own Robot implementation. Would it know how to handle it?
    Piotr Trochim
    Ranch Hand

    Joined: Dec 29, 2006
    Posts: 35
    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
    Nicholas Jordan
    Ranch Hand

    Joined: Sep 17, 2006
    Posts: 1282
    abstract class Robot implements Mover, Displayable{}
    class EvilRobot extends Robot{}// We have hardcoded.
    class GoodRobot extends Robot{}// We have hardcoded.

    class Engine .....

    And so on, it occured to me that writing short, useless classes serves as a mental notation. It also occured to me that the only differentiating behaviour is what would be called an approach. An evil weevil will attack, a good TwoShoes may vist. There is more than one subtle issues here. If we could have a phasor be a determinant of motile seeking, then experimentation for unanticipated patterns would be available.

    By making the move an interface, we hold open extension of the designe to do exploration of how moving rules may detect strengths and weaknesses in strategy. Strategics are well explored in gaming theory. EndGame is where vultures gather for carrion.

    I used to watch a world-class master, a master at end games. Somewhat astute about the matter I noted that he spent supplies on devious and destructive vectors, but most of them were masked by social behaviour that was eagerly encouraged. Whenever Don DeFastOne would become acute, I would watch for the responses of the players, players that were orchestrated like willing saps. Most programming reveals the need for separation of constructor from declaration, and I as well stubb in an init() - though it may not be used. Possibly make an Engine class; have it implement Mover; put the movement in Engine - as variables; Engine has a move() method; that move() is put in an enhanced for loop; number of Clocks == for each Robot in TestDomain ->move().

    This plugs a slew of Robots into a single line of code, the for loop. The number of Robots and the number of moves may be hardcoded as </code>static final int</code> but however it is done this places what seems to be bulky code in a remarkably distinct code block of small, tight design. In a similar fashion, a slew of Robots may be constructed with pluggable behaviour. How the Robot moves is determined at <code>load()</code> by reading in a file, possibly <code>DataInputStream</code>, again in a loop. Multiple runs may be passed as a Vector or other Collection, there are remarkable concept links that map from a File to a List. Small datasets may be hardcoded in source, how to do the file then becomes apparent as the same collection may handle several thousand Robots.

    The snag I think you will hang on is how to diff the behaviour of Robots, using only one engine class. If I may be bold, the possibility of a shorter range ~ omni-vision field for the friendly, cuddly robots and a forward-focused perceptor field for the attacking population. Thus, the sedentary population survives by dispersal. Carnivores have a larger delta: <code>Move(x,y)</code>, but a narrower direction change due to inertia.

    Unless of course, an animal trapper is smarter than they are.

    That's not too hard because the behvours are read in from disk and do not change.

    But either way, the trapper is either very smart or very lucky. There is no middle ground.
    Piotr Trochim
    Ranch Hand

    Joined: Dec 29, 2006
    Posts: 35
    Hi

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

    Best regards,
    Paksas
    Nicholas Jordan
    Ranch Hand

    Joined: Sep 17, 2006
    Posts: 1282
    There are only two Agent Types, so saving Population ( persist ) consists of a List of Ordered-Pairs of Positions. Starting with a List of Ordered-Pairs gives us a naive theory ( non-formalized ) of a data structure that acts as an actual file would. We initially template a minimal population as an array in the source code, doing Arrays.asList() to open an expansion path to all of Collections, which are now are candidates for achieving Utility.

    IOW - The code design scales in that the hardcode array may be replaced by an actual file.

    A possible design model is T - Total Agents; R - Ratio Good|Evil IP - InitialPositions .... To distinguish Good we could have bunnies, DumbBunnies. For evil, we could have a simple graphic of a gasoline nozzle being used as a pistol. Trying to make the motion of a displayed graphics clock to a reasonable rate is known, but I have not done that yet. Probably a Timer. Number of Good Bunnies equals Total Agents minus Bad Bunnies. Drawing intially consists of setting each of the ordered pairs in the two lists to a hue for each of the lists in an NxN array of type Color.

    Note the inclusion of the Position in the Agent class. Suprisingly, all movement of the Robotic is done by changing the x,y variable. To show the movement, the clock has to subordinate to the graphical display rate available. Some fiddling usually works.

    The author of the book I am using states that getting AI into field practice is the hope of the book. If we make some progress, we have fulfilled licensing stipulations.


    We know that artificial intelligence is built into my machine because whenever I try to position my cursor, it will go anywhere but where I try to put it.

    Also, for what it's worth:



    [ June 09, 2008: Message edited by: Nicholas Jordan ]
    [ June 10, 2008: Message edited by: Nicholas Jordan ]
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: assembling a complex structure