Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int lab[6][10] = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- { 1, 2, 0, 0, 0, 1, 0, 0, 3, 1 },
- { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
- { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
- { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
- { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }};
- class PathFinder{
- private:
- int in_x, in_y, o_x, o_y, wave;
- int l_row = 10, l_col = 6;
- std::string savefile;
- public:
- PathFinder();
- void DoWave(int x, int y, int c_wave);
- void PrintIt();
- };
- PathFinder::PathFinder(){
- for (int i = 0; i < l_col; i++){
- for (int j = 0; j < l_row; j++){
- if (lab[i][j] == 2){
- in_x = j;
- in_y = i;
- lab[i][j] = 0;
- }
- else if (lab[i][j] == 3){
- o_x = j;
- o_y = i;
- lab[i][j] = 0;
- }
- else if (lab[i][j] == 1){
- lab[i][j] = -1;
- }
- }
- }
- DoWave(in_y, in_x, 0);
- }
- void PathFinder::DoWave(int x, int y, int c_wave){
- int s = 0;
- PrintIt();
- system("pause");
- lab[x][y] = c_wave;
- if (y + 1 < 10){
- if ((lab[x][y + 1] == 0) || ((lab[x][y + 1] != -1) && (lab[x][y + 1] > c_wave))){
- DoWave(x, y + 1, c_wave + 1);
- }
- }
- if (x + 1 < 6){
- if ((lab[x + 1][y] == 0) || ((lab[x + 1][y] != -1) && (lab[x + 1][y] > c_wave))){
- DoWave(x + 1, y, c_wave + 1);
- }
- }
- if (y - 1 >= 0){
- if ((lab[x][y - 1] == 0) || ((lab[x][y - 1] != -1) && (lab[x][y - 1] > c_wave))){
- DoWave(x, y - 1, c_wave + 1);
- }
- }
- if (x - 1 >= 0){
- if ((lab[x - 1][y] == 0) || ((lab[x - 1][y] != -1) && (lab[x - 1][y] > c_wave))){
- DoWave(x - 1, y, c_wave + 1);
- }
- }
- }
- void PathFinder::PrintIt(){
- for (int i = 0; i < 6;i++){
- for (int j = 0; j < 10; j++){
- if (lab[i][j] == -1)
- std::cout << char(178) << char(178) << char(178);
- else
- if (lab[i][j]<10)
- std::cout << lab[i][j] << " ";
- else
- std::cout << lab[i][j] << " ";
- }
- std::cout << std::endl;
- }
- }
- int main(){
- PathFinder test;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment