Exemple #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;
            }
        }
Exemple #2
0
 // Deep copy passed vehicle
 public Vehicle(Vehicle vehicle)
 {
     this.length = vehicle.length;
     this.direction = vehicle.direction;
     this.identity = vehicle.identity;
     this.startPos = vehicle.startPos;
 }
Exemple #3
0
 public Move(Vehicle v, int delta)
 {
     this.movingVehicle = v;
     this.delta = delta;
 }
Exemple #4
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;
                }
            }
        }
Exemple #5
0
        List<Move> getMovesForVehicle(Vehicle v)
        {
            List<Move> moves = new List<Move>();

            // Check left/up
            int delta = -1;
            Move move = new Move(v, delta);
            while(this.IsInBounds(move) && !this.IsOccupied(move))
            {
                moves.Add(move);

                delta--;
                move = new Move(v, delta);
            }

            // Check right/down
            delta = 1;
            move = new Move(v, delta);
            while (this.IsInBounds(move) && !this.IsOccupied(move))
            {
                moves.Add(move);

                delta++;
                move = new Move(v, delta);
            }

            return moves;
        }