Exemplo n.º 1
0
        static void Main(string[] args)
        {
            FileProcessor fp = new FileProcessor();
            NumberReader  nr = new NumberReader();

            KeyValuePair <Bitmap, string>[] testCases = fp.GetNumberReaderTests();
            foreach (KeyValuePair <Bitmap, string> test in testCases)
            {
                Console.WriteLine("Test: " + test.Value + "");
                Bitmap b = new Bitmap(test.Key);
                Console.WriteLine(nr.ReadFromImage(ref b));
                //Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        private char makeGuess(ref Island island)
        {
            Point[] d = new Point[0];
            NumberReader.PrintIsland(ref island, ref d);

            island.PerimeterFill();
            island.Negate();
            List <Island> inners = island.GetInnerIslands(10);

            if (inners.Count == 0)
            {
                return(' ');
            }
            else if (inners.Count == 1)
            {
                Island inner = inners.First();
                if (inner.Morph.Length > island.Morph.Length / 4)
                {
                    return('0');
                }
                int nearTop = gnInnerNearTop(ref inner, ref island);
                switch (nearTop)
                {
                case 0: return(' ');

                case 1: return('9');

                case -1: return('6');
                }
            }
            else if (inners.Count == 2)
            {
                Island ilA = inners.ElementAt(0);
                Island ilB = inners.ElementAt(1);
                int    ha  = gnInnerNearTop(ref ilA, ref island);
                int    hb  = gnInnerNearTop(ref ilB, ref island);
                if ((ha == 1 && hb == -1) || (ha == -1 && hb == 1))
                {
                    return('8');
                }
            }
            return(' ');
        }
Exemplo n.º 3
0
        private bool gnHasPath(ref Island orig, Point a, Point b)
        {
            bool debug = false;

            if (debug)
            {
                Console.WriteLine("has path" + a + " " + b);
            }

            if (!orig.Morph[a.X, a.Y] || !orig.Morph[b.X, b.Y])
            {
                return(false);
            }

            const int res = 10; // checks along path
            double    dx  = (b.X - a.X) / (double)res;
            double    dy  = (b.Y - a.Y) / (double)res;

            int w = orig.GetWidth(), h = orig.GetHeight();

            if (dx * res < w / 5 && dy * res < h / 5)
            {
                return(false);
            }

            int[,] rad =
            {
                {  0,  0 },
                {  1,  0 }, {  2,  0 },
                {  0,  1 }, {  0,  2 },
                { -1,  0 }, { -2,  0 },
                {  0, -1 }, {  0, -2 }
            };
            int x = 0, y = 0;

            for (int i = 0; i <= res; i++)
            {
                x = a.X + (int)Math.Round(i * dx);
                y = a.Y + (int)Math.Round(i * dy);

                if (debug)
                {
                    Console.WriteLine(x + " " + y);// + "|" + dx + " " + dy);
                    Point[] pts = { a, b, };
                    NumberReader.PrintIsland(ref orig, ref pts, x, y);
                    //debug = !(Console.ReadLine().Contains("x"));
                    string debugL = Console.ReadLine();
                    debug = !debugL.Contains("x");
                }

                bool ok = false;
                for (int s = 0; s < rad.GetLength(0); s++)
                {
                    int tx = x + rad[s, 0], ty = y + rad[s, 1];
                    if (tx >= 0 && ty >= 0 && tx < w && ty < h &&
                        orig.Morph[tx, ty])
                    {
                        ok = true;
                        break;
                    }
                }

                if (!ok)
                {
                    return(false);
                }
            }

            return(true);
        }