private Rek CreateRek(double x, double y, double z) { Rek rek = new Rek(x, y, z, 0, 0, 0); worldObjects.Add(rek); return(rek); }
public Storage(Node n, double x, double y, double z, World currentworld) { DropoffNode = n; position_x = x; position_y = y; position_z = z; this.w = currentworld; // Have the Storage element start off with a random number of Rek's Random r = new Random(); int q = r.Next(1, 5); x_size = 25; z_size = 5; for (int i = 0; i < q; i++) { Rek newrek = new Rek((i * 2.5) + position_x, 0, position_z + 2.5, 0, 0, 0); newrek.readyforpickup = false; // If i have spare time later, edit this to give it a random position in the list/ array Stored.Add(newrek); } RenderRekken(); }
/*public void AddRek(Rek r) * { * r.readyforpickup = false; * for (int i = 0; i < Stored.Count; i++) * { * if (Stored[i] == null) * { * Stored[i] = r; * r.Move((i * 2.5) + position_x, 0, position_z + 2.5); * } * } * }*/ public void AddRek(Rek r) { r.readyforpickup = false; Stored.Add(r); r.Move((Stored.Count * 2.5) + position_x, 0, position_z + 2.5); }
/// <summary> /// Storage area to store barrels /// </summary> /// <param name="n">The node the robot ahs to reach to drop off it's load. </param> /// <param name="x_size">Horizontal size</param> /// <param name="z_size">Vertical size</param> /// <param name="x_position">position</param> /// <param name="y_position">position</param> /// <param name="z_position">position</param> /// <param name="currentworld">A reference to the current world object</param> public Storage(Node n, double x_size, double z_size, double x_position, double y_position, double z_position, World currentworld) { DropoffNode = n; position_x = x_position; position_y = y_position; position_z = z_position; this.x_size = x_size; this.z_size = z_size; Max_Barrels = Convert.ToInt64(Math.Floor(x_size / 2.5)); this.w = currentworld; // Have the Storage element start off with a random number of Rek's Random r = new Random(); int q = r.Next(1, 3); for (int i = 0; i < q; i++) { Rek newrek = new Rek((i * 1.5) + position_x, 0, position_z + 2.5, 0, 0, 0); newrek.readyforpickup = false; // If i have spare time later, edit this to give it a random position in the list/ array Stored.Add(newrek); } RenderRekken(); }
int AtLoadingDock() { Rek cargo = this.Unload(); this.CarriedRek = null; this._world.TrainArrived(this, cargo); this._state = TreiState.AT_LOADING_DOCK; return(0); }
/// <summary> ///Tell the robot to pick up a specific Rek /// </summary> public void PickupRek(Rek k) { if (k.readyforpickup == true) { carriedRek = k; // carriedRek.Move(this.x+30, this.y+30, this.z); } else { Console.WriteLine("Tried to pickup unready Rek"); } }
/// <summary> /// Accept a Rek from a robot, and store it /// </summary> /// <param name="r">rek to be stored</param> public void AddRek(Rek r) { r.readyforpickup = false; for (int i = 0; i < 10; i++) { if (Stored.ElementAtOrDefault(i) == null) { r.Move((i * 1.5) + position_x, 0, position_z + 2.5); Stored.Add(r); return; } } }
/// <summary> /// Gets called when the robot reaches it's destination /// </summary> public void DropOffRek(Node DropOffAt) { // Check if the robot is actually carrying a Rek if (carriedRek != null) { // Loop over all the storagespots, find the matching spot for (int i = 0; i < w.StorageSpots.Count; i++) { if (DropOffAt == w.StorageSpots[i].DropoffNode) { // Spot matches. Check if the spot isnt full by now. If so, redirect it to a different spot if (w.StorageSpots[i].IsFull()) { // Search for a storage area with an empty spot foreach (var item in w.StorageSpots) { if (!item.IsFull()) { // Create new route, send the robot to a not-full storage area. this.route.Clear(); List <char> Route = w.d.shortest_path(DropOffAt.name, item.DropoffNode.name); List <char> DepotRoute = w.d.shortest_path(item.DropoffNode.name, 'B'); Route.Reverse(); DepotRoute.Reverse(); Route.AddRange(DepotRoute); this.SetRoute(Route, item.DropoffNode.name); position = -1; destinationreached = false; isMoving = false; return; // List<char> Route = d.shortest_path(start, end); // List<char> Terugweg = d.shortest_path(end, start); // Route.Reverse(); // Terugweg.Reverse(); // Route.AddRange(Terugweg); // return Route; } } } w.StorageSpots[i].AddRek(carriedRek); carriedRek = null; } } } }
public Trein(double x, double y, double z, double rotationX, double rotationY, double rotationZ, World w) { this.type = "trein"; this.guid = Guid.NewGuid(); this._world = w; this._x = x; this._y = y; this._z = z; this._rX = rotationX; this._rY = rotationY; this._rZ = rotationZ; this.CarriedRek = this._world.CreateRek(this.x, this.y, this.z); _state = TreiState.TRAIN_INCOMMING; }
/// <summary> /// Gets called when the robot reaches it's destination /// </summary> public void DropOffRek(Node DropOffAt) { // Check if the robot is actually carrying a Rek if (carriedRek != null) { // Loop over all the storagespots, find the matching spot for (int i = 0; i < w.StorageSpots.Count; i++) { if (DropOffAt == w.StorageSpots[i].DropoffNode) { w.StorageSpots[i].AddRek(carriedRek); carriedRek = null; break; } } // Drop off or something } }
/// <summary> ///Tell the robot to pick up a nearby Rek /// </summary> public void PickupRek() { // Check if the robot is at the depot if (atPickupPoint) { foreach (var item in w.worldObjects) { if (item is Rek) { Rek q = (Rek)item; if (q.readyforpickup == true) { carriedRek = q; // carriedRek.Move(this.x+30, this.y+30, this.z); } } } } }
// public void CommandPickup(Rek k, bool atTrain, Robot _r) { // Tell a robot to come pick up an item _r.idle = false; _r.rekToCarry = k; if (atTrain) { //Als B magazijn is en A trein // Move k (rekToCarry van de robot) van trein(A) naar magazijn(B) _r.SetRoute(GenerateRoute('A', 'B'), 'B'); } else { //Als B magazijn is en A trein // Move k (rekToCarry van de robot) van magazijn(B) naar trein(A) _r.SetRoute(GenerateRoute('B', 'A'), 'A'); } //r.PickupRek(); }
public World() { // Create the graph, and create the nodes the robot can move to d = new Dijkstra(); InitialNodes(); // Create the four storage area's Storage storage1 = new Storage(NodeList[6], 10, 5, 3, 0, 5, this); Storage storage2 = new Storage(NodeList[8], 10, 5, 3, 0, 12.5, this); Storage storage3 = new Storage(NodeList[10], 35, 5, 20, 0, 5, this); Storage storage4 = new Storage(NodeList[12], 10, 5, 3, 0, 22.5, this); StorageSpots.Add(storage1); StorageSpots.Add(storage2); StorageSpots.Add(storage3); StorageSpots.Add(storage4); //Create the train t = SpawnTruck(-20, 0, 0); //a few Rek's for testing purposes Rek q = CreateRek(12, 0, 0); Rek w = CreateRek(15, 0, 0); Rek z = CreateRek(18, 0, 0); Rek a = CreateRek(18, 0, 0); Rek b = CreateRek(18, 0, 0); Rek c = CreateRek(18, 0, 0); // Create the robots r = CreateRobot(12, 0, 0); walle = CreateRobot(15, 0, 0); irongiant = CreateRobot(18, 0, 0); robotlist.Add(r); robotlist.Add(walle); robotlist.Add(irongiant); // Each time this function is called, tells a single robot to pick up a Rek. There are three robots CommandPickup(); CommandPickup(); CommandPickup(); }
/// <summary> ///Tell the robot to pick up a nearby Rek /// </summary> public bool PickupRek() { // Check if the robot is at the depot. Obsolete? if (atPickupPoint) { foreach (var item in w.worldObjects) { if (item is Rek) { Rek q = (Rek)item; if (q.readyforpickup == true) { q.readyforpickup = false; carriedRek = q; return(true); } } } } return(false); }
public void TrainArrived(Trein _t, Rek cargo) { //Word aangeroepen wanneer een trein (_t) bij het loading dock is cargo.readyforpickup = true; //Loop door robots en laat een idle robot de cargo ophalen foreach (Robot r in this.robots) { if (r.idle) { CommandPickup(cargo, true, r); r.idle = false; break; } } //Loop door robots een laat een idle robot een rek uit de storage naar de trein brengen foreach (Robot r in this.robots) { foreach (Storage s in this.StorageSpots) { for (int i = 0; i < s.Stored.Count; i++) { Rek rek = s.Stored[i]; if (r.idle) { s.Stored.Remove(rek); rek.readyforpickup = true; r.trainToLoad = _t; CommandPickup(rek, false, r); r.idle = false; } } } } }
// Word aangeroepen door een robot public void Load(Rek cargo) { this.CarriedRek = cargo; }
/// <summary> /// Main loop /// </summary> public void Main() { // If idle, dont do anything if (idle) { return; } if (route != null && route.Count > position) { this.MoveTo(route[position]); // Check if the robot has reached a node if (this.x == route[position].x && this.y == route[position].y && this.z == route[position].z) { //Check if the robot is at it's destination if (this.x == TargetNode.x && this.y == TargetNode.y && this.z == TargetNode.z) { if (carriedRek != null) { if (this.trainToLoad != null) { this.trainToLoad.Load(carriedRek); this.carriedRek = null; this.trainToLoad = null; } else { DropOffRek(TargetNode); } } else { PickupRek(rekToCarry); } } // Else,check if this is the last stop else if (route[route.Count - 1] == route[position]) { if (carriedRek != null) { if (this.trainToLoad != null) { this.trainToLoad.Load(carriedRek); this.carriedRek = null; this.trainToLoad = null; idle = true; } else { DropOffRek(route[position]); } } idle = true; return; } position++; this.isMoving = false; } } }