Example #1
0
        public ClarionAgent(WSProxy nws, String creature_ID, String creature_Name)
        {
            worldServer = nws;
            // Initialize the agent
            CurrentAgent = World.NewAgent("Current Agent");
            mind         = new MindViewer();
            mind.Show();
            creatureId   = creature_ID;
            creatureName = creature_Name;

            // Initialize Input Information
            inputWallAhead      = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_WALL_AHEAD);
            inputFoodAhead      = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AHEAD);
            inputJewelAhead     = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_AHEAD);
            inputDistantJewel   = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_DISTANT_JEWEL);
            inputDistantFood    = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_DISTANT_FOOD);
            inputDeliverLeaflet = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_DELIVER_LEAFLET);

            // Initialize Output actions
            outputRotateClockwise = World.NewExternalActionChunk(CreatureActions.ROTATE_CLOCKWISE.ToString());
            //outputGoAhead = World.NewExternalActionChunk(CreatureActions.GO_AHEAD.ToString());
            outputGoToClosestJewel = World.NewExternalActionChunk(CreatureActions.GO_TO_CLOSEST_JEWEL.ToString());
            outputGoToClosestFood  = World.NewExternalActionChunk(CreatureActions.GO_TO_CLOSEST_FOOD.ToString());
            outputEatFood          = World.NewExternalActionChunk(CreatureActions.EAT_FOOD.ToString());
            outputSackJewel        = World.NewExternalActionChunk(CreatureActions.SACK_JEWEL.ToString());
            outputDeliverLeaflet   = World.NewExternalActionChunk(CreatureActions.PREPARE_TO_DELIVER_LEAFLET.ToString());
            outputStop             = World.NewExternalActionChunk(CreatureActions.STOP.ToString());

            //Create thread to simulation
            runThread = new Thread(CognitiveCycle);
            Console.WriteLine("Agent started");
        }
Example #2
0
        public ClarionAgent(WSProxy nws, String creature_ID, String creature_Name)
        {
            worldServer = nws;
            // Initialize the agent
            CurrentAgent = World.NewAgent("Current Agent");
            mind         = new MindViewer();
            mind.Show();
            creatureId   = creature_ID;
            creatureName = creature_Name;

            // Initialize Input Information
            inputWallAhead  = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_WALL_AHEAD);
            inputFoodAhead  = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AHEAD);
            inputJewelAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_AHEAD);
            inputNeedJewel  = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_NEED_JEWEL);


            // Initialize Output actions
            outputRotateClockwise = World.NewExternalActionChunk(CreatureActions.ROTATE_CLOCKWISE.ToString());
            outputGoAhead         = World.NewExternalActionChunk(CreatureActions.GO_AHEAD.ToString());
            outputGetJewel        = World.NewExternalActionChunk(CreatureActions.GET_JEWEL.ToString());
            outputEatFood         = World.NewExternalActionChunk(CreatureActions.EAT_FOOD.ToString());
            outputGoToJewel       = World.NewExternalActionChunk(CreatureActions.GO_TO_JEWEL.ToString());

            //Create thread to simulation
            runThread = new Thread(CognitiveCycle);
            Console.WriteLine("Agent started");
        }
Example #3
0
        public MainClass()
        {
            Application.Init();
            Console.WriteLine("ClarionApp V0.8");
            try
            {
                ws = new WSProxy("localhost", 4011);

                String message = ws.Connect();

                if (ws != null && ws.IsConnected)
                {
                    Console.Out.WriteLine("[SUCCESS] " + message + "\n");
                    if (!GlobalVars.competitionMode)
                    {
                        // Only reset the environment if not on competition mode.
                        ws.SendWorldReset();
                    }
                    ws.NewCreature(400, 200, 0, out creatureId, out creatureName);

                    ws.SendCreateLeaflet();

                    // Create entities
                    CreateEntities();

                    if (!String.IsNullOrWhiteSpace(creatureId))
                    {
                        ws.SendStartCamera(creatureId);
                        ws.SendStartCreature(creatureId);
                    }

                    Console.Out.WriteLine("Creature created with name: " + creatureId + "\n");
                    agent = new ClarionAgent(ws, creatureId, creatureName);
                    agent.Run();
                    Console.Out.WriteLine("Running Simulation ...\n");
                }
                else
                {
                    Console.Out.WriteLine("The WorldServer3D engine was not found ! You must start WorldServer3D before running this application !");
                    System.Environment.Exit(1);
                }
            }
            catch (WorldServerInvalidArgument invalidArtgument)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message));
            }
            catch (WorldServerConnectionError serverError)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message));
            }
            Application.Run();
        }
