Exemplo n.º 1
0
 public void RemoveRack(Point point)
 {
     point.AddRack(this.rack);
     this._rack.AssignPoint(point);
     this._rack = null;
 }
Exemplo n.º 2
0
 public RobotPickupRack(Rack r)
 {
     this.rack = r;
 }
Exemplo n.º 3
0
 public void RemoveRack(Truck truck)
 {
     truck.AddRack(this.rack);
     this._rack = null;
 }
Exemplo n.º 4
0
        // Hier worden de graph, de truck, de robots en de rekjes neergezet
        public World()
        {
            Point a = new Point(-20, 0, 0);
            Point b = new Point(-10, 0, 0);
            Point c = new Point(-10, 0, 10);
            Point d = new Point(0, 0, 10);
            Point e = new Point(10, 0, 10);
            Point f = new Point(10, 0, 0);
            Point g = new Point(10, 0, -10);
            Point h = new Point(0, 0, -10);
            Point i = new Point(-10, 0, -10);
            Point j = new Point(0, 0, 0);

            Point tA = new Point(-20, 0, -50);
            Point tB = new Point(-20, 0, 0);
            Point tC = new Point(-20, 0, 50);

            a.AddNode(b);
            b.AddNode(new List <Point>()
            {
                c, i
            });
            c.AddNode(d);
            d.AddNode(new List <Point>()
            {
                e, j
            });
            e.AddNode(f);
            f.AddNode(g);
            h.AddNode(new List <Point>()
            {
                i, j, g
            });

            tB.AddNode(new List <Point>()
            {
                tA, tB
            });

            List <Point> pointList = new List <Point>()
            {
                a, b, c, d, e, f, g, h, i, j
            };

            pointGraph = new Graph((pointList));

            truckGraph = new Graph(new List <Point>()
            {
                tA, tB, tC
            });

            Robot robot1 = CreateRobot(a);
            Robot robot2 = CreateRobot(a);
            Robot robot3 = CreateRobot(a);

            Rack rack1 = CreateRack(e);
            Rack rack2 = CreateRack(i);
            Rack rack3 = CreateRack(j);
            Rack rack4 = CreateRack(g);
            Rack rack5 = CreateRack(b);
            Rack rack6 = CreateRack(c);

            Truck t = CreateTruck(tA);

            robot1.AddTask(new RobotMove(pointGraph, rack1.point));
            robot2.AddTask(new RobotMove(pointGraph, rack2.point));
            robot3.AddTask(new RobotMove(pointGraph, rack3.point));

            int counter = 3;

            foreach (Model3D r in worldObjects)
            {
                if (r is Robot)
                {
                    ((Robot)r).AddTask(new RobotPickUp());
                    ((Robot)r).AddTask(new RobotMove(pointGraph, a));
                    ((Robot)r).AddTask(new RobotDropOff(t));
                    ((Robot)r).AddTask(new RobotPickUp());
                    ((Robot)r).AddTask(new RobotMove(pointGraph, pointList[counter]));
                    ((Robot)r).AddTask(new RobotDropOff(pointList[counter]));
                    counter++;
                    ((Robot)r).AddTask(new RobotMove(pointGraph, a));
                }
            }
            t.AddTask(new TruckMove(tB));
            t.AddTask(new TruckLoad());
            t.AddTask(new TruckMove(tC));
            t.AddTask(new TruckTeleport(tA));
            t.AddTask(new TruckMove(tB));
            t.AddTask(new TruckDump(a));
            t.AddTask(new TruckMove(tC));
        }
