示例#1
0
        /// <summary>
        /// check a given template against a given position in a map and return true if the template matche.
        /// </summary>
        /// <param name="map">The map to  check the template against</param>
        /// <param name="pattern">The template to check</param>
        /// <param name="xpos">X position</param>
        /// <param name="ypos">Y position</param>
        /// <returns>true if the template Matches, false otherwise</returns>
        public static bool FullMatch(char[,] map, char[,] pattern, int xpos, int ypos)
        {
            bool match = false;

            if ((xpos + pattern.GetLength(1) - 1 >= map.GetLength(1)) || (ypos + pattern.GetLength(0) - 1 >= map.GetLength(0)))
            {
                return(false);
            }

            if ((xpos < 0) || (ypos < 0))
            {
                return(false);
            }

            bool value = true;

            // check the template
            for (int y2 = 0; y2 < pattern.GetLength(0); y2++)
            {
                for (int x2 = 0; x2 < pattern.GetLength(1); x2++)
                {
                    if (!(pattern[y2, x2] == '?' || map[ypos + y2, xpos + x2] == '?'))
                    {
                        match = CharGroups.areSameGroup(pattern[y2, x2], map[ypos + y2, xpos + x2]);
                        if (!match)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(value);
        }
示例#2
0
        static public String getGroupName(int group)
        {
            String name;

            // if it's a single group
            if (groupNames.TryGetValue(group, out name))
            {
                return(name);
            }
            // otherwise, check each group in the name list for those who are in the given group
            Dictionary <int, String> .KeyCollection keys = groupNames.Keys;
            foreach (int key in keys)
            {
                if (CharGroups.areSameGroup(key, group))
                {
                    name = name + " " + groupNames[key];
                }
            }
            return(name);
        }