예제 #1
0
        public Wagon AddDierToNewWagon(Dier dier)
        {
            Wagon NewWagon = new Wagon();

            NewWagon.TryAddDier(dier);

            Wagons.Add(NewWagon);

            return(NewWagon);
        }
예제 #2
0
 private static Wagon DierToevogen(Wagon wagon, Dier dier)
 {
     if (GetPuntenFromWagon(wagon, dier) + dier.punten <= 10)
     {
         if (Isvalid(wagon, dier))
         {
             wagon.dieren.Add(dier);
             dier.Check = true;
         }
     }
     return(wagon);
 }
예제 #3
0
        public void AddAnimalsToWagons()
        {
            animalSorter.SortAnimals(train.Animals, wagons);

            train.Wagons.Clear();
            Wagon wagon = new Wagon();

            train.Wagons.Add(wagon);

            train.AddAnimalsToWagon(animalSorter.Animals);
            animalSorter.Animals.Clear();
            train.Animals.Clear();
        }
예제 #4
0
        private void LbTrein_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = lbTrein.SelectedIndex;

            Wagon selectedWagon = Trein1.Wagons[selectedIndex];

            lbWagon.Items.Clear();

            foreach (Dier wagonDier in selectedWagon.Dieren)
            {
                lbWagon.Items.Add(wagonDier);
            }
        }
예제 #5
0
        private void LoadAnimalsInWagon()
        {
            listBoxAnimalInWagon.Items.Clear();
            Wagon selectedWagon = (Wagon)listBoxWagons.SelectedItem;

            foreach (Wagon wagon in wagons)
            {
                if (selectedWagon == wagon)
                {
                    listBoxAnimalInWagon.Items.Add(wagon);
                }
            }
        }
예제 #6
0
        private static int GetPuntenFromWagon(Wagon wagon, Dier dier)
        {
            int punt = 0;

            if (wagon.dieren != null)
            {
                foreach (var item in wagon.dieren)
                {
                    punt += item.punten;
                }
                return(punt);
            }
            return(0);
        }
예제 #7
0
        public void Loadanimals()
        {
            currentWagon = new Wagon(iAnimalConnection);
            wagons.Add(currentWagon);
            int animalstoload = iAnimalConnection.Loadammount();
            int i             = 0;

            while (animalstoload != i)
            {
                bool hasloaded = currentWagon.LoadWagon();
                if (hasloaded == true)
                {
                    i++;
                }
                else if (hasloaded == false)
                {
                    currentWagon = new Wagon(iAnimalConnection);
                    wagons.Add(currentWagon);
                }
            }
        }
예제 #8
0
        public void AddAnimal(Animal animal)
        {
            Wagon availableWagon = null;

            foreach (Wagon w in wagons)
            {
                if (w.CanAddAnimal(animal))
                {
                    availableWagon = w;
                    break;
                }
            }

            if (availableWagon == null)
            {
                availableWagon = new Wagon();
                wagons.Add(availableWagon);
            }

            availableWagon.Add(animal);
        }
예제 #9
0
        public void AddAnimalsToWagon(List <Animal> animals)
        {
            foreach (Animal animal in animals)
            {
                succes = false;
                foreach (Wagon wagon in Wagons)
                {
                    if (wagon.TryToAddTheAnimal(animal) == true)
                    {
                        succes = true;
                        break;
                    }
                }

                if (succes == false)
                {
                    Wagon wagon = new Wagon(animal);
                    Wagons.Add(wagon);
                }
            }
        }
예제 #10
0
        public void LoadTrain(List <Animal> animals)
        {
            int wagonIndex = 0;

            while (animals.Count != 0)
            {
                AddWagon(wagonIndex, animals[0]);
                Wagon wagon = Wagons[wagonIndex];
                animals.RemoveAt(0);

                for (int i = animals.Count - 1; i >= 0; i--)
                {
                    Animal animal = animals[i];
                    if (wagon.AddAnimal(animal))
                    {
                        animals.Remove(animal);
                    }
                }
                wagonIndex += 1;
            }
        }
예제 #11
0
        public Wagon WagonMetPlek(Dier dier)
        {
            {
                // Er wordt niets gedaan met de return van de wagon maar deze dient eigenlijk als een break.
                foreach (Wagon wagon in Wagons)
                {
                    if (!wagon.GeenPlek(dier))
                    {
                        if (!wagon.GevaarlijkVoorDier(dier))
                        {
                            wagon.VoegDierToe(dier);
                            return(wagon);
                        }
                    }
                }
            }
            Wagon a = MaakWagon();

            a.VoegDierToe(dier);
            Wagons.Add(a);
            return(a);
        }
예제 #12
0
        public void VerdeelDieren()
        {
            //Orden Dieren
            Ordener ordener = new Ordener();

            dieren = ordener.OrdenDieren(dieren);

            //Per wagon kijken of dier erbij past.
            while (dieren.Count > 0)
            {
                trein.Add(new Wagon());
                for (int d = 0; d < dieren.Count; d++)
                {
                    Wagon lastWagon = trein[trein.Count - 1];
                    Dier  dier      = dieren[d];
                    if (lastWagon.TryAndAddDier(dier))
                    {
                        dieren.Remove(dier);
                        d = -1;
                    }
                }
            }
        }