Example #4
0
        public ClarionAgent(WSProxy nws, String creature_ID, String creature_Name, List <Leaflet> leafletList)
        {
            worldServer = nws;
            // Initialize the agent
            CurrentAgent = World.NewAgent("Current Agent");
            mind         = new MindViewer();
            mind.Show();
            creatureId   = creature_ID;
            creatureName = creature_Name;

            // Initialize Input Information
            inputWallCreatureAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_WALL_AHEAD);
            inputFoodAhead         = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AHEAD);
            inputJewelAhead        = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_AHEAD);
            inputJewelInVision     = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_IN_VISION);
            inputFuelLow           = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FUEL_LOW);

            // Initialize Output actions
            outputRotateClockwise   = World.NewExternalActionChunk(CreatureActions.ROTATE_CLOCKWISE.ToString());
            outputGoAhead           = World.NewExternalActionChunk(CreatureActions.GO_AHEAD.ToString());
            outputEatFood           = World.NewExternalActionChunk(CreatureActions.EAT_FOOD.ToString());
            outputGetJewel          = World.NewExternalActionChunk(CreatureActions.GET_JEWEL.ToString());
            outputHideJewel         = World.NewExternalActionChunk(CreatureActions.HIDE_JEWEL.ToString());
            outputGoalAchieved      = World.NewExternalActionChunk(CreatureActions.GOAL_ACHIEVED.ToString());
            outputGoToJewelInVision = World.NewExternalActionChunk(CreatureActions.GO_TO_JEWEL.ToString());
            outputFuelLow           = World.NewExternalActionChunk(CreatureActions.FUEL_LOW.ToString());

            //List<Thing> listThing = nws.SendGetCreatureState (creature_ID);

            //IList<Thing> response = null;

            //if (worldServer != null && worldServer.IsConnected) {
            //	response = worldServer.SendGetCreatureState (creatureName);
            //		Creature cc = (Creature)response [0];
            //		leaflet1.leafletID = cc.leaflets [0].leafletID;
            //		leaflet2.leafletID = cc.leaflets [1].leafletID;
            //		leaflet3.leafletID = cc.leaflets [2].leafletID;
            //		Console.WriteLine ("Creature found: " + cc.Name);
            //		Console.WriteLine ("LF1: " + cc.leaflets [0].leafletID);
            //		Console.WriteLine ("LF2: " + cc.leaflets [1].leafletID);
            //		Console.WriteLine ("LF3: " + cc.leaflets [2].leafletID);
            //}

            // Load leaflet control
            loadLeafletsControl(leafletList);
            mind.loadLeaflet(leafletList[0], leafletList[1], leafletList[2]);

            //Create thread to simulation
            runThread = new Thread(CognitiveCycle);
            //Console.WriteLine ("Agent started");
        }
Example #5
0
        public ClarionAgent(WSProxy nws, String creature_ID, String creature_Name)
        {
            worldServer = nws;
            // Initialize the agent
            CurrentAgent = World.NewAgent("Current Agent");
            mind         = new MindViewer();
            mind.Show();
            creatureId   = creature_ID;
            creatureName = creature_Name;

            // Initialize Input Information
            inputWallCreatureAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_WALL_AHEAD);
            inputFoodAhead         = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AHEAD);
            inputJewelAhead        = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_AHEAD);
            inputJewelInVision     = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_IN_VISION);

            // Initialize Output actions
            outputRotateClockwise   = World.NewExternalActionChunk(CreatureActions.ROTATE_CLOCKWISE.ToString());
            outputGoAhead           = World.NewExternalActionChunk(CreatureActions.GO_AHEAD.ToString());
            outputEatFood           = World.NewExternalActionChunk(CreatureActions.EAT_FOOD.ToString());
            outputGetJewel          = World.NewExternalActionChunk(CreatureActions.GET_JEWEL.ToString());
            outputHideJewel         = World.NewExternalActionChunk(CreatureActions.HIDE_JEWEL.ToString());
            outputGoalAchieved      = World.NewExternalActionChunk(CreatureActions.GOAL_ACHIEVED.ToString());
            outputGoToJewelInVision = World.NewExternalActionChunk(CreatureActions.GO_TO_JEWEL.ToString());

            /*List<Thing> thingList = nws.SendGetCreatureState (creature_ID);
             * foreach(Thing t in thingList) {
             *      Console.WriteLine ("Thing: ");
             *      Console.Write (t);
             * }*/



            // Define jewels out of scope
            jewelOutOfScope.Add("Orange");
            jewelOutOfScope.Add("DarkGray_Spoiled");

            //Create thread to simulation
            runThread = new Thread(CognitiveCycle);
            Console.WriteLine("Agent started");
        }