Exemplo n.º 5
0
 public void AddRack(Rack rack)
 {
     _racks.Add(rack);
     rack.AssignPoint(null);
     rack.Move(this.x, this.y + 0.2m, this.z);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Set rack to robot
 /// </summary>
 /// <param name="rack"></param>
 public void PickupRack(Rack rack)
 {
     currentRack = rack;
 }
Exemplo n.º 7
0
        public bool Update(int tick)
        {
            for (int i = worldObjects.Count - 1; i >= 0; i--)
            {
                if (worldObjects[i] is IUpdatable)
                {
                    bool needsCommand = ((IUpdatable)worldObjects[i]).Update(tick);

                    if (needsCommand)
                    {
                        if (worldObjects[i] is Robot)
                        {
                            Robot r = (Robot)worldObjects[i];

                            // Gives Robot new tasks if possible and needed
                            if (r.currentNode == homeNode && r.currentRack == null && r.tasks.Count == 0)
                            {
                                if (storedRacks.Count >= 25) // Search for rack and place it at the home node
                                {
                                    int  randomRackInt      = 0;
                                    Rack randomRack         = null;
                                    int  randomRackNodeName = 0;

                                    bool checkRack = false;
                                    // Select a random rack
                                    while (!checkRack)
                                    {
                                        randomRackInt      = random.Next(storedRacks.Count);
                                        randomRack         = storedRacks[randomRackInt];
                                        randomRackNodeName = Convert.ToInt32(randomRack.currentNode.NodeName);

                                        if (randomRackNodeName != Convert.ToInt32(this.homeNode.NodeName))
                                        {
                                            checkRack = true;
                                        }
                                    }

                                    rackPlacedList[randomRackNodeName] = false;

                                    // Ride robot to position, pickup rack and drop at homenode
                                    r.AddTask(new RobotMove(this.dijkstra.GetBestRoute(r.currentNode, randomRack.currentNode).ToArray()));
                                    r.AddTask(new RobotPickupRack(randomRack));
                                    r.AddTask(new RobotMove(this.dijkstra.GetBestRoute(randomRack.currentNode, this.homeNode).ToArray()));
                                    r.AddTask(new RobotDropRack());

                                    randomRack.currentNode.busy = true;
                                    emptyRacks.Add(randomRack);
                                    storedRacks.RemoveAt(storedRacks.IndexOf(randomRack));
                                }
                                else if (newRacks.Count > 0)    // Pickup rack, drop in storage and return
                                {
                                    Node placeRackNode = null;
                                    for (int count = 0; count < nodeList.Count; count++)    // Get avaible place in storage
                                    {
                                        if (rackPlacedList[count] == false)
                                        {
                                            placeRackNode = nodeList[count];
                                            if (!placeRackNode.busy)
                                            {
                                                rackPlacedList[count] = true;
                                                count = nodeList.Count;
                                            }
                                        }
                                    }

                                    if (placeRackNode != null)
                                    {
                                        // Pickup rack, Ride robot to position and drop rack
                                        r.AddTask(new RobotPickupRack(newRacks[0]));
                                        r.AddTask(new RobotMove(this.dijkstra.GetBestRoute(r.currentNode, placeRackNode).ToArray()));
                                        r.AddTask(new RobotDropRack());
                                        r.AddTask(new RobotMove(this.dijkstra.GetBestRoute(placeRackNode, this.homeNode).ToArray()));

                                        // Update storage
                                        storedRacks.Add(newRacks[0]);
                                        newRacks.RemoveAt(0);
                                    }
                                }
                            }
                        }
                        else if (worldObjects[i] is Transport)
                        {
                            Transport t = (Transport)worldObjects[i];
                            t.UpdatePosition();

                            // Transport reached loader
                            if (t.reachedLoader)
                            {
                                // Clear all empty racks
                                foreach (Rack r in emptyRacks)
                                {
                                    if (r.currentNode == this.homeNode && r.delete != true)
                                    {
                                        r.delete      = true;
                                        r.needsUpdate = true;
                                    }
                                }

                                if (!t.createdRacks)
                                {
                                    t.createdRacks = true;

                                    int generatedRacks = 0;
                                    // Generates random count of racks to be placed in storage
                                    if (storedRacks.Count <= 25)
                                    {
                                        generatedRacks = random.Next(3, 5);
                                    }
                                    else
                                    {
                                        generatedRacks = 0;
                                    }

                                    // Spaw new racks when truck has reached the loader
                                    for (int a = generatedRacks; a > 0; a--)
                                    {
                                        newRacks.Add(CreateRack(homeNode.x + 1, homeNode.y + 0.2, homeNode.z, homeNode));
                                    }
                                    Console.Write("Stored racks: " + storedRacks.Count);
                                    Console.WriteLine(" New racks: " + newRacks.Count);
                                }
                            }
                        }

                        // Send Model through socket
                        SendCommandToObservers(new UpdateModel3DCommand(worldObjects[i]));

                        // Remove object from worldobjects
                        if (worldObjects[i].delete == true)
                        {
                            worldObjects.RemoveAt(i);
                        }
                    }
                }
            }

            return(true);
        }