예제 #13
0
        public Train PerformAlghoritm(List <Animal> Animals)
        {
            Train train = new Train();
            Wagon wagon = new Wagon();

            train.wagons.Add(wagon);

            foreach (Animal a in Animals)
            {
                bool AnimalHasBeenAdded = false;
                foreach (Wagon w in train.wagons)
                {
                    if (AnimalHasBeenAdded)
                    {
                        break;
                    }
                    //Check if there is room in the wagon
                    if (algoritme.WagonHasRoom(w, a))
                    {
                        //if animal is a herbivore
                        if (a.Eater == AnimalType.Herbivore)
                        {
                            //If there is no other carnivore
                            if (!algoritme.WagonHasMeatEater(w))
                            {
                                w.Animals.Add(a);
                                w.FreePoints      -= a.points;
                                AnimalHasBeenAdded = true;
                            }


                            //If the carnivore is smaller than the current herbivore animal
                            else if (algoritme.WagonMeatEater(w).Size < a.Size)
                            {
                                w.Animals.Add(a);
                                w.FreePoints      -= a.points;
                                AnimalHasBeenAdded = true;
                            }
                        }

                        //Animal is a carnivore
                        else
                        {
                            bool SmallestAnimal = true;
                            //If there is not a bigger carnivore
                            foreach (Animal a2 in w.Animals)
                            {
                                if (a2.Size <= a.Size)
                                {
                                    SmallestAnimal = false;
                                }
                            }

                            //If there are no other meateaters in the wagon and the current animal is the smallest out of the ones in the wagon.
                            if (!algoritme.WagonHasMeatEater(w) && SmallestAnimal)
                            {
                                w.Animals.Add(a);
                                w.FreePoints      -= a.points;
                                AnimalHasBeenAdded = true;
                            }

                            //PREVIOUS TRY

                            /*//Looks for biggest carnivore, and checking if it is smaller than the biggest herbivore
                             * Animal BiggestCarnivore = w.Animals.FirstOrDefault(a2 => a2.Eater != AnimalType.Herbivore);
                             * if (BiggestCarnivore != null)
                             * {
                             *  //Er zit een vleeseter/omnivoor in de wagon
                             *  if (SizeFits(a, BiggestCarnivore) == true)
                             *  {
                             *      //De planteneter past in de wagon
                             *      w.Animals.Add(a);
                             *      w.FreePoints -= a.points;
                             *      AnimalHasBeenAdded = true;
                             *  }
                             * }
                             * else
                             * {
                             *  //er zit geen vleeseter/omnivoor in en er is plek.
                             *  w.Animals.Add(a);
                             *  w.FreePoints -= a.points;
                             *  AnimalHasBeenAdded = true;
                             * }*/
                        }
                    }
                }

                //Adds animal to a new wagon because animal can't be added to an existing wagon
                if (!AnimalHasBeenAdded)
                {
                    Wagon w = new Wagon();
                    w.Animals.Add(a);
                    w.FreePoints -= a.points;
                    train.wagons.Add(w);
                }
            }

            return(train);
        }
예제 #14
0
 public void addWagon(Wagon wagon)
 {
     wagons.Add(wagon);
 }
예제 #15
0
        private static bool Isvalid(Wagon wagon, Dier dier)
        {
            if (wagon.dieren != null)
            {
                foreach (var item in wagon.dieren)
                {
                    if (dier.Eten == Dier.eten.Vlees)
                    {
                        if (dier.Formaat == Dier.formaat.Groot)
                        {
                            return(false);
                        }
                        if (dier.Formaat == Dier.formaat.Middelmatig)
                        {
                            if (item.Formaat == Dier.formaat.Groot && item.Eten == Dier.eten.Planten)
                            {
                                return(true);
                            }
                            return(false);
                        }
                        if (dier.Formaat == Dier.formaat.Klein)
                        {
                            if (item.Formaat == Dier.formaat.Middelmatig && item.Eten == Dier.eten.Planten || item.Formaat == Dier.formaat.Groot && item.Eten == Dier.eten.Planten)
                            {
                                return(true);
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        if (item.Eten == Dier.eten.Vlees)
                        {
                            if (item.Formaat == Dier.formaat.Groot)
                            {
                                return(false);
                            }
                            if (item.Formaat == Dier.formaat.Middelmatig)
                            {
                                if (dier.Formaat == Dier.formaat.Groot && dier.Eten == Dier.eten.Planten)
                                {
                                    return(true);
                                }
                                return(false);
                            }
                            if (item.Formaat == Dier.formaat.Klein)
                            {
                                if (dier.Formaat == Dier.formaat.Middelmatig && dier.Eten == Dier.eten.Planten || dier.Formaat == Dier.formaat.Groot && dier.Eten == Dier.eten.Planten)
                                {
                                    return(true);
                                }
                                return(false);
                            }
                        }
                    }


                    return(true);
                }
            }
            return(true);
        }
예제 #16
0
 public void AddWagon(Wagon wagon)
 {
     _wagons.Add(wagon);
 }
예제 #17
0
 private Wagon MaakWagon()
 {
     Wagon = new Wagon();
     return(Wagon);
 }
예제 #18
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     Wagon.SetMaxPoints(decimal.ToInt32(nmrcWagonSize.Value));
     Close();
 }