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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include<iostream>
#include<vector>
using namespace std;
/* Head ends here */
void next_move(int posx, int posy, vector <string> board) {
int p_pos,found=0,m_pos,turn=0,i=posx-1,j=posy-1,count=1,line_turn=1,loop_turn=1;
while(i<0)
{i++;}
while(j<0)
{j++;}
while(i>4)
{i--;}
while(j>4)
{j--;}
int counter_i = i;
int counter_j = j;
int new_posx = posx+1;
int new_posy = posy+1;
for(i=counter_i;i<=new_posx;i++)
{
for(j=counter_j;j<=new_posy;j++)
{
if(board[i].at(j)=='d')
{
found = 1;
break;
}
}
if(found==1)
{
break;
}
}
if(i<posx&&turn==0&&found==1)
{
cout<<"UP"<< endl;
turn=1;
posx--;
}
if(i>posx&&turn==0&&found==1)
{
cout<<"DOWN"<< endl;
turn=1;
posx++;
}
if(j<posy&&turn==0&&found==1)
{
cout<<"LEFT"<< endl;
turn=1;
posy--;
}
if(j>posy&&turn==0&&found==1)
{
cout<<"RIGHT"<< endl;
turn=1;
posy++;
}
if(i == posx && j == posy && turn == 0 && found == 1)
{
cout<<"CLEAN"<< endl;
board[i].at(j) = '-';
turn = 1;
}
if(found == 0)
{
if(posx!=4&&posy!=4)
{
if(posx+1 < 5 && line_turn == 1&&loop_turn==1)
{
posx++;
cout<<"RIGHT"<< endl;
loop_turn=0;
}
if(posx+1 == 5 && line_turn ==1&&loop_turn==1)
{
posy++;
cout<<"DOWN"<< endl;
line_turn = 0;
loop_turn=0;
}
if(posx-1 > -1 && line_turn == 0&&loop_turn==1)
{
posx--;
cout<<"LEFT"<< endl;
loop_turn=0;
}
if(posx-1 == -1 && line_turn == 0&&loop_turn==1)
{
posy++;
cout<<"DOWN"<< endl;
line_turn = 1;
loop_turn=0;
}
next_move(posx,posy,board);
}
else{return;}
}
else{next_move(posx,posy,board);}
}
/* Tail starts here */
int main(void) {
int pos[2];
vector <string> board;
cin>>pos[0]>>pos[1];
for(int i=0;i<5;i++) {
string s;cin >> s;
board.push_back(s);
}
next_move(pos[0], pos[1], board);
return 0;
}
|