Exemple #1
0
        /// <summary>
        /// Konstruktor okna głównego
        /// </summary>
        int GetNeighboursCount(Neighbourhoods _neighbourhood, int Size)
        {
            switch (_neighbourhood)
            {
            case Neighbourhoods.Mixed:
                return(GetNeighboursCount(Neighbourhoods.Moore, Size) + GetNeighboursCount(Neighbourhoods.VonNeumann, Size));

            case Neighbourhoods.Moore:
                return((2 * Size + 1) * (2 * Size + 1) - 1);

            case Neighbourhoods.VonNeumann:
                return(4 * Size);

            case Neighbourhoods.Taxi:
                return(2 * Size * (Size + 1));
            }
            throw new ArgumentException("Unrecognisable neighbourhood");
        }
Exemple #2
0
        INeighbourhood GetNeighbourhood(Neighbourhoods _neighbourhood, Shape _shape, int Size, int _width, int _height)
        {
            switch (_neighbourhood)
            {
            case Neighbourhoods.Mixed:
                return
                    (new Mixed(GetNeighbourhood(Neighbourhoods.Moore, _shape, Size, _width, _height), GetNeighbourhood(Neighbourhoods.VonNeumann, _shape, Size, _width, _height)));

            case Neighbourhoods.Moore:
                switch (_shape)
                {
                case Shape.Płaski:
                    return(new Moore(_width, _height, Size));

                case Shape.Torus:
                    return(new MooreTorus(_width, _height, Size));
                }
                break;

            case Neighbourhoods.VonNeumann:
                switch (_shape)
                {
                case Shape.Płaski:
                    return(new VonNeumann(_width, _height, Size));

                case Shape.Torus:
                    return(new VonNeumannTorus(_width, _height, Size));
                }
                break;

            case Neighbourhoods.Taxi:
                switch (_shape)
                {
                case Shape.Płaski:
                    return(new Taxi(_width, _height, Size));

                case Shape.Torus:
                    return(new TaxiTorus(_width, _height, Size));
                }
                break;
            }
            throw new ArgumentException("Unrecognisable neighbourhood");
        }
        public async Task <IActionResult> Create([Bind("NeighbourhoodId,NeighbourhoodNaming")] Neighbourhoods neighbourhoods)
        {
            if (ModelState.IsValid)
            {
                if (_context.Neighbourhoods.Where(pr => pr.NeighbourhoodNaming == neighbourhoods.NeighbourhoodNaming).Count() == 0)

                {
                    _context.Add(neighbourhoods);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError("", "Sorry! Doublicate error!");
                }
            }

            return(View(neighbourhoods));
        }
        public async Task <IActionResult> Edit(int id, [Bind("NeighbourhoodId,NeighbourhoodNaming")] Neighbourhoods neighbourhoods)
        {
            if (id != neighbourhoods.NeighbourhoodId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (_context.Neighbourhoods.Where(pr => pr.NeighbourhoodNaming == neighbourhoods.NeighbourhoodNaming).Count() == 0)

                {
                    try
                    {
                        _context.Update(neighbourhoods);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!NeighbourhoodsExists(neighbourhoods.NeighbourhoodId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Sorry! Doublicate error!");
                }
            }
            return(View(neighbourhoods));
        }
Exemple #5
0
 public bool AreNeighbours(int n1, int n2)
 {
     return(Neighbourhoods.Any(t => t.Item1 == n1 && t.Item2 == n2) || Neighbourhoods.Any(t => t.Item1 == n2 && t.Item2 == n1));
 }
Exemple #6
0
 public int DegreeOf(int i)
 {
     return(Neighbourhoods.Count(t => t.Item1 == i || t.Item2 == i));
 }
Exemple #7
0
 /// <summary>
 /// Konstruktor okna głównego
 /// </summary>
 int GetNeighboursCount(Neighbourhoods _neighbourhood, int Size)
 {
     switch (_neighbourhood)
     {
         case Neighbourhoods.Mixed:
             return GetNeighboursCount(Neighbourhoods.Moore, Size) + GetNeighboursCount(Neighbourhoods.VonNeumann, Size);
         case Neighbourhoods.Moore:
             return (2 * Size + 1) * (2 * Size + 1) - 1;
         case Neighbourhoods.VonNeumann:
             return 4 * Size;
         case Neighbourhoods.Taxi:
            return 2*Size*(Size + 1);
     }
     throw new ArgumentException("Unrecognisable neighbourhood");
 }
Exemple #8
0
 INeighbourhood GetNeighbourhood(Neighbourhoods _neighbourhood, Shape _shape, int Size, int _width, int _height)
 {
     switch (_neighbourhood)
     {
         case Neighbourhoods.Mixed:
             return
                 new Mixed(GetNeighbourhood(Neighbourhoods.Moore, _shape, Size,_width,_height), GetNeighbourhood(Neighbourhoods.VonNeumann, _shape, Size,_width,_height));
         case Neighbourhoods.Moore:
             switch (_shape)
             {
                 case Shape.Płaski:
                     return new Moore(_width, _height, Size);
                 case Shape.Torus:
                     return new MooreTorus(_width, _height, Size);
             }
             break;
         case Neighbourhoods.VonNeumann:
             switch (_shape)
             {
                 case Shape.Płaski:
                     return new VonNeumann(_width, _height, Size);
                 case Shape.Torus:
                     return new VonNeumannTorus(_width, _height, Size);
             }
             break;
         case Neighbourhoods.Taxi:
             switch (_shape)
             {
                 case Shape.Płaski:
                     return new Taxi(_width, _height, Size);
                 case Shape.Torus:
                     return new TaxiTorus(_width, _height, Size);
             }
             break;
     }
     throw new ArgumentException("Unrecognisable neighbourhood");
 }