示例#1
0
文件: Gene.cs 项目: OCox1991/Genome
 /// <summary>
 /// Matches a given shape across the entire genome, adding the necessary posMods and negMods
 /// </summary>
 /// <param name="s">The shape to match across the whole genome</param>
 private void patternMatch(Shape s)
 {
     for (int i = 0; i <= cells.Length - s.sizeRow(); i++)
     {
         for (int j = 0; j <= cells[i].Length - s.sizeCol(); j++)
         {
             if (cellMatch(s, i, j))
             {
                 posMods.AddRange(s.getPosMods());
                 negMods.AddRange(s.getNegMods());
             }
         }
     }
 }
示例#2
0
文件: Gene.cs 项目: OCox1991/Genome
        /// <summary>
        /// Checks if some shape matches at a given location. This is done by checking the next few rows and columns from the
        /// given location and checking they all match the shape.
        /// </summary>
        /// <param name="s">The shape to check</param>
        /// <param name="row">The row of the top left cell to look at</param>
        /// <param name="col">The column of the top left cell to look at</param>
        /// <returns>True if all cells match the given colours of the shape and false otherwise. The colour -1 is used to represent a wildcard</returns>
        private bool cellMatch(Shape s, int row, int col)
        {
            Cell[][] checkCells = new Cell[s.sizeRow()][];
            for (int i = 0; i < s.sizeRow(); i++)
            {
                checkCells[i] = new Cell[s.sizeCol()];
                for (int j = 0; j < s.sizeCol(); j++)
                {
                    checkCells[i][j] = cells[i + row][j + col];
                }
            }
            bool isMatch = true;
            int sizeCol = s.sizeCol();
            int sizeRow = s.sizeRow();

            for (int compCol = 0; compCol < sizeCol; compCol++)
            {
                for (int compRow = 0; compRow < sizeRow; compRow++)
                {
                    if(s.getColour(compRow, compCol) == -1)
                    {
                        //do nothing, -1 represents the wildcard
                    }
                    else if(s.getColour(compRow, compCol) == checkCells[compRow][compCol].getDomColour())
                    {
                        //do nothing, the cells match
                    }
                    else
                    {
                        isMatch = false; //Otherwise they don't match so the shape doesn't match at this location
                    }
                }
            }
            #if DEBUG
            if (isMatch)
            {
            }
            #endif
            return isMatch;
        }