Advertisement
Guest User

Untitled

a guest
Nov 19th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int outputmap(char arr[10][10]){
  5. for(int i = 0; i < 10; i++){
  6. for(int j = 0; j < 10; j++){
  7. printf("%c",arr[i][j]);
  8. }
  9. printf("\n");
  10. }
  11.  
  12. }
  13.  
  14. char opposite(char current){
  15. if(current == '.'){
  16. return '#';
  17. }
  18. else if(current == '#'){
  19. return '.';
  20. }
  21. else{return '..';}
  22. }
  23.  
  24. int main()
  25. {
  26.  
  27. int turns = 0;
  28.  
  29. struct player{
  30. int loc[2];
  31. int dir;
  32. };
  33.  
  34. struct player ant;
  35.  
  36. ant.loc[0] = 0;
  37. ant.loc[1] = 0;
  38. ant.dir = 180;
  39.  
  40. printf("Enter number of turns: ");
  41. scanf("%d", &turns);
  42. printf("Enter start position: ");
  43. scanf("%d %d",&ant.loc[0],&ant.loc[1]);
  44. printf("\n");
  45.  
  46. char a[10][10] = {
  47. {'.','.','.','.','.','.','.','.','.','.'},
  48. {'.','.','.','.','.','.','.','.','.','.'},
  49. {'.','.','.','.','.','.','.','.','.','.'},
  50. {'.','.','.','.','.','.','.','.','.','.'},
  51. {'.','.','.','.','.','.','.','.','.','.'},
  52. {'.','.','.','.','.','.','.','.','.','.'},
  53. {'.','.','.','.','.','.','.','.','.','.'},
  54. {'.','.','.','.','.','.','.','.','.','.'},
  55. {'.','.','.','.','.','.','.','.','.','.'},
  56. {'.','.','.','.','.','.','.','.','.','.'},
  57. };
  58.  
  59. char opp = '.';
  60.  
  61.  
  62. for(int i = 0; i < turns; i++){
  63.  
  64. opp = opposite(a[ant.loc[1]][ant.loc[0]]);
  65. printf("%c",opp);
  66. printf("%d \n",ant.dir);
  67. outputmap(a);
  68. printf("\n");
  69. if(a[ant.loc[1]][ant.loc[0]] == '.'){
  70. ant.dir -= 90;
  71. if(ant.dir < 0){ant.dir += 360;}
  72. }
  73. else{
  74. ant.dir += 90;
  75. if(ant.dir >= 360){ant.dir -= 360;}
  76. }
  77.  
  78.  
  79. if(ant.dir == 0){
  80. a[ant.loc[1]][ant.loc[0]] = opp;
  81. ant.loc[0] += 1;
  82.  
  83. }
  84. else if(ant.dir == 90){
  85. a[ant.loc[1]][ant.loc[0]] = opp;
  86. ant.loc[1] -= 1;
  87.  
  88. }
  89. else if(ant.dir == 180){
  90. a[ant.loc[1]][ant.loc[0]] = opp;
  91. ant.loc[0] -= 1;
  92.  
  93. }
  94. else if(ant.dir == 270){
  95. a[ant.loc[1]][ant.loc[0]] = opp;
  96. ant.loc[1] += 1;
  97.  
  98. }
  99.  
  100.  
  101.  
  102. }
  103.  
  104. if(a[ant.loc[1]][ant.loc[0]] = '.'){
  105. a[ant.loc[1]][ant.loc[0]] = 'a';
  106. }
  107. else{
  108. a[ant.loc[1]][ant.loc[0]] = 'A';
  109.  
  110. };
  111.  
  112.  
  113.  
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement