Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int outputmap(char arr[10][10]){
- for(int i = 0; i < 10; i++){
- for(int j = 0; j < 10; j++){
- printf("%c",arr[i][j]);
- }
- printf("\n");
- }
- }
- char opposite(char current){
- if(current == '.'){
- return '#';
- }
- else if(current == '#'){
- return '.';
- }
- else{return '..';}
- }
- int main()
- {
- int turns = 0;
- struct player{
- int loc[2];
- int dir;
- };
- struct player ant;
- ant.loc[0] = 0;
- ant.loc[1] = 0;
- ant.dir = 180;
- printf("Enter number of turns: ");
- scanf("%d", &turns);
- printf("Enter start position: ");
- scanf("%d %d",&ant.loc[0],&ant.loc[1]);
- printf("\n");
- char a[10][10] = {
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- {'.','.','.','.','.','.','.','.','.','.'},
- };
- char opp = '.';
- for(int i = 0; i < turns; i++){
- opp = opposite(a[ant.loc[1]][ant.loc[0]]);
- printf("%c",opp);
- printf("%d \n",ant.dir);
- outputmap(a);
- printf("\n");
- if(a[ant.loc[1]][ant.loc[0]] == '.'){
- ant.dir -= 90;
- if(ant.dir < 0){ant.dir += 360;}
- }
- else{
- ant.dir += 90;
- if(ant.dir >= 360){ant.dir -= 360;}
- }
- if(ant.dir == 0){
- a[ant.loc[1]][ant.loc[0]] = opp;
- ant.loc[0] += 1;
- }
- else if(ant.dir == 90){
- a[ant.loc[1]][ant.loc[0]] = opp;
- ant.loc[1] -= 1;
- }
- else if(ant.dir == 180){
- a[ant.loc[1]][ant.loc[0]] = opp;
- ant.loc[0] -= 1;
- }
- else if(ant.dir == 270){
- a[ant.loc[1]][ant.loc[0]] = opp;
- ant.loc[1] += 1;
- }
- }
- if(a[ant.loc[1]][ant.loc[0]] = '.'){
- a[ant.loc[1]][ant.loc[0]] = 'a';
- }
- else{
- a[ant.loc[1]][ant.loc[0]] = 'A';
- };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement