Esempio n. 1
0
        public object[] GetMatchData(int left, char addc)
        {
            CharData matchData = null;
            CharData nowData   = null;

            char[,] baseTable    = null;
            char[,] baseDirTable = null;
            char[,] dirTable     = null;
            int pointCount = 0;

            int             totalPointCount = 0;
            double          score           = 0.0d;
            HashSet <Point> hitCharPoint    = new HashSet <Point>();
            int             hitTable        = 0;

            double maxScore = double.MinValue;

            baseTable = AAUtil.TrimTable(this.table, 0, left, this.table.GetLength(1), this.charm[this.charm.Count - 1].Width, 1);

            baseDirTable = new PatturnBuilder(baseTable).Patturn;

            for (int i = 0; i < this.charm.Count; i++)
            {
                nowData = this.charm[i];

                //AAUtil.DebugTable(nowData.Patturn);

                //テーブル初期化
                if (i == 0 || this.charm[i - 1].Width != nowData.Width)
                {
                    //baseTable = AAUtil.TrimTable(this.table, 0, left, this.table.GetLength(1), nowData.Width, 1);

                    dirTable = AAUtil.TrimTable(baseDirTable, 0, 0, nowData.Height, nowData.Width, 0);

                    pointCount = 0;

                    for (int y = 0; y < dirTable.GetLength(1); y++)
                    {
                        for (int x = 0; x < dirTable.GetLength(0); x++)
                        {
                            if (dirTable[x, y] != ' ')
                            {
                                pointCount++;
                            }
                        }
                    }


                    //if (i == 0)
                    //{
                    //    AAUtil.DebugTable(this.table);
                    //    AAUtil.DebugTable(baseTable);
                    //    AAUtil.DebugTable(baseDirTable);
                    //    AAUtil.DebugTable(nowData.Patturn);
                    //    AAUtil.DebugTable(nowData.NormalPatturn);
                    //}
                }

                if (i == 0 && pointCount <= 2)
                {
                    return(new object[] { this.charm[' '], 0.0d });
                }

                if (nowData.Character == '|' && addc == '.')
                {
                    continue;
                }

                if (nowData.IsHorizonLine && addc != '\0')
                {
                    continue;
                }

                //if (nowData.IsTarget == true)
                //{
                //    continue;
                //}


                //スコア関連初期化
                score    = 0.0d;
                hitTable = 0;
                hitCharPoint.Clear();
                totalPointCount = (nowData.PointNormalCount * 5 + pointCount * 3);

                if (totalPointCount == 0)
                {
                    continue;
                }

                //パターンマッチング
                int height = dirTable.GetLength(1);
                int width  = dirTable.GetLength(0);

                int matchAreaX = 0;
                int matchAreaY = 0;

                if (cm.Match == 1)
                {
                    matchAreaX = 1;
                    matchAreaY = 1;
                }
                else if (cm.Match == 2)
                {
                    matchAreaX = 2;
                    matchAreaY = 2;
                }
                else
                {
                    matchAreaX = 3;
                    matchAreaY = 3;
                }

                bool         isHit1;
                List <Point> lstPoint;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (dirTable[x, y] == ' ')
                        {
                            continue;
                        }



                        isHit1 = false;

                        lstPoint = nowData.GetDirPoint('N');

                        foreach (Point p in lstPoint)
                        {
                            if (Math.Abs(p.X - x) <= matchAreaX && Math.Abs(p.Y - y) <= matchAreaY)
                            {
                                if (!isHit1)
                                {
                                    isHit1 = true;

                                    hitTable += 2;
                                }

                                if (!hitCharPoint.Contains(p))
                                {
                                    hitCharPoint.Add(p);
                                    hitTable++;

                                    // Debug.WriteLine(p);

                                    goto LOOP_END;
                                }
                            }
                        }

LOOP_END:

                        ;
                    }
                }

                score = Convert.ToDouble((hitTable + hitCharPoint.Count * 5)) / Convert.ToDouble(totalPointCount) * 100;

                if (maxScore < score)
                {
                    maxScore  = score;
                    matchData = nowData;

                    if (maxScore >= this.cm.Score4)
                    {
                        return(new object[] { matchData, maxScore });
                    }
                }
            }

            if (maxScore < this.cm.Score3)
            {
                return(new object[] { this.charm[' '], 0.0d });
            }

            if (matchData == null)
            {
                return(new object[] { this.charm[' '], 0.0d });
            }

            return(new object[] { matchData, maxScore });
        }
Esempio n. 2
0
        public CharData(char c, Font f, int pitch)
        {
            this.character = c;

            this.isTarget = c == '.' || c == ' ' ? false : true;

            PatturnBuilder pb = new PatturnBuilder(c, f, pitch);

            this.patturn = pb.Patturn;

            this.width  = this.patturn.GetLength(0);
            this.height = this.patturn.GetLength(1);

            this.dirPoint = new Dictionary <char, List <Point> >();

            for (int dir = 0; dir < 10; dir++)
            {
                this.dirPoint[Convert.ToString(dir)[0]] = new List <Point>();
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (this.patturn[x, y] != ' ' && this.patturn[x, y] != '0')
                    {
                        pcount++;

                        char dir = Convert.ToString(this.patturn[x, y])[0];

                        this.dirPoint[dir].Add(new Point(x, y));
                    }
                }
            }

            foreach (char key in this.dirPoint.Keys)
            {
                this.dirPoint[key].Sort(new Sorter());
            }

            int normalCount = 0;

            for (int y = 0; y < pb.NormalData.GetLength(1); y++)
            {
                for (int x = 0; x < pb.NormalData.GetLength(0); x++)
                {
                    if (pb.NormalData[x, y] == '■')
                    {
                        normalCount++;
                    }
                }
            }

            int thinCount = 0;

            for (int y = 0; y < pb.ThinData.GetLength(1); y++)
            {
                for (int x = 0; x < pb.ThinData.GetLength(0); x++)
                {
                    if (pb.ThinData[x, y] == '■')
                    {
                        thinCount++;
                    }
                }
            }

            if (thinCount <= 2 || normalCount <= 2)
            {
                //AAUtil.DebugTable(pb.NormalData);
                //AAUtil.DebugTable(pb.ThinData);

                this.isTarget = false;
            }
            else if (thinCount * 100 / normalCount < 70)
            {
                //AAUtil.DebugTable(pb.NormalData);
                //AAUtil.DebugTable(pb.ThinData);

                this.isTarget = false;
            }

            this.pcountNormal = normalCount;

            int addY = -1;
            int addX = -1;

            this.normalPatturn = new char[pb.NormalData.GetLength(0) - 2, pb.NormalData.GetLength(1) - 2];

            List <Point> lst = new List <Point>();

            for (int y = 0; y < pb.NormalData.GetLength(1); y++)
            {
                for (int x = 0; x < pb.NormalData.GetLength(0); x++)
                {
                    if (x + addX < 0 || y + addY < 0 || x + addX >= this.normalPatturn.GetLength(0) || y + addY >= this.normalPatturn.GetLength(1))
                    {
                        continue;
                    }

                    if (pb.NormalData[x, y] == '■')
                    {
                        this.normalPatturn[x + addX, y + addY] = '■';
                        lst.Add(new Point(x + addX, y + addY));
                    }
                    else
                    {
                        this.normalPatturn[x + addX, y + addY] = '□';
                    }
                }
            }

            this.dirPoint['N'] = lst;

            if (this.dirPoint['N'].Count > 0 && this.dirPoint['1'].Count * 100 / this.dirPoint['N'].Count > 75)
            {
                this.isHLine = true;
            }
        }