コード例 #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
        public static void loadFromFile(string sourceFile)
        {
            Logger.Info($"Reading char groups in file {sourceFile}");
            Logger.Push();
            try
            {
                StreamReader reader = new StreamReader(sourceFile);

                while (true)
                {
                    String groupname = reader.ReadLine();
                    String charList  = reader.ReadLine();

                    int groupId = CharGroups.addGroup(groupname);
                    Logger.Info($"Creating groups {groupname}");
                    foreach (char v in charList)
                    {
                        CharGroups.addCharacterGroup(v, groupId);
                    }
                }
            }
            catch (Exception)
            {
                // do nothing
            }
            Logger.Pop();
        }
コード例 #3
0
        /// <summary>
        /// indicate if a characters belongs to a group
        /// </summary>
        /// <param name="character">the character to check</param>
        /// <param name="group"></param>
        /// <returns></returns>
        static public Boolean areSameGroup(Char character, int group, bool strict = false)
        {
            if (character == '?' && !strict)
            {
                return(true);
            }
            int g1 = CharGroups.getCharacterGroups(character);

            return((g1 & group) > 0);
        }
コード例 #4
0
        /// <summary>
        /// Check to see if 2 characters have a common group
        /// </summary>
        /// <param name="c1"></param>
        /// <param name="c2"></param>
        /// <returns>true if a groups belongs to both characters</returns>
        static public bool areSameGroup(Char c1, Char c2, bool strict = false)
        {
            if ((c1 == '?' || c2 == '?') && !strict)
            {
                return(true);
            }
            int g1 = CharGroups.getCharacterGroups(c1);
            int g2 = CharGroups.getCharacterGroups(c2);

            return((g1 & g2) > 0);
        }
コード例 #5
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);
        }