Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.07 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace vyjezd
  6. {
  7.     static class Globals
  8.     {
  9.         public static Node[,] node2DArray;
  10.         public static int gridHeight;
  11.         public static int gridWidth;
  12.             //pocet rozbitych krizovatek (dodelat)
  13.         public static int startY;
  14.         public static int startX;
  15.         public static int finishY;
  16.         public static int finishX;
  17.         public static int brokenNodeX; //tech bude vic, podle poctu broken krizovatek loopovat
  18.         public static int brokenNodeY;
  19.         public static int i;
  20.         public static int y;
  21.         public static Queue queue = new Queue();
  22.     }
  23.     class Node
  24.     {
  25.         //int x;
  26.         //int y;
  27.         public bool isBroken = false;
  28.         public bool wasVisited = false;
  29.         public int minDistance = Int32.MaxValue; //zvetsi se oo jedno kazdym stepem zacina na nule
  30.         public List<int[]> neighboursXandYcoords = new List<int[]>();
  31.         //Queue queue = new Queue();
  32.  
  33.         Node()
  34.         {
  35.  
  36.         }
  37.  
  38.         public void FindNeighbours()
  39.         {
  40.             if (Globals.node2DArray[Globals.i - 1, Globals.y]!=null) //top one
  41.             {
  42.                
  43.                 neighboursXandYcoords.Add(new int[] { Globals.i - 1, Globals.y });
  44.             }
  45.             if (Globals.node2DArray[Globals.i + 1, Globals.y] != null) //bottom one
  46.             {
  47.                 neighboursXandYcoords.Add(new int[] { Globals.i - 1, Globals.y });
  48.             }
  49.             if (Globals.node2DArray[Globals.i, Globals.y -1] != null) //left one
  50.             {
  51.                 neighboursXandYcoords.Add(new int[] { Globals.i, Globals.y - 1 });
  52.             }
  53.             if (Globals.node2DArray[Globals.i, Globals.y + 1] != null) //right one
  54.             {
  55.                 neighboursXandYcoords.Add(new int[] { Globals.i, Globals.y + 1 });
  56.             }
  57.         }
  58.  
  59.         public void CheckNeighbours()
  60.         {
  61.             wasVisited = true;
  62.             for (int i=0; i < neighboursXandYcoords.Count; i++)
  63.             {
  64.                 if (Globals.node2DArray[neighboursXandYcoords[i][0], neighboursXandYcoords[i][1]].wasVisited == false)
  65.                 {
  66.                     Globals.node2DArray[neighboursXandYcoords[i][0], neighboursXandYcoords[i][1]].wasVisited = true;
  67.                     Globals.node2DArray[neighboursXandYcoords[i][0], neighboursXandYcoords[i][1]].minDistance = minDistance+1;
  68.                     Globals.queue.Enqueue(new int[] { neighboursXandYcoords[i][0], neighboursXandYcoords[i][1] });
  69.  
  70.                 }
  71.             }
  72.         }
  73.  
  74.     }
  75.     class Program
  76.     {
  77.         static void Main(string[] args)
  78.         {
  79.             //otevrit soubor
  80.             //precist pocet zadani (dodelat)
  81.             //precist vysku gridu
  82.             Globals.gridHeight = 3;
  83.             Globals.gridWidth = 3;
  84.             Globals.node2DArray = new Node[Globals.gridWidth, Globals.gridHeight]; //sirka x vyska
  85.             //pocet rozbitych krizovatek (dodelat)
  86.             Globals.startY = 1;
  87.             Globals.startX = 2;
  88.             Globals.finishY = 1;
  89.             Globals.finishX = 1;
  90.             Globals.brokenNodeX = 2; //tech bude vic, podle poctu broken krizovatek loopovat
  91.             Globals.brokenNodeY = 2;
  92.             Globals.node2DArray[Globals.brokenNodeX, Globals.brokenNodeY].isBroken = true;
  93.  
  94.            
  95.  
  96.             for (int i = 0; i< Globals.gridWidth; i++)
  97.             {
  98.                 for (int y = 0; y< Globals.gridHeight; y++)
  99.                 {
  100.                     Globals.i = i;
  101.                     Globals.y = y;
  102.                     Globals.node2DArray[Globals.i, Globals.y].FindNeighbours();
  103.                     //Globals.queue.Enqueue(Globals.node2DArray[i, y]);
  104.                 }
  105.             }
  106.  
  107.             Globals.node2DArray[Globals.startX, Globals.startY].minDistance = 0;
  108.             Globals.node2DArray[Globals.startX, Globals.startY].CheckNeighbours();
  109.             //queue
  110.            
  111.            
  112.             Console.WriteLine("Hello World!");
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement