예제 #1
0
        public static Boat RandomizeFreightship(Freightship boat)
        {
            int freightshipWeight            = rnd.Next(3000, 20000 + 1);               // Random Freightship spec
            int freightshipSpeed             = rnd.Next(0, 20 + 1);
            int freightshipAmountofContainer = rnd.Next(0, 500 + 1);

            StringBuilder strbuild = new StringBuilder();
            string        randomString;

            // strbuild.Clear();
            char letter;
            int  length = 3;

            for (int j = 0; j < length; j++)                                 // Creating stringbuilder.
            {
                double flt   = rnd.NextDouble();
                int    shift = Convert.ToInt32(Math.Floor(25 * flt));
                letter = Convert.ToChar(shift + 65);
                strbuild.Append(letter);
            }
            randomString            = strbuild.ToString();
            boat.Id                 = $"F-{randomString}";
            boat.Weight             = freightshipWeight;
            boat.Topspeed           = freightshipSpeed;
            boat.Type               = "Freightship";
            boat.AmountOfContainers = freightshipAmountofContainer;
            boat.DaysLeft           = 6;
            boat.ParkingRange       = 4;
            return(boat);
        }
예제 #2
0
        public static Freightship InitializeFreightship()
        {
            Freightship x = new Freightship()
            {
                Id = "", Weight = 0, Topspeed = 0, AmountOfContainers = 4, ParkingRange = 2, Type = " Error Message", DaysLeft = 6
            };

            return(x);
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Simulate days
            //for (int i = 0; i < DaysToSimulate; i++)
            //{
            //    // Day Start

            //    // Get 5 random boats
            //    for (int x = 0; i < BoatPerDay; x++)
            //    {
            //         // Does the boat fit in the harbor
            //         // If boat fits, park it, else lose it.
            //    }
            //    // Day End
            //}

            for (int i = 0; i < harborSize; i++)      // Fyller hamnen med "tomt"
            {
                hamn.Add(new Tomt {
                    Type = "tomt", Id = ""
                });
            }

            Console.WriteLine("------------Empty harbor ---");

            foreach (var boat in hamn)
            {
                Console.WriteLine(boat.Type);
            }

            while (true)
            {
                day++;

                int temp = 0;

                foreach (var item in hamn)
                {
                    var q = hamn
                            .GroupBy(a => a.Id)
                            .Where(b => b.Count() > 1)
                            .Select(c => c.Key)
                            .ToList();
                    foreach (var distinctId in q)
                    {
                        if (item.Id == distinctId)
                        {
                            item.DaysLeft -= 1;
                        }
                    }

                    //  item.DaysLeft -= 1;
                }
                Console.WriteLine($"-----------DAY {day}-----------------");

                for (int i = 0; i < hamn.Count; i++)     // Boats depart.
                {
                    if (hamn[i].Type == "tomt" || hamn[i].DaysLeft == 0)
                    {
                        hamn.RemoveRange(i, 1);
                        Tomt newTomt = InitializeTomt();
                        hamn.Insert(i, newTomt);
                    }
                }


                // If sailboat arrives - find parking, else rejectedboats.add();
                for (int i = 0; i < hamn.Count; i++)
                {
                    // abvryta här?
                    int slump = rnd.Next(1, 4 + 1);
                    switch (slump)
                    {
                    case 1:
                        try
                        {
                            foreach (var item in hamn)
                            {
                                //FindParkingSizeHalf
                                //FindParkingSizeOne
                                //FindparkingSizeTwo
                                //FindparkingSizeFour
                            }
                            hamn.RemoveRange(i, 1);
                            hamn.RemoveRange(i + 1, 1);
                            Sailboat newSailBoat = new Sailboat();
                            RandomizeSailBoat(newSailBoat);
                            hamn.Insert(i, newSailBoat);
                            hamn.Insert(i + 1, newSailBoat);
                            Console.WriteLine("A sailboat has arrived.... !!");
                        }
                        catch (ArgumentException) { }
                        break;

                    case 2:
                        try
                        {
                            hamn.RemoveRange(i, 1);
                            Motorboat newMotorBoat = new Motorboat();
                            RandomizeMotorBoat(newMotorBoat);
                            hamn.Insert(i, newMotorBoat);
                            Console.WriteLine("A Motorboat has arrived.... !!");
                        }
                        catch (ArgumentException) { }
                        break;

                    case 3:
                        try
                        {
                            hamn.RemoveRange(i, 1);               // TODO Hur ska vi göra med roddbåtarna
                            Rowingboat newRowingBboat = new Rowingboat();
                            RandomizeRowingBoat(newRowingBboat);
                            hamn.Insert(i, newRowingBboat);
                            Console.WriteLine("A Rowingboat has arrived.... !!");
                        }
                        catch (ArgumentException) { }
                        break;

                    case 4:
                        try
                        {
                            hamn.RemoveRange(i, 4);
                            Freightship newFreightship = new Freightship();
                            RandomizeFreightship(newFreightship);
                            hamn.Insert(i, newFreightship);
                            hamn.Insert(i + 1, newFreightship);
                            hamn.Insert(i + 2, newFreightship);
                            hamn.Insert(i + 3, newFreightship);
                            Console.WriteLine("A Freightship has arrived.... !!");
                        }
                        catch (ArgumentException) { }
                        break;

                    default:
                        break;
                    }

                    Console.WriteLine("--------------------------- !!");
                    int parkingSpace = 1;
                    foreach (var boat in hamn)
                    {
                        Console.WriteLine($" Space: {parkingSpace}  Reg: {boat.Id} Type: {boat.Type}, Weight: {boat.Weight}kg Misc: Error. ");
                        parkingSpace++;
                    }
                    Console.ReadKey(true);

                    Boat boata = new Boat();
                }
            }
        }