Advertisement
silvi81

Knight Path

Nov 14th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace KnightPath
  8. {
  9. class KnightPath
  10. {
  11. static void Main()
  12. {
  13. int n = 1;
  14. int[] arr = new int[8];
  15. arr[0] = 1;
  16. int pos = 0;
  17. int row = 0;
  18. for (int i = 0; i < 25; i++)
  19. {
  20. string command = Console.ReadLine();
  21. if (command=="stop")
  22. {
  23. break;
  24. }
  25.  
  26. if (command== "left down")
  27. {
  28. pos += 2;
  29. row += 1;
  30. if (pos>=0 && pos<8 && row>=0 && row<8)
  31. {
  32.  
  33. n <<= 2;
  34. arr[row]= arr[row] ^ n;
  35. }
  36. else
  37. {
  38. pos -= 2;
  39. row -= 1;
  40. }
  41. }
  42. if (command == "left up")
  43. {
  44. pos += 2;
  45. row -= 1;
  46. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  47. {
  48.  
  49. n <<= 2;
  50. arr[row] = arr[row] ^ n;
  51. }
  52. else
  53. {
  54. pos -= 2;
  55. row += 1;
  56. }
  57. }
  58. if (command == "right up")
  59. {
  60. pos -= 2;
  61. row -= 1;
  62. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  63. {
  64.  
  65. n >>= 2;
  66. arr[row]= arr[row] ^ n;
  67. }
  68. else
  69. {
  70. pos += 2;
  71. row += 1;
  72. }
  73. }
  74. if (command == "right down")
  75. {
  76. pos -= 2;
  77. row += 1;
  78. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  79. {
  80.  
  81. n >>= 2;
  82. arr[row]= arr[row] ^ n;
  83. }
  84. else
  85. {
  86. pos += 2;
  87. row -= 1;
  88. }
  89. }
  90. if (command == "up left")
  91. {
  92. pos += 1;
  93. row -= 2;
  94. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  95. {
  96.  
  97. n <<= 1;
  98. arr[row ]= arr[row] ^ n;
  99. }
  100. else
  101. {
  102. pos -= 1;
  103. row += 2;
  104. }
  105. }
  106. if (command == "down left")
  107. {
  108. pos += 1;
  109. row += 2;
  110. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  111. {
  112.  
  113. n <<= 1;
  114. arr[row ]= arr[row] ^ n;
  115. }
  116. else
  117. {
  118. pos -= 1;
  119. row -= 2;
  120. }
  121. }
  122. if (command == "up right")
  123. {
  124. pos -= 1;
  125. row -= 2;
  126. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  127. {
  128.  
  129. n >>= 1;
  130. arr[row]= arr[row] ^ n;
  131. }
  132. else
  133. {
  134. pos += 1;
  135. row += 2;
  136. }
  137. }
  138. if (command == "down right")
  139. {
  140. pos -= 1;
  141. row += 2;
  142. if (pos >= 0 && pos < 8 && row >= 0 && row < 8)
  143. {
  144.  
  145. n >>= 1;
  146. arr[row ] = arr[row] ^ n ;
  147. }
  148. else
  149. {
  150. pos += 1;
  151. row -= 2;
  152. }
  153. }
  154. }
  155. if (Array.TrueForAll(arr, y => y == 0))
  156. {
  157. Console.WriteLine("[Board is empty]");
  158. }
  159. else
  160. {
  161. for (int i = 0; i < 8; i++)
  162. {
  163. if (arr[i] != 0)
  164. {
  165. Console.WriteLine(arr[i]);
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement