Exemplo n.º 1
0
        public void Clone()
        {
            Position position = new Position();

            position.PutNumberAt(1, 0, 0);
            position.PutNumberAt(2, 1, 0);
            position.PutNumberAt(3, 2, 0);

            position.PutNumberAt(3, 3, 3);
            position.PutNumberAt(4, 4, 3);
            position.PutNumberAt(5, 5, 3);

            position.PutNumberAt(6, 6, 6);
            position.PutNumberAt(7, 7, 6);
            position.PutNumberAt(8, 8, 6);

            Position newposition = position.Clone();

            Assert.AreEqual(position.Size, newposition.Size);
            Assert.AreEqual(position.Range, newposition.Range);

            for (int x = 0; x < position.Size; x++)
                for (int y = 0; y < position.Size; y++)
                    Assert.AreEqual(newposition.GetNumberAt(x, y), position.GetNumberAt(x, y));
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            string gametxt = args[0];
            Position position = new Position(gametxt);

            positions.Push(position);

            while (positions.Count > 0)
            {
                position = positions.Pop();

                DumpPosition(position);

                CellInfo ci = solver.Resolve(position);

                while (ci != null)
                {
                    System.Console.WriteLine(String.Format("{0} at {1} {2}", ci.Number, ci.X + 1, ci.Y + 1));

                    position.PutNumberAt(ci.Number, ci.X, ci.Y);
                    DumpPosition(position);

                    ci = solver.Resolve(position);
                }

                if (position.Solved)
                    break;

                List<List<CellInfo>> results = solver.GetPossibleMoves(position);

                if (results.Count == 0)
                {
                    System.Console.WriteLine("No Branch");
                    continue;
                }

                bool hasbranches = false;

                foreach (List<CellInfo> cells in results)
                {
                    if (cells.Count != 2)
                        continue;

                    foreach (CellInfo cell in cells)
                    {
                        System.Console.WriteLine(String.Format("Branch {0} at {1} {2}", cell.Number, cell.X + 1, cell.Y + 1));
                        Position newposition = position.Clone();
                        newposition.PutNumberAt(cell.Number, cell.X, cell.Y);
                        DumpPosition(newposition);
                        positions.Push(newposition);
                    }

                    hasbranches = true;

                    break;
                }

                if (!hasbranches)
                    System.Console.WriteLine("No Branch 2");
            }

            System.Console.ReadLine();
        }