Maze game , verilen txt ler ile

Öncelikle herkese merhabalar ve kolay gelsin, ben bu oyunu nasıl ilerleteceğim ve hangi kuralları işleteceğim hakkında kafam karışık yardım edebilir misiniz ek açıklamaları ilgilenmek isteyen arkadaşlara yapabilirim

Merhaba, hoşgeldin.

Soru biraz havada kalmış gibi. Labirent oluşturmaktan mı bahsediyorsun, yoksa verilen bir labirentte bir çıkış yolu bulmaktan mı bahsediyorsun? Txt dosyasının içindeki verileri görsek bize baya yardım edebilirsin.

Bunu yazarak zaman kaybedeceğimize ek açıklamayı da yazsan daha güzel olurdu.

Cevabım biraz havada kalacak ama backtracking algorithm kullanarak labirentte yolunu bulabilirsin.

İyi geceler dilerim.

Estağfirullah ne demek.

Stack kullanarak dfs atarsan soruyu çözersin. Cumadan sonra sana kod da yazayım.

Kolay gelsin.

Son zamanlarda sorulan sorulari ve cevaplara goz gezdirdiginde gordugun seviyedeki genel bilgi disinda hic bir seyi bilmeyen, belki hocanin, belki de cocugunun arkadasi olan insanlara soruyormus gibi.

Gereken veya gerekme ihtimali olan butun ek aciklamalariyla birlikte.

Soruyu neden Ingilizce ve resim dosyasi olarak sordugunun aciklamasiyla beraber.

Allah kabul etsin , teşekkür ederim daha sonra kendi uğraştığım kod üstünden de soru sorabilir miyim orda da belli bir noktaya gelmiştim aslında?

Hah, tamam. Tahmin etmistik zaten de, onden belirtmekte fayda var.

Bunu da tahmin ettik ama kod veya odevi yapmaya yonelik bir sey olmadan odev metni oldugu gibi geldiginde “bu insan odevini onun yerine yapmamizi istiyor” varsayimi olusuyor.

:+1:

Nerede kafanin karistigina dair bir fikrimiz olmasi icin kodunu veya bir kismini paylasabilirsin. Yoksa sadece tanimlara/egitim metinlerine yonlendirebiliriz.

Kullandigin algoritmaya gore degisiyor.

Mesela yukarida da bahsi gecen depth-first search yontemiyle gidersen daha once gidilmemis bir yonu sectigin surece hangisine oncelik verdiginin onemi yok.

Simdiden sorabilirsin. Hatta sor.

Bastan sormus olsaydin simdiye cevaplamistik.

[quote=“aib, post:10, topic:9741”]
depth-first search
[/quote]siteye dün üye oldum zaten hiç böyle bir yardım beklemiyordum şahsen :slight_smile: ama artık bildiğim çoğu konuda aynı yardımda bulunucam ihtiyacı olanlara gerçekten çok çok iyi bir site burası herkesin emeğine sağlık.

Kodu uc backtick (```) arasina alman lazim:

```
kod
```

Nasil bir hata aliyorsun?

f tanimsiz. with open(...) as f mi kullanmak istedin?

‘’’
kod
‘’’
bunun kullanım amacı nedir?

invalid syntax hatası alıyorum

İçindeki metne kod görünümü kazandırmak. Foruma kodları atarken ``` arasına alıyoruz, baştaki ```'in sonuna da kodun yazıldığı dilin ismini yazıyoruz. Şurada anlatılmış:

Merhaba, cpp ile kodu bitirmiş bulunmaktayım. Krinç krinç hatalarla boğuşmak zorunda olunca biraz geç oldu. python bende köreldi de. Yapabilirsem bir de python ile yazarım.Ne demişler, acele code’a bug karisir :upside_down_face:

/*


   ***   	         *
    *                  *
    *                  *
    *	 ****	 ****  *****    ****   *   *
    *	*   *   *      *   *    *  *   *   *
    *	*   *   *      *   *    *  *   *   *
*   *	*   *   *      *   *    *  *   *****
*   *	*   *   *      *   *    *  *       *
 ***	 *** *  *      *****    *** *      *
                                           *
********************************************

*/

/*ya parçalayacam ya parçalayacam ya da parçalayacammm :)*/


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define ceza(i, n) for(ll i = n - 1; i >= 0; i--)
#define RUN_JARBAY_RUN ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vll vector<ll>
#define deql deque<ll>
#define vi vector<int>
#define sll stack<ll>
#define pqueue priority_queue
#define pll pair<ll, ll>
#define mp make_pair
#define ff first
#define ss second
#define mete make_tuple
#define pb push_back
#define pf push_front
#define popf pop_front
#define popb pop_back

#define gcd __gcd
#define lcm(x, y) x * y / gcd(x, y)
#define get_digit(a) a - '0'
#define tos(x, y) string x; stringstream strstream; strstream << y; strstream >> x; 
#define all(a) a.begin(), a.end()
#define dbg_list(a)  cout<<"debug: "<<#a<<" "; for(ll i : a) { cout<<i<<" ";} cout<<endl;
#define dbg(a) cout<<"debug: "<<#a<<" : "<<a<<endl;
#define dbg2(a, b) cout<<"debug: "<<#a<<" : "<<a<<" || "<<#b<<" : "<<b<<endl;
#define inf 1000000009 // 10^9 + 9
#define mod 1000000007 // 10^9 + 7

// WARNING: only for int, not long long
#define clz(x) __builtin_clz(x) // the number of zeros at the beginning of the number
#define ctz(x) __builtin_ctz(x) // the number of zeros at the end of the number
#define popcount(x) __builtin_popcount(x) // the number of ones in the number
#define parity(x) __builtin_parity(x) // the parity (even or odd) of the number of ones

// for long long
#define clzll(x) __builtin_clzll(x) // the number of zeros at the beginning of the number
#define ctzll(x) __builtin_ctzll(x) // the number of zeros at the end of the number
#define popcountll(x) __builtin_popcountll(x) // the number of ones in the number
#define parityll(x) __builtin_parityll(x) // the parity (even or odd) of the number of ones

//node definition
struct node
{
  ll data;
  struct node *next;
};

typedef struct node Node;

//linked list definition
struct LinkedList
{
  Node *head;
  Node *tail;
};

typedef struct LinkedList LinkedList;

// definitions for problems

struct point
{
  ll x;
  ll y;
};

typedef struct point point;

ll n, m;
bool isfinded = false;
char MAP[100][100];
int visited[100][100];

void dfs(point start, point end)
{
  stack<point> path; // dfs için yiğin oluşturuyorum.
  path.push(start); // yiğina ilk noktayi yukluyorum.
  while(!path.empty())
  {
    point loc = path.top(); // su anda bulundugum konumun bilgisini aliyorum.
    
    if(loc.x == end.x && loc.y == end.y) break; // eger aradiğimiz konuma ulaştiysak donguden cikiyorum.
    else if(loc.x > 0 && !visited[loc.x - 1][loc.y]) // bulundugumuz konumdan yukariya gidebiliyor muyum
      path.push({loc.x - 1, loc.y}); 
    else if(loc.x < n - 1 && !visited[loc.x + 1][loc.y]) // bulundugumuz konumdan asagiya gidebiliyor muyum
      path.push({loc.x + 1, loc.y});
    else if(loc.y > 0 && !visited[loc.x][loc.y - 1]) // bulundugumuz konumun soluna gidebiliyor muyum
      path.push({loc.x, loc.y - 1});
    else if(loc.y < m - 1 && !visited[loc.x][loc.y + 1]) // bulundugumuz konumun sagina gidebiliyor muyum
      path.push({loc.x, loc.y + 1});
    else path.pop();
    
    visited[loc.x][loc.y] = 1;
    
    
  }
  isfinded = !path.empty(); // yiğin bossa hedefe varamamisiz demektir
  while(!path.empty())
  {
    // bu dongude de haritadaki son ayarlamalari yapiyorum.
    point loc = path.top();
    path.pop();
    MAP[loc.x][loc.y] = '1';
  }
}

void solve()
{
  point start, end;
  cin>>n>>m;
  cin>>start.x>>start.y;
  cin>>end.x>>end.y;
  
  rep(i, n)
    rep(j, m)
    {
      cin>>MAP[i][j]; // haritayı okuyorum.
      visited[i][j] = (MAP[i][j] == '*'); // eger duvar yıldızlı ise burayı ziyaret edemeyiz.
    }
    
  if(MAP[start.x][start.y] == '*')
  {
    cout<<-1<<endl; // gireceğimiz yer kapalı
    return;
  }
  dfs(start, end); // dfs yi baslatiyorum.
  if(isfinded) // istediğimiz konuma ulastiysam haritanin son halini bastiriyorum.
  {
    rep(i, n)
    {
      rep(j, m)
        cout<<MAP[i][j];
      cout<<endl;
    }
  }
  else cout<<-1<<endl; // yoksa -1 bastırıyorum.
}


int main()
{
  RUN_JARBAY_RUN
  
  #ifdef JARBAY_DEBUG
    clock_t start = clock();
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
  #endif
  
  ll t = 1;
  //cin>>t;
  rep(i, t)
    solve();
    
  #ifdef JARBAY_DEBUG
    double EXECUTION_TIME = (double(clock()) - double(start)) / double(CLOCKS_PER_SEC);
    cout<<"\n*******************************************"<<endl;
    cout<<"EXECUTION TIME: "<<EXECUTION_TIME<<endl;
  #endif
		
}

Ya bir de bu input outputların sınır limiti var mı?

Tabiki. Bilgim dahilinde yardımcı olmaya çalışırım.

n, m = map(int, input().split())

start = list(map(int, input().split()))
end = list(map(int, input().split()))

MAP = []
visited = []
for i in range(n):
  MAP.append(list(input()))
  visited.append([0 for i in range(m)])
  
isfinded = False
def dfs(start, end):
  global isfinded
  global MAP;
  stack = [start]
  while(stack):
    r, c = stack[-1]
    
    if(stack[-1] == end): break
    elif(MAP[r][c] == "*"): stack.pop()
    elif(r > 0 and not visited[r - 1][c]):
      stack.append([r - 1, c])
    elif(r < n - 1 and not visited[r + 1][c]):
      stack.append([r + 1, c])
    elif(c > 0 and not visited[r][c - 1]):
      stack.append([r, c - 1])
    elif(c < m - 1 and not visited[r][c + 1]):
      stack.append([r, c + 1])
    else: stack.pop()
    
    visited[r][c] = 1
    
  isfinded = bool(stack)
  # print(stack)
  while(stack):
    r, c = stack[-1]
    MAP[r][c] = "1"
    stack.pop()

dfs(start, end)   
if(not isfinded): print("-1")
else:
  for i in range(n):
    for j in range(m):
      print(MAP[i][j], end = "")
    print()

Bu da python’lu bir çözüm.