Example #6
0
        // To indicate we are done.
        //Boolean allJewelsCollected = false;
        //Boolean reachedDeliverySpot = false;
        #endregion

        #region Constructor
        public ClarionAgent(WSProxy nws, String creature_ID, String creature_Name)
        {
            worldServer = nws;
            // Initialize the agent
            CurrentAgent = World.NewAgent("Current Agent");
            mind         = new MindViewer();
            mind.Show();
            creatureId   = creature_ID;
            creatureName = creature_Name;

            // Create a (fake) delivery spot.
            // It seems WSProxy.cs does not support it, so place it at (0,0).
            deliverySpot    = new Thing();
            deliverySpot.X1 = 0;
            deliverySpot.Y1 = 0;

            // Initialize Input Information
            inputWallAhead          = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_WALL_AHEAD);
            inputJewelAhead         = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_AHEAD);
            inputFoodAhead          = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AHEAD);
            inputJewelAway          = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_JEWEL_AWAY);
            inputFoodAway           = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AWAY);
            inputAllJewelsCollected = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_ALL_JEWELS_COLLECTED);
            inputCreatureCanDeliver = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_CREATURE_CAN_DELIVER);

            // Initialize Output actions
            outputRotateClockwise  = World.NewExternalActionChunk(CreatureActions.ROTATE_CLOCKWISE.ToString());
            outputGetJewel         = World.NewExternalActionChunk(CreatureActions.GET_JEWEL.ToString());
            outputGetFood          = World.NewExternalActionChunk(CreatureActions.GET_FOOD.ToString());
            outputGoToJewel        = World.NewExternalActionChunk(CreatureActions.GO_TO_JEWEL.ToString());
            outputGoToFood         = World.NewExternalActionChunk(CreatureActions.GO_TO_FOOD.ToString());
            outputWander           = World.NewExternalActionChunk(CreatureActions.WANDER.ToString());
            outputGoToDeliverySpot = World.NewExternalActionChunk(CreatureActions.GO_TO_DELIVER.ToString());
            outputDoDelivery       = World.NewExternalActionChunk(CreatureActions.DELIVER.ToString());

            //Create thread to simulation
            runThread = new Thread(CognitiveCycle);
            Console.WriteLine("Agent started");
        }
Example #7
0
        public MainClass()
        {
            Application.Init();
            Console.WriteLine("ClarionApp V0.8");

            RandomGenerator rg        = new RandomGenerator();
            int             ws_width  = 800;
            int             ws_lenght = 600;

            try
            {
                ws = new WSProxy("localhost", 4011);

                String message = ws.Connect();


                if (ws != null && ws.IsConnected)
                {
                    Console.Out.WriteLine("[SUCCESS] " + message + "\n");
                    //ws.SendWorldReset();
                    ws.NewCreature(400, 200, 0, out creatureId, out creatureName);
                    ws.SendCreateLeaflet();

                    ws.NewBrick(4, 0, 0, -50, ws_lenght + 50);
                    ws.NewBrick(4, 0, ws_lenght, ws_width + 50, ws_lenght + 50);
                    ws.NewBrick(4, ws_width, ws_lenght, ws_width + 50, -50);
                    ws.NewBrick(4, ws_width, 0, -50, -50);

                    //while (true) {
                    int nu_of_jewels = 15;
                    for (int i = 0; i < nu_of_jewels; i++)
                    {
                        ws.NewJewel(rg.randomInt(0, 6), rg.randomInt(0, ws_width), rg.randomInt(0, ws_lenght));
                    }

                    int nu_of_foods = 8;
                    for (int i = 0; i < nu_of_foods; i++)
                    {
                        ws.NewFood(rg.randomInt(0, 2), rg.randomInt(0, ws_width), rg.randomInt(0, ws_lenght));
                    }
                    //Thread.Sleep(10000);
                    //}

                    if (!String.IsNullOrWhiteSpace(creatureId))
                    {
                        ws.SendStartCamera(creatureId);
                        ws.SendStartCreature(creatureId);
                    }

                    Console.Out.WriteLine("Creature created with name: " + creatureId + "\n");
                    agent = new ClarionAgent(ws, creatureId, creatureName);
                    agent.Run();
                    Console.Out.WriteLine("Running Simulation ...\n");
                }
                else
                {
                    Console.Out.WriteLine("The WorldServer3D engine was not found ! You must start WorldServer3D before running this application !");
                    System.Environment.Exit(1);
                }
            }
            catch (WorldServerInvalidArgument invalidArtgument)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message));
            }
            catch (WorldServerConnectionError serverError)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message));
            }
            Application.Run();
        }
