Ejemplo n.º 1
0
        public Hall(StreamReader reader, int verbose = 0)
        {
            _verbose = verbose;
            var firstLine = reader.ReadLine().Split(' ');
            _height = int.Parse(firstLine[0]);
            _width = int.Parse(firstLine[1]);
            Distance = int.Parse(firstLine[2]);

            _hall = new Square[_height, _width];
            if (_verbose >= 1)
                Console.WriteLine("Distance max = " + Distance);

            for (int i = 0; i < _height; ++i)
            {
                string curLine = reader.ReadLine();
                if(_verbose >= 1)
                    Console.WriteLine(curLine);

                for (int j = 0; j < _width; j++)
                {
                    switch(curLine[j])
                    {
                        case '#':
                            _hall[i, j] = Square.Mirror;
                            break;
                        case '.':
                            _hall[i, j] = Square.Empty;
                            break;
                        case 'X':
                            _hall[i, j] = Square.Me;
                            Me = new Position(i, j);
                            break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Fuzzy MoveAlong(Direction direction, double step, out Position newPosition)
        {
            // simple case #1 : dx == 0
            if ( direction.Dx == 0 )
            {
                newPosition = new Position(x, y + step * Fuzzy.Sign(direction.Dy));
                return step;
            }

            // simple case #2 : dy == 0
            if ( direction.Dy == 0)
            {
                newPosition = new Position(x + step * Fuzzy.Sign(direction.Dx), y);
                return step;
            }

            var newXOnGrid = GetNextPositionOnGrid(x, direction.Dx, step);
            var newYOnGrid = GetNextPositionOnGrid(y, direction.Dy, step);

            var xMotion = newXOnGrid - x;
            var yMotion = newYOnGrid - y;

            Debug.Assert(Fuzzy.Abs(xMotion) > 0);
            Debug.Assert(Fuzzy.Abs(xMotion) <= 0.5);
            Debug.Assert(Fuzzy.Abs(yMotion) > 0);
            Debug.Assert(Fuzzy.Abs(yMotion) <= 0.5);

            // shorter motion on X axis
            if (xMotion / direction.Dx < yMotion / direction.Dy)
            {
                yMotion = xMotion * direction.Dy / direction.Dx;
                Debug.Assert(Fuzzy.Abs(yMotion) > 0);
                Debug.Assert(Fuzzy.Abs(yMotion) <= 0.5);
            }
            // shorter motion on Y axis
            else if (xMotion / direction.Dx > yMotion / direction.Dy)
            {
                xMotion = yMotion * direction.Dx / direction.Dy;
                Debug.Assert(Fuzzy.Abs(xMotion) > 0);
                Debug.Assert(Fuzzy.Abs(xMotion) <= 0.5);
            }

            Debug.Assert(yMotion / xMotion == direction.Dy / direction.Dx);

            newPosition = new Position(x + xMotion, y + yMotion);

            return Fuzzy.Sqrt(xMotion * xMotion + yMotion * yMotion);
        }
Ejemplo n.º 3
0
 public bool Equals(Position other)
 {
     return x == other.x && y == other.y;
 }
Ejemplo n.º 4
0
 public TestCase(char[,] grid, int maxDistance)
 {
     this.grid = grid;
     this.maxDistance = maxDistance;
     this.startPosition = FindStartPosition(grid);
 }