Esempio n. 1
0
        // Deep copy board
        public Board(Board board)
        {
            this.game = board.game;

            foreach (KeyValuePair<char, Vehicle> pair in board.vehicles)
            {
                this.vehicles[pair.Key] = pair.Value.Copy();
            }
            this.ownVehicle = this.vehicles['x'];

            this.board = new Vehicle[board.board.GetLength(0), board.board.GetLength(1)];

            for (int x = 0; x < board.board.GetLength(0); x++)
            {
                for (int y = 0; y < board.board.GetLength(1); y++)
                {
                    Vehicle v = board.board[x, y];
                    if (v != null)
                    {
                        v = this.vehicles[v.identity];
                    }
                    this.board[x, y] = v;
                }
            }

            switch (game.outputMode)
            {
                case Game.OutputMode.Solve:
                    this.appliedMoves.AddRange(board.appliedMoves);
                    break;
                case Game.OutputMode.Count:
                    this.generation = board.generation + 1;
                    break;
            }
        }
Esempio n. 2
0
        public Board(Game game, string[] boardString)
        {
            this.game = game;

            this.board = new Vehicle[boardString[0].Length, boardString.Length];

            for (int y = 0; y < boardString.Length; y++)
            {
                string s = boardString[y];

                for (int x = 0; x < s.Length; x++){
                    char c = s[x];

                    Vehicle v;
                    if (c == '.')
                    {
                        v = null;
                    }
                    else if (this.vehicles.ContainsKey(c))
                    {
                        v = this.vehicles[c];
                        v.length++;
                        if (x == v.startPos.X)
                        {
                            v.direction = Vehicle.Direction.Vertical;
                        }
                        else if (y == v.startPos.Y)
                        {
                            v.direction = Vehicle.Direction.Horizontal;
                        }
                    }
                    else
                    {
                        v = new Vehicle(c, x, y);
                        this.vehicles[c] = v;
                        if (c == 'x')
                        {
                            this.ownVehicle = v;
                        }
                    }
                    this.board[x, y] = v;
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Game.OutputMode outputMode = (Game.OutputMode)int.Parse(Console.ReadLine());
            int boardHeight = int.Parse(Console.ReadLine());

            int yTarget = int.Parse(Console.ReadLine());
            int xTarget = int.Parse(Console.ReadLine());

            Position targetPos = new Position(xTarget, yTarget);

            string[] boardString = new string[boardHeight];

            for (int i = 0; i < boardHeight; i++)
            {
                boardString[i] = Console.ReadLine();
            }

            for (int threadCount = 4; threadCount <= 4; threadCount += 2)
            {
                Console.WriteLine(threadCount);
                System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                stopWatch.Start();

                for (int i = 0; i < 100; i++)
                {
                    Game g = new Game(outputMode, targetPos, boardString);
                    g.Start(threadCount);
                }

                stopWatch.Stop();

                TimeSpan ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                    ts.Hours, ts.Minutes, ts.Seconds,
                    ts.Milliseconds / 10);
                Console.WriteLine("RunTime " + elapsedTime);
            }

            Console.ReadKey();
        }