Example #8
0
        public MainClass(string [] args)
        {
            Application.Init();
            Console.WriteLine("IA941 - Clarion - Activity");
            try {
                ws = new WSProxy("localhost", 4011);

                String message = ws.Connect();

                if (ws != null && ws.IsConnected)
                {
                    Console.Out.WriteLine("[SUCCESS] " + message + "\n");
                    if (args.Length > 1)
                    {
                        if (args [1] == "reset")
                        {
                            ws.SendWorldReset();
                        }
                    }
                    else
                    {
                        ws.SendWorldReset();
                    }

                    ws.NewCreature(100, 500, 0, out creatureId, out creatureName);

                    // Start >>> Leaflet process preparation //
                    String    leaflets_raw = ws.SendCreateLeaflet();
                    string [] leaflets_arr = leaflets_raw.Split(' ');
                    //Console.WriteLine ("Leaflets: " + leaflets_raw);

                    Leaflet leaflet1 = new Leaflet();
                    leaflet1.items = new List <LeafletItem> ();
                    Leaflet leaflet2 = new Leaflet();
                    leaflet2.items = new List <LeafletItem> ();
                    Leaflet leaflet3 = new Leaflet();
                    leaflet3.items = new List <LeafletItem> ();

                    int leafNum = 1;
                    int lf1T    = 0;
                    int lf2T    = 0;
                    int lf3T    = 0;
                    for (int i = 0; i < leaflets_arr.Length; i++)
                    {
                        if (leaflets_arr [i] != "")
                        {
                            if (leaflets_arr [i] == "false")
                            {
                                leafNum++;
                            }
                            else if (leaflets_arr [i].Length > 3)
                            {
                                switch (leafNum)
                                {
                                case 1:
                                    leaflet1.items.Add(new LeafletItem(leaflets_arr [i], Int32.Parse(leaflets_arr [i + 2]), 0));
                                    lf1T = lf1T + Int32.Parse(leaflets_arr [i + 2]);
                                    i    = i + 2;
                                    break;

                                case 2:
                                    leaflet2.items.Add(new LeafletItem(leaflets_arr [i], Int32.Parse(leaflets_arr [i + 2]), 0));
                                    lf2T = lf2T + Int32.Parse(leaflets_arr [i + 2]);
                                    i    = i + 2;
                                    break;

                                case 3:
                                    leaflet3.items.Add(new LeafletItem(leaflets_arr [i], Int32.Parse(leaflets_arr [i + 2]), 0));
                                    lf3T = lf3T + Int32.Parse(leaflets_arr [i + 2]);
                                    i    = i + 2;
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }

                    //Console.WriteLine ("Leaflet 1 items: ");
                    //foreach(LeafletItem lt in leaflet1.items) {
                    //	Console.WriteLine ("Jewel: " + lt.itemKey);
                    //	Console.WriteLine ("Total: " + lt.totalNumber);

                    //}

                    //Console.WriteLine ("Leaflet 2 items: ");
                    //foreach (LeafletItem lt in leaflet2.items) {
                    //	Console.WriteLine ("Jewel: " + lt.itemKey);
                    //	Console.WriteLine ("Total: " + lt.totalNumber);

                    //}

                    //Console.WriteLine ("Leaflet 3 items: ");
                    //foreach (LeafletItem lt in leaflet3.items) {
                    //	Console.WriteLine ("Jewel: " + lt.itemKey);
                    //	Console.WriteLine ("Total: " + lt.totalNumber);

                    //}

                    // In case the leaflets sum have less than 9 jewels, then add remaining
                    int remJewels = 9 - (lf1T + lf2T + lf3T);
                    //Console.WriteLine ("Rem Jewels: " + remJewels);
                    //Console.WriteLine ("count lf1: " + leaflet1.items.Count);
                    if (remJewels > 0)
                    {
                        for (int i = 0; i < remJewels; i++)
                        {
                            if (lf1T < 3)
                            {
                                leaflet1.items.Add(new LeafletItem("Red", 1, 0));
                                lf1T++;
                                //Console.WriteLine ("Added rem Jewel - Leaflet 1");
                            }
                            else if (lf2T < 3)
                            {
                                leaflet2.items.Add(new LeafletItem("Red", 1, 0));
                                lf2T++;
                                //Console.WriteLine ("Added rem Jewel - Leaflet 2");
                            }
                            else if (lf3T < 3)
                            {
                                leaflet3.items.Add(new LeafletItem("Red", 1, 0));
                                lf3T++;
                                //Console.WriteLine ("Added rem Jewel - Leaflet 3");
                            }
                        }
                    }
                    //Console.WriteLine ("Double check: ");
                    //Console.WriteLine ("Leaflet 1 items: ");
                    //foreach (LeafletItem lt in leaflet1.items) {
                    //	Console.WriteLine ("Jewel: " + lt.itemKey);
                    //	Console.WriteLine ("Total: " + lt.totalNumber);

                    //}

                    //Console.WriteLine ("Leaflet 2 items: ");
                    //foreach (LeafletItem lt in leaflet2.items) {
                    //	Console.WriteLine ("Jewel: " + lt.itemKey);
                    //	Console.WriteLine ("Total: " + lt.totalNumber);

                    //}

                    //Console.WriteLine ("Leaflet 3 items: ");
                    //foreach (LeafletItem lt in leaflet3.items) {
                    //	Console.WriteLine ("Jewel: " + lt.itemKey);
                    //	Console.WriteLine ("Total: " + lt.totalNumber);

                    //}
                    // End >>> Leaflet process preparation //

                    ws.SendNewWayPoint(700, 500);
                    if (args.Length > 1)
                    {
                        if (args [3] == "grow")
                        {
                            //ws.NewBrick (4, 747, 2, 800, 567);
                            //ws.NewBrick (4, 50, -4, 747, 47);
                            //ws.NewBrick (4, 49, 562, 796, 599);
                            //ws.NewBrick (4, -2, 6, 50, 599);

                            Random x    = new Random();
                            Random y    = new Random();
                            Random z    = new Random();
                            int    minX = 100;
                            int    maxX = 600;
                            int    minY = 100;
                            int    maxY = 500;
                            int    xNew = 0;
                            int    yNew = 0;

                            // Random Jewels
                            for (int j = 0; j < 7; j++)
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    xNew = x.Next(minX, maxX);
                                    yNew = y.Next(minY, maxY);
                                    if (((mod(xNew, 100) < 50) && (mod(yNew, 100) < 50)) || ((mod(xNew, 100) < 50) && (mod(yNew, 500) < 50)))
                                    {
                                        x.Next(minX + z.Next(1, 50), maxX);
                                        if (i > 0)
                                        {
                                            i--;
                                        }
                                    }
                                    else
                                    {
                                        ws.NewJewel(j, xNew, yNew);
                                        x.Next(minX + z.Next(1, 50), maxX);
                                    }
                                }
                            }

                            // Random food
                            for (int j = 0; j < 2; j++)
                            {
                                for (int i = 0; i < 2; i++)
                                {
                                    xNew = x.Next(minX, maxX);
                                    yNew = y.Next(minY, maxY);
                                    if (!(((xNew > 60) && (xNew < 140)) || (((xNew > 360) && (xNew < 440)))))
                                    {
                                        ws.NewFood(j, xNew, yNew);
                                        x.Next(minX + i, maxX);
                                    }
                                    else
                                    {
                                        x.Next(minX + i, maxX);
                                        if (i > 0)
                                        {
                                            i--;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //ws.NewBrick (4, 747, 2, 800, 567);
                        //ws.NewBrick (4, 50, -4, 747, 47);
                        //ws.NewBrick (4, 49, 562, 796, 599);
                        //ws.NewBrick (4, -2, 6, 50, 599);

                        Random x    = new Random();
                        Random y    = new Random();
                        Random z    = new Random();
                        int    minX = 100;
                        int    maxX = 600;
                        int    minY = 100;
                        int    maxY = 500;
                        int    xNew = 0;
                        int    yNew = 0;

                        // Random Jewels
                        for (int j = 0; j < 7; j++)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                xNew = x.Next(minX, maxX);
                                yNew = y.Next(minY, maxY);
                                if (((mod(xNew, 100) < 50) && (mod(yNew, 100) < 50)) || ((mod(xNew, 100) < 50) && (mod(yNew, 500) < 50)))
                                {
                                    x.Next(minX + z.Next(1, 50), maxX);
                                    if (i > 0)
                                    {
                                        i--;
                                    }
                                }
                                else
                                {
                                    ws.NewJewel(j, xNew, yNew);
                                    x.Next(minX + z.Next(1, 50), maxX);
                                }
                            }
                        }

                        // Random food
                        for (int j = 0; j < 2; j++)
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                xNew = x.Next(minX, maxX);
                                yNew = y.Next(minY, maxY);
                                if (!(((xNew > 60) && (xNew < 140)) || (((xNew > 360) && (xNew < 440)))))
                                {
                                    ws.NewFood(j, xNew, yNew);
                                    x.Next(minX + i, maxX);
                                }
                                else
                                {
                                    x.Next(minX + i, maxX);
                                    if (i > 0)
                                    {
                                        i--;
                                    }
                                }
                            }
                        }
                    }


                    // ---- Start - Leaflet Generation --- //
                    IList <Thing> response = null;
                    if (ws != null && ws.IsConnected)
                    {
                        response = ws.SendGetCreatureState(creatureName);
                        if (leaflet1.leafletID == 0 && leaflet2.leafletID == 0 && leaflet3.leafletID == 0)
                        {
                            Creature cc = (Creature)response [0];
                            //leaflet1.leafletID = cc.leaflets [0].leafletID;
                            //leaflet2.leafletID = cc.leaflets [1].leafletID;
                            //leaflet3.leafletID = cc.leaflets [2].leafletID;
                            leaflet1 = cc.leaflets [0];
                            leaflet2 = cc.leaflets [1];
                            leaflet3 = cc.leaflets [2];
                            //Console.WriteLine ("Creature found: " + cc.Name);
                            //Console.WriteLine ("LF1: " + cc.leaflets [0].leafletID);
                            //Console.WriteLine ("LF2: " + cc.leaflets [1].leafletID);
                            //Console.WriteLine ("LF3: " + cc.leaflets [2].leafletID);
                        }
                    }
                    List <Leaflet> leafletList = new List <Leaflet> ();
                    leafletList.Add(leaflet1);
                    leafletList.Add(leaflet2);
                    leafletList.Add(leaflet3);
                    // ---- Finish - Leaflet generation --- //



                    if (!String.IsNullOrWhiteSpace(creatureId))
                    {
                        ws.SendStartCamera(creatureId);
                        ws.SendStartCreature(creatureId);
                    }

                    if (args.Length > 0)
                    {
                        Console.Out.WriteLine("Sleep time: " + Convert.ToInt32(args [0]));
                        Thread.Sleep(Convert.ToInt32(args [0]));
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }

                    Console.Out.WriteLine("Creature created with name: " + creatureId + "\n");
                    agent = new ClarionAgent(ws, creatureId, creatureName, leafletList);
                    agent.Run();
                    Console.Out.WriteLine("Running Simulation ...\n");
                }
                else
                {
                    Console.Out.WriteLine("The WorldServer3D engine was not found ! You must start WorldServer3D before running this application !");
                    System.Environment.Exit(1);
                }
            } catch (WorldServerInvalidArgument invalidArtgument) {
                Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message));
            } catch (WorldServerConnectionError serverError) {
                Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message));
            } catch (Exception ex) {
                Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message));
            }
            Application.Run();
        }
