본문 바로가기
반응형

전체 글218

BFS를 이용한 길찾기 구현 using System; using System.Collections.Generic; using System.Text; namespace Algorithm { class Pos { public Pos(int y, int x) { Y = y; X = x; } public int Y; public int X; } class Player { public int PosY { get; private set; } public int PosX { get; private set; } Random _random = new Random(); Board _board; enum Dir { Up = 0, Left = 1, Down = 2, Right = 3 } int _dir = (int)Dir.Up; List _points .. 2023. 7. 16.
BFS(너비 우선 탐색) namespace Exercise { internal class Program { class Graph { int[,] adj = new int[6, 6] {{0,1,0,1,0,0}, {1,0,1,1,0,0}, {0,1,0,0,0,0}, {1,1,0,0,1,0}, {0,0,0,1,0,1}, {0,0,0,0,1,0}}; List[] adj2 = new List[] { new List{ 1, 3 }, new List{ 0, 2, 3 }, new List{ 1 }, new List{ 0, 1, 4 }, new List{ 3, 5 }, new List{ 4 }, }; public void BFS(int start)//길찾기에서 쓰임 { bool[] found = new bool[6]; int[] parent =.. 2023. 7. 16.
DFS(깊이 우선 탐색) namespace Exercise { internal class Program { class Graph { int[,] adj = new int[6, 6] {{0,1,0,1,0,0}, {1,0,1,1,0,0}, {0,1,0,0,0,0}, {1,1,0,0,1,0}, {0,0,0,1,0,1}, {0,0,0,0,1,0}}; List[] adj2 = new List[] { new List{ 1, 3 }, new List{ 0, 2, 3 }, new List{ 1 }, new List{ 0, 1 }, new List{ 5 }, new List{ 4 }, }; // 1) 우선 now부터 방문하고. // 2) now와 연결된 정점들을 하나씩 확인해서, // [ 아직 미발견(미방문)상태라면] 방문한다. public v.. 2023. 7. 16.
그래프 생성 namespace Exercise { internal class Program { class Graph { int[,] adj = new int[6, 6] {{0,1,0,1,0,0}, {1,0,1,1,0,0}, {0,1,0,0,0,0}, {1,1,0,0,1,0}, {0,0,0,1,0,1}, {0,0,0,0,1,0}}; }; List[] list = new List[] { new List{ 1, 3 }, new List{ 0, 2, 3 }, new List{ 1 }, new List{ 0, 1, 4 }, new List{ 3, 5 }, new List{ 4 }, }; static void Main(string[] args) { //DFS(Depth First Search 깊이 우선 탐색) //BFS(Bre.. 2023. 7. 16.
그래프 이론 [현실 세게의 사물이나 추상적인 개념 간]의 [연결 관계]를 표현 정점(Vertex): 데이터를 표현(사물, 개념 등) 간선(Edge) : 정점들을 연결하는데 사용 2023. 7. 16.
오른손의 법칙 Board using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Algorithm { class Board { public TileType[,] Tile { get; private set; } public int Size { get; private set; } const char CIRCLE = '\u25cf'; public int DestY { get; private set; } public int DestX { get; private set; } Player _player; public enum TileType { Empty, Wa.. 2023. 7. 14.
스택과 큐 스택 : LIFO(후입선출 Last in First out) 큐 : FIFO(선입 선출First in First out) namespace Exercise { internal class Program { static void Main(string[] args) { Stack stack = new Stack();//후입선출 stack.Push(101); stack.Push(102); stack.Push(103); stack.Push(104); stack.Push(105); int data = stack.Pop();//Pop, Peek은 stack 값이 없을 경우 에러 출력 int data2 = stack.Peek(); Queue queue = new Queue();//선입선출 queue.Enqueue(10.. 2023. 7. 14.
플레이어 이동 Player using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Algorithm { class Player { public int PosY { get; private set; } public int PosX { get; private set; } Random _random = new Random(); Board _board; public void Initialize(int posY, int posX, int destX, int destY, Board board) { PosX = posX; PosY = posY; _board = bo.. 2023. 7. 13.
SideWinder 미로 생성 알고리즘 using System; namespace Algorithm { class Board { public TileType[,] _tile; public int _size; const char CIRCLE = '\u25cf'; public enum TileType { Empty, Wall } public void Initialize(int size) { if (size % 2 == 0) return; _tile = new TileType[size, size]; _size = size; //Mazes for Programmers //일단 길을 다 막아버리는 작업 for(int y = 0; y 2023. 7. 13.
Binary Tree using System; namespace Algorithm { class Board { public TileType[,] _tile; public int _size; const char CIRCLE = '\u25cf'; public enum TileType { Empty, Wall } public void Initialize(int size) { if (size % 2 == 0) return; _tile = new TileType[size, size]; _size = size; //Mazes for Programmers //일단 길을 다 막아버리는 작업 for(int y = 0; y 2023. 7. 13.
맵 만들기 Program using System; using System.Collections; using System.Reflection; namespace Algorithm { class Program { static void Main(string[] args) { Board board = new Board(); board.Initialize(25); Console.CursorVisible = false; const int WAIT_TICK = 1000 / 30; int lastTick = 0; while (true) { //FPS 프레임 (60프레임 OK 30 프레임 이하는 X) #region 프레임 관리 int currentTick = System.Environment.TickCount; //만약에 경과한 .. 2023. 7. 13.
연결 리스트 구현 연습 using System; namespace CSharp1 { class MyLinkedListNode { public T Data; public MyLinkedListNode Next; public MyLinkedListNode Prev; } class MyLinkedList { public MyLinkedListNode Head = null;//첫번째 public MyLinkedListNode Tail = null;//마지막 public int Count = 0; public MyLinkedListNode AddLast(T data) { MyLinkedListNode newRoom = new MyLinkedListNode(); newRoom.Data = data; //만약에 아직 방이 아ㅖ 없었다면, .. 2023. 7. 13.
반응형