Ejemplo n.º 1
0
        public static List<Cube> ReaderSmallCubes()
        {
            var answer = new List<Cube>();
            numOfCubes = int.Parse(Console.ReadLine());

            for (var i = 1; i <= numOfCubes; i++)
            {
                var cube = new Cube(Console.ReadLine(), i);
                answer.Add(cube);
                cubes[i] = cube;
            }
            return answer;
        }
Ejemplo n.º 2
0
 private int ShowPlaceForEdgeOnDirect(Cube cube, Directions direct)
 {
     var sizeOnCurrentDirect = cube.ShowSizes[direct];
     return
         PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect].Keys.First(
             place => PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect][place] != 0);
 }
Ejemplo n.º 3
0
        private void TakePlaceOnDirectForEdges(Cube cube, Directions direct)
        {
            var sizeOnCurrentDirect = cube.ShowSizes[direct];
            var placeOnCurrentDirect = cube.Place[direct];

            if (!PlaceForSizeForExistingSquare[direct].ContainsKey(sizeOnCurrentDirect))
            {
                PlaceForSizeForExistingSquare[direct].Add(sizeOnCurrentDirect, new Dictionary<int, int>());
            }

            if (PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect].ContainsKey(placeOnCurrentDirect))
            {
                PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect][placeOnCurrentDirect] -= 1;
            }
            else
            {
                PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect].Add(placeOnCurrentDirect,
                                                                               DimensionCoeficient - 1);
            }
        }
Ejemplo n.º 4
0
        private bool IsExistPlaceForEdge(Cube cube, Directions direct)
        {
            var sizeOnCurrentDirect = cube.ShowSizes[direct];
            //            var placeOnCurrentDirect = cube.Place[direct];

            if (!PlaceForSizeForExistingSquare[direct].ContainsKey(sizeOnCurrentDirect))
            {
                return false;
            }
            if (
                PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect].Keys.Any(
                    place => PlaceForSizeForExistingSquare[direct][sizeOnCurrentDirect][place] != 0))
            {
                return true;
            }
            return false;
        }
Ejemplo n.º 5
0
        public bool TryTakePlace(Cube cube)
        {
            var sizeVector = cube.GetSizeState();

            var posiblePoints = getUnbusyPoint(sizeVector);

            if (posiblePoints == null) return false;

            var counter = 0;
            Directions intrestingDirect = Directions.Top;

            int[] goodPoint=null;
             foreach (var posiblePoint in posiblePoints)
            {
                var flag = true;
                goodPoint = posiblePoint;
                for (int i = 0; i < 3; i++)
                {
                    if (cube.Place.ContainsKey(CubeUtils.ZeroSides[i]))
                    {
                        if (posiblePoint[i] != cube.Place[CubeUtils.ZeroSides[i]])
                        {
                            goodPoint = null;
                            flag = false;
                        }
                    }
                    if (posiblePoint[i] < 0)
                    {
                        goodPoint = null;
                        flag = false;
                    }

                }
                if (flag) break;
            }

            if (goodPoint!=null){
            //                var goodPoint = posiblePoints.Find(place => place[counter].Equals(cube.Place[intrestingDirect]));
                posiblePoints.Remove(goodPoint);
                for (int i = 0; i < 3; i++)
                {
                    if (!cube.Place.ContainsKey(CubeUtils.ZeroSides[i]))
                    {
                        cube.Place.Add(CubeUtils.ZeroSides[i], goodPoint[i]);
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 6
0
        public void placeMeByOrder(Cube cube)
        {
            foreach (var direct in CubeUtils.ZeroSides)
            {
                if (!cube.Place.ContainsKey(direct))
                {
                    var sizeOnDirect = cube.ShowSizes[direct];

                    int chosenPlace;
                    if (IsExistPlaceForEdge(cube, direct))//Основная ошибка здесь. Связана с тем, что система не видит разницы между разными рёбрами и может попытаться перекинуть куб из одного ребра в другое, произойдёт коллизия, которая не отслеживается. Нужно привязать поиск свободного места к конктерному ребру.
                    {
                        chosenPlace = ShowPlaceForEdgeOnDirect(cube, direct);

                        cube.Place.Add(direct, chosenPlace);
                        TakePlaceOnDirectForEdges(cube, direct);

                        return;
                    }

                    chosenPlace = nextForExistingSquare[direct];

                    nextForExistingSquare[direct] += sizeOnDirect;

                    cube.Place.Add(direct, chosenPlace);
                    TakePlaceOnDirectForEdges(cube, direct);

                    return;
                }
            }
        }
Ejemplo n.º 7
0
        public void placeMeByColor(Cube cube)
        {
            var sideAgregator = new Dictionary<Directions, int>();
            for (int i = 0; i < 6; i++)
            {
                var side = CubeUtils.Order[i];
                sideAgregator.Add(side, -1);
                if (cube.IsColored(side))
                {
                    sideAgregator[side] = 1;
                }
            }

            var places = cube.Place;

            for (int i = 0; i < 6; i += 2)
            {
                var side = CubeUtils.Order[i];
                if (sideAgregator[CubeUtils.ReverseDirection(side)] == 1)
                {
                    places.Add(side, this.Sizes[side] - cube.ShowSizes[side]);
                }
                if (sideAgregator[side] == 1)
                {
                    if (!places.ContainsKey(side))
                    {
                        places.Add(side, 0);
                    }
                    else
                    {
                        places[side] = 0;
                    }
                }
            }
        }
Ejemplo n.º 8
0
 public void DesignateStartpointsForAngles(Cube cube)
 {
     foreach (var direct in CubeUtils.ZeroSides)
     {
         var currentSize = cube.ShowSizes[direct];
         if (!PlaceForSizeForExistingSquare[direct].ContainsKey(currentSize))
         {
             PlaceForSizeForExistingSquare[direct].Add(currentSize, new Dictionary<int, int>());
         }
         if (!PlaceForSizeForExistingSquare[direct][currentSize].ContainsKey(cube.Place[direct]))
         {
             PlaceForSizeForExistingSquare[direct][currentSize].Add(cube.Place[direct], 0);
         }
         if (nextForExistingSquare[direct] == 0 ||
             nextForExistingSquare[direct] > cube.ShowSizes[direct] + cube.Place[direct])
             nextForExistingSquare[direct] = cube.ShowSizes[direct];
     }
 }