Example #9
0
        public MainClass(string[] args)
        {
            Application.Init();
            Console.WriteLine("IA941 - Clarion - Activity");
            try
            {
                ws = new WSProxy("localhost", 4011);

                String message = ws.Connect();

                if (ws != null && ws.IsConnected)
                {
                    Console.Out.WriteLine("[SUCCESS] " + message + "\n");
                    if (args.Length > 1)
                    {
                        if (args[1] == "reset")
                        {
                            ws.SendWorldReset();
                        }
                    }
                    else
                    {
                        ws.SendWorldReset();
                    }

                    ws.NewCreature(100, 500, 0, out creatureId, out creatureName);
                    //Console.WriteLine ("SendCreateLeaflet: ");
                    //ws.SendCreateLeaflet();
                    //ws.SendNewWayPoint (700, 500);

                    if (args.Length > 1)
                    {
                        if (args[3] == "grow")
                        {
                            //ws.NewBrick(4, 747, 2, 800, 567);
                            //ws.NewBrick(4, 50, -4, 747, 47);
                            //ws.NewBrick(4, 49, 562, 796, 599);
                            //ws.NewBrick(4, -2, 6, 50, 599);

                            Random x    = new Random();
                            Random y    = new Random();
                            Random z    = new Random();
                            int    minX = 100;
                            int    maxX = 600;
                            int    minY = 100;
                            int    maxY = 500;
                            int    xNew = 0;
                            int    yNew = 0;

                            // Random Jewels
                            for (int j = 0; j < 7; j++)
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    xNew = x.Next(minX, maxX);
                                    yNew = y.Next(minY, maxY);
                                    if (((mod(xNew, 100) < 50) && (mod(yNew, 100) < 50)) || ((mod(xNew, 100) < 50) && (mod(yNew, 500) < 50)))
                                    {
                                        x.Next(minX + z.Next(1, 50), maxX);
                                        if (i > 0)
                                        {
                                            i--;
                                        }
                                    }
                                    else
                                    {
                                        ws.NewJewel(j, xNew, yNew);
                                        x.Next(minX + z.Next(1, 50), maxX);
                                    }
                                }
                            }

                            // Random food
                            for (int j = 0; j < 2; j++)
                            {
                                for (int i = 0; i < 2; i++)
                                {
                                    xNew = x.Next(minX, maxX);
                                    yNew = y.Next(minY, maxY);
                                    if (!(((xNew > 60) && (xNew < 140)) || (((xNew > 360) && (xNew < 440)))))
                                    {
                                        ws.NewFood(j, xNew, yNew);
                                        x.Next(minX + i, maxX);
                                    }
                                    else
                                    {
                                        x.Next(minX + i, maxX);
                                        if (i > 0)
                                        {
                                            i--;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //ws.NewBrick(4, 747, 2, 800, 567);
                        //ws.NewBrick(4, 50, -4, 747, 47);
                        //ws.NewBrick(4, 49, 562, 796, 599);
                        //ws.NewBrick(4, -2, 6, 50, 599);

                        Random x    = new Random();
                        Random y    = new Random();
                        Random z    = new Random();
                        int    minX = 100;
                        int    maxX = 600;
                        int    minY = 100;
                        int    maxY = 500;
                        int    xNew = 0;
                        int    yNew = 0;

                        // Random Jewels
                        for (int j = 0; j < 7; j++)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                xNew = x.Next(minX, maxX);
                                yNew = y.Next(minY, maxY);
                                if (((mod(xNew, 100) < 50) && (mod(yNew, 100) < 50)) || ((mod(xNew, 100) < 50) && (mod(yNew, 500) < 50)))
                                {
                                    x.Next(minX + z.Next(1, 50), maxX);
                                    if (i > 0)
                                    {
                                        i--;
                                    }
                                }
                                else
                                {
                                    ws.NewJewel(j, xNew, yNew);
                                    x.Next(minX + z.Next(1, 50), maxX);
                                }
                            }
                        }

                        // Random food
                        for (int j = 0; j < 2; j++)
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                xNew = x.Next(minX, maxX);
                                yNew = y.Next(minY, maxY);
                                if (!(((xNew > 60) && (xNew < 140)) || (((xNew > 360) && (xNew < 440)))))
                                {
                                    ws.NewFood(j, xNew, yNew);
                                    x.Next(minX + i, maxX);
                                }
                                else
                                {
                                    x.Next(minX + i, maxX);
                                    if (i > 0)
                                    {
                                        i--;
                                    }
                                }
                            }
                        }
                    }
                    if (!String.IsNullOrWhiteSpace(creatureId))
                    {
                        ws.SendStartCamera(creatureId);
                        ws.SendStartCreature(creatureId);
                    }

                    if (args.Length > 0)
                    {
                        Console.Out.WriteLine("Sleep time: " + Convert.ToInt32(args[0]));
                        Thread.Sleep(Convert.ToInt32(args[0]));
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }

                    Console.Out.WriteLine("Creature created with name: " + creatureId + "\n");
                    agent = new ClarionAgent(ws, creatureId, creatureName);
                    agent.Run();
                    Console.Out.WriteLine("Running Simulation ...\n");
                }
                else
                {
                    Console.Out.WriteLine("The WorldServer3D engine was not found ! You must start WorldServer3D before running this application !");
                    System.Environment.Exit(1);
                }
            }
            catch (WorldServerInvalidArgument invalidArtgument)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message));
            }
            catch (WorldServerConnectionError serverError)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message));
            }
            Application.Run();
        }
