Esempio n. 1
0
        public override String ToString()
        {
            String s = GAtomicObject._getGAtomicElementsString(element);

            for (GAtomicConnectionDirection direction = GAtomicConnectionDirection.TOP; direction <= GAtomicConnectionDirection.TRIPLE_LEFT; direction++)
            {
                if (_hasConnection(direction))
                {
                    s += "1";
                }
                else
                {
                    s += "0";
                }
            }

            return(s);
        }
Esempio n. 2
0
        public bool _setConnectionElement(GAtomicConnectionDirection direction, GAtomicElementObject element)
        {
            if ((direction < GAtomicConnectionDirection.TOP) || (direction > GAtomicConnectionDirection.TRIPLE_LEFT))
            {
                return(false);
            }

            for (int k = 0; k < connection_elements.Length; k++)
            {
                GAtomicConnectionElement c = (GAtomicConnectionElement)connection_elements[k];
                if (c.DirectionOfConnectingElement == direction)
                {
                    c.AtomicElement = element;
                }
            }

            return(true);
        }
Esempio n. 3
0
        public bool _hasConnection(GAtomicConnectionDirection direction)
        {
            if (connection_elements == null)
            {
                return(false);
            }

            if ((direction < GAtomicConnectionDirection.TOP) || (direction > GAtomicConnectionDirection.TRIPLE_LEFT))
            {
                return(false);
            }

            for (int k = 0; k < connection_elements.Length; k++)
            {
                GAtomicConnectionElement c = (GAtomicConnectionElement)connection_elements[k];
                if (c.DirectionOfConnectingElement == direction)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public object _getConnectionElement(GAtomicConnectionDirection direction)
        {
            if (connection_elements == null)
            {
                return(null);
            }

            if ((direction < GAtomicConnectionDirection.TOP) || (direction > GAtomicConnectionDirection.TRIPLE_LEFT))
            {
                return(null);
            }

            for (int k = 0; k < connection_elements.Length; k++)
            {
                GAtomicConnectionElement c = (GAtomicConnectionElement)connection_elements[k];
                if (c.DirectionOfConnectingElement == direction)
                {
                    return(c.AtomicElement);
                }
            }

            return(null);
        }
Esempio n. 5
0
 public GAtomicConnectionElement(GAtomicElementObject elem, GAtomicConnectionDirection dir)
 {
     atomic_element = elem;
     direction_of_connecting_element = dir;
 }
Esempio n. 6
0
        private void _selectCheckingConnectionsAndElements()
        {
            checking_elements = Array.CreateInstance(typeof(GAtomicObject), number_of_elements);
            // read miniature elements and read connections from it in an array (connection direction and element)
            // forget first and last row, first and last column, only borders

            int                  row = 0, col = 0;
            int                  neighbour_row = row;
            int                  neighbour_col = col;
            object               array_object  = null;
            ArrayList            neighbours    = new ArrayList();
            ArrayList            connections   = new ArrayList();
            GAtomicElementObject base_element  = null;

            int index = 0;

            for (row = 1; row < miniature_elements.GetLength(0) - 1; row++)
            {
                for (col = 1; col < miniature_elements.GetLength(1) - 1; col++)
                {
                    array_object = miniature_elements.GetValue(row, col);
                    if (array_object is GAtomicElementObject)
                    {
                        base_element = (GAtomicElementObject)array_object;

                        neighbours  = new ArrayList();
                        connections = new ArrayList();
                        // check if it has connecting elements assigned to it
                        for (GAtomicConnectionDirection direction = GAtomicConnectionDirection.TOP; direction <= GAtomicConnectionDirection.TRIPLE_LEFT; direction++)
                        {
                            if (((GAtomicElementObject)array_object)._hasConnection(direction))
                            {
                                // Check connections
                                neighbour_row = row;
                                neighbour_col = col;
                                if ((direction == GAtomicConnectionDirection.TOP) || (direction == GAtomicConnectionDirection.DOUBLE_TOP) || (direction == GAtomicConnectionDirection.TRIPLE_TOP))
                                {
                                    neighbour_row--;
                                }
                                else if (direction == GAtomicConnectionDirection.TOP_RIGHT)
                                {
                                    neighbour_row--;
                                    neighbour_col++;
                                }
                                else if ((direction == GAtomicConnectionDirection.RIGHT) || (direction == GAtomicConnectionDirection.DOUBLE_RIGHT) || (direction == GAtomicConnectionDirection.TRIPLE_RIGHT))
                                {
                                    neighbour_col++;
                                }
                                else if (direction == GAtomicConnectionDirection.BOTTOM_RIGHT)
                                {
                                    neighbour_row++;
                                    neighbour_col++;
                                }
                                else if ((direction == GAtomicConnectionDirection.BOTTOM) || (direction == GAtomicConnectionDirection.DOUBLE_BOTTOM) || (direction == GAtomicConnectionDirection.TRIPLE_BOTTOM))
                                {
                                    neighbour_row++;
                                }
                                else if (direction == GAtomicConnectionDirection.BOTTOM_LEFT)
                                {
                                    neighbour_row++;
                                    neighbour_col--;
                                }
                                else if ((direction == GAtomicConnectionDirection.LEFT) || (direction == GAtomicConnectionDirection.DOUBLE_LEFT) || (direction == GAtomicConnectionDirection.TRIPLE_LEFT))
                                {
                                    neighbour_col--;
                                }
                                else if (direction == GAtomicConnectionDirection.TOP_LEFT)
                                {
                                    neighbour_row--;
                                    neighbour_col--;
                                }

                                if (!_validRowAndColumn(neighbour_row, neighbour_col))
                                {
                                    continue;
                                }

                                base_element._setConnectionElement(direction, (GAtomicElementObject)miniature_elements.GetValue(neighbour_row, neighbour_col));
                            }
                        }                        // end of for (GAtomicConnectionDirection direction = GAt

                        // you need to add en element with its directions**********
                        // add element, direction and element at that direction
                        // we want take the array object and put the elements in the direction instead of the null
                        // so we need to make a new copy of this element
                        // and then put the elements instead of null with each connection

                        checking_elements.SetValue(base_element, index);

                        index++;
                    }    // end of if (array_object is GAtomicElementObject)
                }        // end of for col
            }            // end of for row
        }
Esempio n. 7
0
        private bool _gameSuccess()
        {
            //checking_elements
            // check the array for all elements with the characteristics needed

            object element_object = null;
            GAtomicElementObject atomic_element = null;

            GAtomicElementObject element_to_check_against = null;
            GAtomicElementObject element_to_check_against_connection_element = null;

            int neighbour_row = 0, neighbour_col = 0;

            int checking_elements_index = 0;

            bool element_ok = true;

            for (int row = 0; row < elements.GetLength(0); row++)
            {
                if (!element_ok)
                {
                    // an element is in error, it's all we need to know
                    return(false);
                }

                for (int col = 0; col < elements.GetLength(1); col++)
                {
                    if (!element_ok)
                    {
                        // an element is in error, it's all we need to know
                        return(false);
                    }

                    element_object = elements.GetValue(row, col);
                    if ((element_object != null) && (element_object is GAtomicElementObject))
                    {
                        atomic_element = (GAtomicElementObject)element_object;

                        checking_elements_index = 0;
                        element_ok = false;
                        // check for same(s) in checking elements_array, can have many
                        for (checking_elements_index = 0; checking_elements_index < checking_elements.GetLength(0) && !element_ok; checking_elements_index++)
                        {
                            // only directions are checked
                            if (atomic_element == (GAtomicElementObject)checking_elements.GetValue(checking_elements_index))
                            {
                                // now directions + elements
                                element_to_check_against = (GAtomicElementObject)checking_elements.GetValue(checking_elements_index);
                                // check if atomic_element has same connecting elements as element_to_check_against

                                // check all the directions of element_to_check_against
                                for (GAtomicConnectionDirection direction = GAtomicConnectionDirection.TOP; direction <= GAtomicConnectionDirection.TRIPLE_LEFT; direction++)
                                {
                                    element_object = element_to_check_against._getConnectionElement(direction);

                                    if (element_object != null)
                                    {
                                        element_to_check_against_connection_element = (GAtomicElementObject)element_object;
                                        // get next row and col
                                        neighbour_row = row;
                                        neighbour_col = col;
                                        if ((direction == GAtomicConnectionDirection.TOP) || (direction == GAtomicConnectionDirection.DOUBLE_TOP) || (direction == GAtomicConnectionDirection.TRIPLE_TOP))
                                        {
                                            neighbour_row--;
                                        }
                                        else if (direction == GAtomicConnectionDirection.TOP_RIGHT)
                                        {
                                            neighbour_row--;
                                            neighbour_col++;
                                        }
                                        else if ((direction == GAtomicConnectionDirection.RIGHT) || (direction == GAtomicConnectionDirection.DOUBLE_RIGHT) || (direction == GAtomicConnectionDirection.TRIPLE_RIGHT))
                                        {
                                            neighbour_col++;
                                        }
                                        else if (direction == GAtomicConnectionDirection.BOTTOM_RIGHT)
                                        {
                                            neighbour_row++;
                                            neighbour_col++;
                                        }
                                        else if ((direction == GAtomicConnectionDirection.BOTTOM) || (direction == GAtomicConnectionDirection.DOUBLE_BOTTOM) || (direction == GAtomicConnectionDirection.TRIPLE_BOTTOM))
                                        {
                                            neighbour_row++;
                                        }
                                        else if (direction == GAtomicConnectionDirection.BOTTOM_LEFT)
                                        {
                                            neighbour_row++;
                                            neighbour_col--;
                                        }
                                        else if ((direction == GAtomicConnectionDirection.LEFT) || (direction == GAtomicConnectionDirection.DOUBLE_LEFT) || (direction == GAtomicConnectionDirection.TRIPLE_LEFT))
                                        {
                                            neighbour_col--;
                                        }
                                        else if (direction == GAtomicConnectionDirection.TOP_LEFT)
                                        {
                                            neighbour_row--;
                                            neighbour_col--;
                                        }

                                        if (!_validRowAndColumn(neighbour_row, neighbour_col))
                                        {
                                            return(false);
                                        }

                                        element_object = elements.GetValue(neighbour_row, neighbour_col);

                                        if (!(element_object is GAtomicElementObject))
                                        {
                                            return(false);
                                        }

                                        // check for same original element with same connections
                                        if ((GAtomicElementObject)element_object == element_to_check_against_connection_element)
                                        {
                                            element_ok = true;
                                            // continue for other directions
                                            continue;
                                            // break : for (checking_elements_index = 0; checking_elements_index < checking_elements.GetLength (0) && !element_ok; checking_elements_index++)
                                        }
                                        else
                                        {
                                            element_ok = false;
                                            break;
                                        }
                                    } //  end of if (element_object != null)
                                }     // end of for (GAtomicConnectionDirection direction = GAtomicConnectionDirection.TOP; direction <= GAtomicConnectionDirection.TRIPLE_LEFT; direction++)
                            }         // end of if (atomic_element == (GAtomicElementObject)checking_elements.GetValue (checking_elements_index))
                        }             // end of for (checking_elements_index = 0; checking_elements_index < checking_elements.GetLength (0) && !element_ok; checking_elements_index++)
                    }                 //  end of if ((element_object != null) && (element_object is GAtomicElementObject))
                }                     // end of for (int col = 0; col < elements.GetLength (1); col++)
            }                         //  end of for (int row = 0; row < elements.GetLength (0); row++)

            return(true);
        }