-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
52 lines (39 loc) · 2.16 KB
/
Copy pathTest.cpp
File metadata and controls
52 lines (39 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Labirent.hpp"
#include <iostream>
using namespace std;
int main(){
// Labirent nesnesi oluşturuluyor, başlangıç ve çıkış noktaları belirleniyor.
Labirent *labirent = new Labirent(Konum(0,20), Konum(19,11));
// Başlangıç noktasına ilk adım aşağıya doğru ekleniyor.
labirent->yigit->push(Konum(labirent->x, labirent->y, ASAGI));
labirent->ayarla(Konum(labirent->x, labirent->y, ASAGI).Asagi(), ASAGI);
// Çıkışa ulaşana kadar labirentte gezinmeye başlıyoruz.
while(!labirent->CikisaGeldimi()){
int denemeYonSayisi = 1; // Başlangıçta bir yön deneniyor.
Konum oncekiKonum = labirent->yigit->top(); // Önceki konum kaydediliyor.
Konum mevcutKonum = labirent->mevcutKonum(); // Şu anki konum.
Konum ileri = mevcutKonum.AyniYon(); // İlk yön denemesi.
if(!labirent->adimAt(mevcutKonum, ileri)){ // Eğer ilerlenemiyorsa:
int i = 0; // Diğer yönler için sayaç
bool sonuc = false; // Yol bulundu mu?
Konum yeni = mevcutKonum; // Yeni konum.
while(!sonuc && denemeYonSayisi < 5){
yeni = mevcutKonum.SaatYonu((Yon)((mevcutKonum.yon + i) % 4)); // Saat yönünde dönüyoruz.
i++;
denemeYonSayisi++;
if(yeni.yon == mevcutKonum.TersYon()) // Ters yönde gitmek geçersiz.
sonuc = false;
else
sonuc = labirent->adimAt(mevcutKonum, yeni); // Yön başarılıysa ilerliyoruz.
}
if(denemeYonSayisi == 5){ // Eğer dört yönü de denediyssek:
labirent->yigit->pop(); // Önceki adıma geri dönüyoruz.
labirent->ayarla(oncekiKonum, oncekiKonum.TersYon()); // Geri adım atıyoruz.
}
}
}
cout << "CIKISA GELDI" << endl; // Çıkışa ulaşıldı.
getchar(); // Kullanıcıdan giriş bekliyoruz.
delete labirent; // Labirent nesnesini bellekten siliyoruz.
return 0; // Program sonlanıyor.
}