Example #10
0
        public MainClass()
        {
            Application.Init();
            Console.WriteLine("ClarionApp V0.8");
            try
            {
                ws = new WSProxy("localhost", 4011);

                String message = ws.Connect();

                if (ws != null && ws.IsConnected)
                {
                    Console.Out.WriteLine("[SUCCESS] " + message + "\n");
                    if (!skipReset)
                    {
                        ws.SendWorldReset();
                        ws.NewBrick(4, 747, 2, 800, 567);
                        ws.NewBrick(4, 50, -4, 747, 47);
                        ws.NewBrick(4, 49, 562, 796, 599);
                        ws.NewBrick(4, -2, 6, 50, 599);

                        // Create some food
                        ws.NewFood(0, 415, 212);
                        ws.NewFood(0, 237, 321);
                        ws.NewFood(0, 165, 440);

                        // Create 9 jewels of each color, to enable easy planning
                        ws.NewJewel(0, 200, 200);
                        ws.NewJewel(0, 200, 220);
                        ws.NewJewel(0, 200, 440);
                        ws.NewJewel(0, 420, 100);
                        ws.NewJewel(0, 420, 220);
                        ws.NewJewel(0, 420, 440);
                        ws.NewJewel(0, 640, 100);
                        ws.NewJewel(0, 640, 220);
                        ws.NewJewel(0, 640, 440);
                        ws.NewJewel(1, 200, 200);
                        ws.NewJewel(1, 140, 340);
                        ws.NewJewel(1, 140, 500);
                        ws.NewJewel(1, 340, 220);
                        ws.NewJewel(1, 340, 340);
                        ws.NewJewel(1, 340, 500);
                        ws.NewJewel(1, 600, 140);
                        ws.NewJewel(1, 600, 340);
                        ws.NewJewel(1, 600, 500);
                        ws.NewJewel(2, 250, 170);
                        ws.NewJewel(2, 250, 240);
                        ws.NewJewel(2, 250, 400);
                        ws.NewJewel(2, 440, 170);
                        ws.NewJewel(2, 440, 240);
                        ws.NewJewel(2, 440, 400);
                        ws.NewJewel(2, 530, 170);
                        ws.NewJewel(2, 530, 240);
                        ws.NewJewel(2, 530, 400);

                        ws.NewJewel(3, 260, 100);
                        ws.NewJewel(3, 260, 220);
                        ws.NewJewel(3, 260, 440);
                        ws.NewJewel(3, 500, 100);
                        ws.NewJewel(3, 500, 220);
                        ws.NewJewel(3, 480, 440);
                        ws.NewJewel(3, 700, 100);
                        ws.NewJewel(3, 700, 220);
                        ws.NewJewel(3, 700, 440);
                        ws.NewJewel(4, 200, 140);
                        ws.NewJewel(4, 200, 340);
                        ws.NewJewel(4, 200, 500);
                        ws.NewJewel(4, 400, 220);
                        ws.NewJewel(4, 400, 340);
                        ws.NewJewel(4, 400, 500);
                        ws.NewJewel(4, 660, 140);
                        ws.NewJewel(4, 660, 340);
                        ws.NewJewel(4, 660, 500);
                        ws.NewJewel(5, 310, 170);
                        ws.NewJewel(5, 310, 240);
                        ws.NewJewel(5, 310, 400);
                        ws.NewJewel(5, 500, 170);
                        ws.NewJewel(5, 500, 240);
                        ws.NewJewel(5, 500, 400);
                        ws.NewJewel(5, 590, 170);
                        ws.NewJewel(5, 590, 240);
                        ws.NewJewel(5, 590, 400);
                    }
                    ws.NewCreature(100, 100, 0, out creatureId, out creatureName);
                    ws.SendCreateLeaflet();

                    if (!String.IsNullOrWhiteSpace(creatureId))
                    {
                        ws.SendStartCamera(creatureId);
                        ws.SendStartCreature(creatureId);
                    }

                    Console.Out.WriteLine("Creature created with name: " + creatureId + "\n");
                    agent = new ClarionAgent(ws, creatureId, creatureName);
                    agent.Run();
                    Console.Out.WriteLine("Running Simulation ...\n");
                }
                else
                {
                    Console.Out.WriteLine("The WorldServer3D engine was not found ! You must start WorldServer3D before running this application !");
                    System.Environment.Exit(1);
                }
            }
            catch (WorldServerInvalidArgument invalidArtgument)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message));
            }
            catch (WorldServerConnectionError serverError)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message));
            }
            Application.Run();
        }