Пример #1
0
        /*
         * Method: EvaluateStack()
         * Purpose: Evaluate a stack from [0] - [2] (3 elements)
         * Parameters: HeavyObjectList
         * Returns: double
         */
        public double EvaluateStack(HeavyObjectList input)
        {
            //rewards points based on the postition the heaviest object is one.
            //input[0] should be the heaviest in the stack  for it to be a bottomweight stack
            //create a list that will hold the volume and mass of each object
            List <float> mass = new List <float>();

            for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next())
            {
                mass.Add(i.CurrentItem().Mass);
            }
            //after loading the mass of each object into a list, we can now see if the heaviest in index [0]
            //with the mass , then sort, then reverse,because sort is ascending order and I want descending
            mass.Sort();
            mass.Reverse();

            //lets see the stack first has the heaviest object on the bottom.
            float total = 0.0f;

            if (mass[0] == input.At(0).Mass)
            {
                //if we have the heaviest at the bottom
                //im going to add all the values up and divide by the number of elements
                foreach (float value in mass)
                {
                    total = total + value;
                }
                float count = total / input.Length();
                return((float)Math.Round(count));
            }
            else if (mass[1] == input.At(0).Mass)
            {
                //if we have the second heaviest object on the bottom
                //use this algorithm
                //total the massess like before
                foreach (float value in mass)
                {
                    total = total + value;
                }
                //this time we are going to return a value that is the total divided by the #elements + 2
                float count = total / (input.Length() + 2);
                return((float)Math.Round(count));
            }
            else
            {
                //the bottom is basically at the top
                //total the massess like before
                foreach (float value in mass)
                {
                    total = total + value;
                }
                //this time we are going to return a value that is the total divided by the #elements + 4
                float count = total / (input.Length() + 4);
                return((float)Math.Round(count));
            }
        }
Пример #2
0
        /*
         * Method: EvaluateStack()
         * Purpose: Evaluate a stack from [0] - [2] (3 elements)
         * Parameters: HeavyObjectList
         * Returns: double
         */
        public double EvaluateStack(HeavyObjectList input)
        {
            //opposite of a pyramid, we need to look at mass and volume.
            //logically for a topple, the smallest shape  should logically be on the bottom with the largest shape on top
            //looking at density. (least, middle, most) will topple but also (small,medium,large) shape
            //create a list to make the ideal senario
            List <float> topple = new List <float>();

            for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next())
            {
                topple.Add(i.CurrentItem().Density);
            }
            topple.Sort(); //this should give us a least,meduim,most denisty structure with least at [0];

            //similar to the other structures, we can see if the list[0] is the same as topple[0] for the ideal toople structure
            if (input.At(0).Density == topple[0]) //if the bottom is the most dense
            {
                //we need to find the second most dense and see if it is in the middle
                if (input.At(1).Density == topple[1])
                {
                    //this gaurentees that we have a toople (because there us only 3 elements in every list, this would not work in a real world situation where there could be mutliple lists with different lengths).
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length();
                    return((float)Math.Round(count));
                }
                else //heavy,least,meduim
                {
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 15;
                    return((float)Math.Round(count));
                }
            }
            else if (input.At(0).Density == topple[1]) // we have a medium,heavy,least or meduim, least, heavy, more chance of topple than the previous else above
            {
                if (input.At(1).Density == topple[0])
                {
                    //medium,heavy,least
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 35;
                    return((float)Math.Round(count));
                }
                else //we have a medium,least,heavy
                {
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 25; //almost equal posiblity of it toppling wth senario (heavy,least,meduim)
                    return((float)Math.Round(count));
                }
            }
            else
            {
                //we have a least,meduim,heavy or least,heavy,medium
                if (input.At(1).Density == topple[1]) //meduim in the middle
                {
                    //least,meduim,heavy, proabbly wont topple at all
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = total / input.Length() + 55;
                    return((float)Math.Round(count));
                }
                else
                {
                    //least,heavy,medium
                    float total = 0.0f;
                    foreach (float dens in topple)
                    {
                        total = total + dens;
                    }
                    float count = (float)Math.Round(total / input.Length() + 85);
                    return(count);
                }
            }
        }
Пример #3
0
        /*
         * Method: EvaluateStack()
         * Purpose: Evaluate a stack from [0] - [2] (3 elements)
         * Parameters: HeavyObjectList
         * Returns: double
         */
        public double EvaluateStack(HeavyObjectList input)
        {
            //look at the volume of each box
            List <float> volume = new List <float>();

            for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next())
            {
                volume.Add(i.CurrentItem().Volume);
            }
            volume.Sort();
            volume.Reverse();
            //by reversing after sort we can indicate that we want the most volume at the bottom  to create that Pyramid  shape.
            //test to see if the highest volume, (largest shape) is at the bottom (similar to the bottomweight except were not looking at mass
            if (volume[0] == input.At(0).Volume)
            {
                //now we can test to see if the rest if equal
                //because I know there are three objects in each list.
                int  counter = 0;
                bool isSame  = false;
                foreach (float vol in volume)
                {
                    if (vol == input.At(counter).Volume)
                    {
                        counter++;
                        isSame = true;
                        continue;
                    }
                    else
                    {
                        isSame = false;
                        break; //if the second volumes are not the same to volume stack (which should represent a Pyramid )
                    }
                }
                if (isSame)
                {
                    //return a value based on the volume of each box
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 10); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
                else
                {
                    //because it isnt the same (large, meduim,small)
                    //we must have (large,small,medium) which isnt Pyramid itself
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 20); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
            }
            //the second largest box is now one the bottom
            else if (volume[1] == input.At(0).Volume)
            {
                //the largest box is now in the middle or top
                //lets check where the largest box is
                float largeBox = input.At(1).Volume; //check ot see if this is the largest box
                if (largeBox == volume[0])           //should be teh largest box (medium, large, small)
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 30); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
                else //the largest is on the top, medium,small,large
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 40); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
            }
            //smallest box is on the bottom
            else
            {
                //where is the largest back then
                //in the middle (small,large,medium)
                //check ot see if this is the largest box
                if (volume[0] == input.At(1).Volume)
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 50); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
                else //the largest is on the top, (small,meduim,large)
                {
                    float total = 0;
                    foreach (float vol in volume)
                    {
                        total = total + vol;
                    }
                    float count = total / (input.Length() + 60); //similar to the bottom stack except were using the volume of each box
                    count = (float)Math.Round(count);
                    return(count);
                }
            }
        }