public void RushHour_CreateCarHorizontal()
 {
     var c = new Car(3, 5, 3, 8);
     Assert.IsTrue(c.Equals(new Car(new int[] { 3, 5, 3, 8 })));
     Assert.AreEqual(c.Street, 3);
     Assert.AreEqual(c.Position, 5);
     Assert.AreEqual(c.Length, 4);
     Assert.AreEqual(c.Orientation, CarOrientation.Vertical);
 }
 public void RushHour_CreateCarVertical()
 {
     var c = new Car(3, 2, 4, 2);
     Assert.IsTrue(c.Equals(new Car(new int[] { 3, 2, 4, 2 })));
     Assert.AreEqual(c.Position, 3);
     Assert.AreEqual(c.Street, 2);
     Assert.AreEqual(c.Length, 2);
     Assert.AreEqual(c.Orientation, CarOrientation.Horizontal);
 }
        public static RushHourDefinition FromTutor(IList<string> definition)
        {
            var result = new RushHourDefinition();

            if (definition == null || definition.Count < 1 || definition.Count > MaximalSize)
            {
                throw new ArgumentException("Invalid input format. Argument is null or the number of lines is invalid.");
            }

            result.Size = new[] { definition.Count - 2, definition[0].Length - 2 };

            Func<int, int, int> min = (i, j) => i > j ? j : i;
            Func<int, int, int> max = (i, j) => i > j ? i : j;
            Func<int, int, int[], int[]> update = (i, j, act) => new int[] { min(i, act[0]), min(j, act[1]), max(i, act[2]), max(j, act[3]) };

            var cars = new int[256][];
            for (var i = 0; i < result.Size[0] + 2; i++)
            {
                for (var j = 0; j < result.Size[1] + 2; j++)
                {
                    var c = definition[i][j];
                    switch (c)
                    {
                        case 'E':
                            result.Exit = (i == 0) ? ExitPosition.Up :
                                (i == result.Size[0] + 1) ? ExitPosition.Down :
                                (j == 0) ? ExitPosition.Left : ExitPosition.Right;
                            break;
                        case '-':
                        case '#':
                            break;
                        default:
                            cars[c] = update(j - 1, i - 1, cars[c] ?? new int[] { j - 1, i - 1, j - 1, i - 1 });
                            break;
                    }
                }
            }
            // set RedCar and Cars
            Assert.IsNotNull(cars['x'], "No red car in given instance.");
            var redCar = new Car(cars['x']);
            cars['x'] = null;

            result.Cars = cars.Where(car => car != null).Select(data => new Car(data)).ToList();
            result.Cars.Insert(0, redCar);
            result.InitialState = new RushHourState(result.Cars.Select(c => c.Position).ToList());
            return result;
        }