//[TestMethod]
        public void TestMethod1()
        {
            int inputCount = 0;

            bool[,] matrix = new bool[3, 3];
            LinkedList <string> outputs       = new LinkedList <string>();
            LinkedList <string> inputs        = new LinkedList <string>();
            GopherManager       gopherManager = new GopherManager(3, () => GetInput(inputs),
                                                                  delegate(string output)
            {
                var spliParts = output.Split(' ');
                var numbers   = spliParts.Select(s => int.Parse(s)).ToArray();
                var column    = numbers[1] - 500 == -1 ? 0 : (numbers[1] - 500 == 0 ? 1 : 2);
                var row       = numbers[0];
                var result    = "";
                if (matrix[row - 1, column])
                {
                    if (!matrix[row - 1, 0])
                    {
                        result             = "" + row + " " + 499;
                        matrix[row - 1, 0] = true;
                    }
                    else if (!matrix[row - 1, 1])
                    {
                        result             = "" + row + " " + 500;
                        matrix[row - 1, 1] = true;
                    }
                    else
                    {
                        result             = "" + row + " " + 501;
                        matrix[row - 1, 2] = true;
                    }
                }
                else
                {
                    result = "" + row + " " + (column == 0 ? 499 : (column == 1 ? 500 : 501));
                    matrix[row - 1, column] = true;
                }

                if (AllFalse(matrix))
                {
                    inputs.AddLast("0 0");
                }
                else
                {
                    inputs.AddLast(result);
                    inputCount++;
                }
            });

            gopherManager.Start();
            Assert.IsTrue(gopherManager.Finished);
        }
Exemple #2
0
    public static void Main(string[] args)
    {
        var line = Console.ReadLine();
        int T    = int.Parse(line);

        for (int i = 1; i <= T; i++)
        {
            int           A             = int.Parse(Console.ReadLine());
            GopherManager gopherManager = new GopherManager(A, () => Console.ReadLine(), (s) => Console.WriteLine(s));
            if (gopherManager.Start() == Response.SomeThingWrong)
            {
                break;
            }
        }
    }
        public void TestMethod2()
        {
            LinkedList <string> inputs = new LinkedList <string>();

            bool[,] matrix = null;
            GopherManager gopherManager = new GopherManager(3, delegate()
            {
                var result = inputs.First.Value; inputs.RemoveFirst(); return(result);
            }, delegate(string output)
            {
                int[] numbers = GetNumbers(output);
                int i         = numbers[0];
                int j         = numbers[1];
                Assert.AreNotEqual(i, 1);
                Assert.AreNotEqual(j, 1);

                if (i <= rowMin || i >= rowMax || j != columnCenter)
                {
                    throw new Exception();
                }

                var newT       = GetRandom(new Tuple <int, int>(i, j));
                int iM         = newT.Item1 - rowMin;
                int jM         = newT.Item2 == 499 ? 0 : (newT.Item2 == 500 ? 1 : 2);
                matrix[iM, jM] = true;

                if (AllFalse(matrix))
                {
                    inputs.AddLast("0 0");
                }
                else
                {
                    inputs.AddLast(newT.Item1 + " " + newT.Item2);
                }
            });

            rowMin       = gopherManager.MinRow;
            rowMax       = gopherManager.MaxRow;
            columnCenter = gopherManager.ColumnCenter;
            matrix       = new bool[rowMax - rowMin + 1, 3];

            gopherManager.Start();
            Assert.IsTrue(gopherManager.Finished);
        }