Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace vyjezd
- {
- static class Globals
- {
- public static Node[,] node2DArray;
- public static int gridHeight;
- public static int gridWidth;
- //pocet rozbitych krizovatek (dodelat)
- public static int startY;
- public static int startX;
- public static int finishY;
- public static int finishX;
- public static int brokenNodeX; //tech bude vic, podle poctu broken krizovatek loopovat
- public static int brokenNodeY;
- public static int i;
- public static int y;
- public static Queue queue = new Queue();
- }
- class Node
- {
- //int x;
- //int y;
- public bool isBroken = false;
- public bool wasVisited = false;
- public int minDistance = Int32.MaxValue; //zvetsi se oo jedno kazdym stepem zacina na nule
- public List<int[]> neighboursXandYcoords = new List<int[]>();
- //Queue queue = new Queue();
- Node()
- {
- }
- public void FindNeighbours()
- {
- if (Globals.node2DArray[Globals.i - 1, Globals.y]!=null) //top one
- {
- neighboursXandYcoords.Add(new int[] { Globals.i - 1, Globals.y });
- }
- if (Globals.node2DArray[Globals.i + 1, Globals.y] != null) //bottom one
- {
- neighboursXandYcoords.Add(new int[] { Globals.i - 1, Globals.y });
- }
- if (Globals.node2DArray[Globals.i, Globals.y -1] != null) //left one
- {
- neighboursXandYcoords.Add(new int[] { Globals.i, Globals.y - 1 });
- }
- if (Globals.node2DArray[Globals.i, Globals.y + 1] != null) //right one
- {
- neighboursXandYcoords.Add(new int[] { Globals.i, Globals.y + 1 });
- }
- }
- public void CheckNeighbours()
- {
- wasVisited = true;
- for (int i=0; i < neighboursXandYcoords.Count; i++)
- {
- if (Globals.node2DArray[neighboursXandYcoords[i][0], neighboursXandYcoords[i][1]].wasVisited == false)
- {
- Globals.node2DArray[neighboursXandYcoords[i][0], neighboursXandYcoords[i][1]].wasVisited = true;
- Globals.node2DArray[neighboursXandYcoords[i][0], neighboursXandYcoords[i][1]].minDistance = minDistance+1;
- Globals.queue.Enqueue(new int[] { neighboursXandYcoords[i][0], neighboursXandYcoords[i][1] });
- }
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //otevrit soubor
- //precist pocet zadani (dodelat)
- //precist vysku gridu
- Globals.gridHeight = 3;
- Globals.gridWidth = 3;
- Globals.node2DArray = new Node[Globals.gridWidth, Globals.gridHeight]; //sirka x vyska
- //pocet rozbitych krizovatek (dodelat)
- Globals.startY = 1;
- Globals.startX = 2;
- Globals.finishY = 1;
- Globals.finishX = 1;
- Globals.brokenNodeX = 2; //tech bude vic, podle poctu broken krizovatek loopovat
- Globals.brokenNodeY = 2;
- Globals.node2DArray[Globals.brokenNodeX, Globals.brokenNodeY].isBroken = true;
- for (int i = 0; i< Globals.gridWidth; i++)
- {
- for (int y = 0; y< Globals.gridHeight; y++)
- {
- Globals.i = i;
- Globals.y = y;
- Globals.node2DArray[Globals.i, Globals.y].FindNeighbours();
- //Globals.queue.Enqueue(Globals.node2DArray[i, y]);
- }
- }
- Globals.node2DArray[Globals.startX, Globals.startY].minDistance = 0;
- Globals.node2DArray[Globals.startX, Globals.startY].CheckNeighbours();
- //queue
- Console.WriteLine("Hello World!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement