Witam wszystkich.
Pracuje z 2 wymiarowa tablica. Probuje zmienic wartosci (z "1" na "4") wszystkich sasiadow otaczajacych moj punkt startowy. Niestety, moj obecny kod zmienia rowniez wartosc punktu startowego. Jak tego uniknac? Oto kod:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <queue>
#include "node.h"
#include <math.h>
#include <string>
using namespace std;
void loadMap();
void displayMap();
//Map size
const int Nsize = 5; //number of rows
const int Msize = 7; //number of columns
//Start location
int sX=2;
int sY=1;
//Map
static int map[Nsize][Msize]; //work map
//Directions
const int dir=8;
static int dirX[dir]={1, 1, 0, -1, -1, -1, 0, 1};
static int dirY[dir]={0, 1, 1, 1, 0, -1, -1, -1};
static int dir_map[Nsize][Msize]; //map of directions
int main()
{
loadMap();
for (int i=0; i<dir; i++)
{
for(int j=0; j<dir; j++)
{
map[sX+dirY[i]][sY+dirX[j]] = 4;
}
}
displayMap();
getchar();
return 0;
}
void loadMap ()
{
//load the map from .txt file
ifstream file;
file.open("testmap.txt");
if(file.good()==true)
{
for(int i=0;i<Nsize;i++)
{
for(int j=0;j<Msize;j++)
{
file>>map[i][j];
}
}
file.close();
}
else
{
cout<<"Cannot open the file";
}
}
void displayMap()
{
//Display the map
for(int i=0;i<Nsize;i++)
{
for(int j=0;j<Msize;j++)
{
cout<<" "<<map[i][j];
}
cout<<endl;
}
}