Metin dosyasindan okunan bir labirent haritasinda, baslangic noktasindan cikisa giden yolu bulan bir C++ uygulamasidir. Yol arama islemi icin yigin (stack) veri yapisi ve geri izleme (backtracking) algoritmasi kullanilir.
A C++ application that reads a maze from a text file and finds a path from the starting point to the exit. It uses a stack data structure and a backtracking algorithm for pathfinding.
Program, labirent haritasini bir metin dosyasindan okur. Haritada # karakterleri duvarlari, bosluklar ise gecilebilir alanlari temsil eder. Cozucu, verilen baslangic koordinatindan hareket etmeye baslar ve asagidaki adimlari izler:
The program reads the maze map from a text file. In the map, # characters represent walls and spaces represent passable areas. The solver starts moving from a given starting coordinate and follows these steps:
- Oncelikle mevcut yonde ilerlemeyi dener. Eger on tarafi aciksa o yone dogru ilerler.
- On tarafi kapali ise saat yonunde diger yonleri sirayla dener (asagi, sol, yukari, sag).
- Hicbir yone gidilemiyorsa yigindan onceki konumu cikararak geri adim atar.
- Bu islem, cikis noktasina ulasana kadar tekrarlanir.
- First, it tries to move in the current direction. If the path ahead is clear, it proceeds.
- If the front is blocked, it tries other directions clockwise (down, left, up, right).
- If no direction is available, it backtracks by popping the previous position from the stack.
- This process repeats until the exit point is reached.
Gecilen hucrelere - isareti konularak tekrar ziyaret edilmeleri onlenir. Cozum sirasinda her adim konsola yazdirilir ve kisa bir bekleme suresi eklenerek hareketin canli olarak izlenmesi saglanir.
Visited cells are marked with - so they are not revisited. During the solution, each step is printed to the console with a short delay so the movement can be watched in real time.
Labirent/
include/
Labyrinth.hpp - Labirent sinifi tanimlamasi / Labyrinth class definition
Location.hpp - Konum yapisi ve yon tanimlari / Location struct and direction definitions
Stack.hpp - Bagli liste tabanli yigin sablonu / Linked-list based stack template
src/
Labyrinth.cpp - Harita okuma, adim atma, engel kontrolu / Map reading, stepping, obstacle check
Location.cpp - Yon hesaplama ve konum islemleri / Direction calculations and position operations
run.cpp - Programin giris noktasi, ana dongu / Program entry point, main loop
lib/ - Derlenmis nesne dosyalari / Compiled object files
bin/ - Calistirilabilir dosya / Executable file
map.txt - Ornek labirent haritalari / Sample maze maps
map2.txt
map3.txt
map4.txt
makefile - Derleme ve calistirma komutlari / Build and run commands
Projeyi derlemek ve calistirmak icin:
To build and run the project:
make all
Bu komut once kaynak dosyalari derler, sonra programi calistirir. Yalnizca derlemek icin make build, yalnizca calistirmak icin make run kullanilabilir. Nesne dosyalarini temizlemek icin make clean komutu vardir.
This command first compiles the source files, then runs the program. Use make build to only compile, make run to only run. To clean object files, use make clean.
Harita dosyalari duvarlar icin #, gecilebilir alanlar icin bosluk karakteri kullanir. Dosyanin boyutlari kodda 20 satir ve 50 sutun olarak tanimlanmistir. Baska boyutta harita kullanmak icin Labyrinth.hpp dosyasindaki YUKSEKLIK ve GENISLIK degerlerinin degistirilmesi gerekir.
Map files use # for walls and space characters for passable areas. The dimensions are defined in the code as 20 rows and 50 columns. To use a map with different dimensions, adjust the YUKSEKLIK and GENISLIK values in Labyrinth.hpp.
Varsayilan baslangic noktasi (0, 20) ve cikis noktasi (19, 11) olarak ayarlanmistir. Bu degerler run.cpp icinde degistirilebilir.
The default starting point is (0, 20) and the exit point is (19, 11). These values can be changed in run.cpp.
- g++ derleyicisi / g++ compiler
- make
- Windows (Sleep ve system("cls") komutlari kullanildigi icin) / Windows (due to usage of Sleep and system("cls"))
Program Windows ortami icin yazilmistir. Linux veya macOS uzerinde calistirmak icin Labyrinth.hpp dosyasindaki Windows.h baglantisinin kaldirilmasi ve Labyrinth.cpp icindeki Sleep() ile system("cls") cagrilarinin platforma uygun karsiliklariyla degistirilmesi gerekir.
The program is written for Windows. To run on Linux or macOS, remove the Windows.h include in Labyrinth.hpp and replace the Sleep() and system("cls") calls in Labyrinth.cpp with platform-appropriate alternatives.