Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. package algorithms;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6. static HashMap<String, String> map = new HashMap<String, String>();
  7. static Boolean[][] arr2 = new Boolean[8][8];
  8. public static void find(char[][] arr, int row, int column,int moves) {
  9. if ((row!=7||column!=0)&&arr[row][column] != '.') {
  10. return;
  11. }
  12. if (row == 0 && column == 7) {
  13. System.out.println("WIN");
  14. return;
  15. }
  16. arr2[row][column]= true ;
  17. for (String i : map.keySet()) {
  18. int index1 = (int)i.charAt(0);
  19. int index2 = (int)i.charAt(2);
  20. if(index1+moves==row&&index2==column) {
  21. return ;
  22. }
  23. }
  24. moves++;
  25.  
  26. if (row != arr.length - 1) {
  27. if(a)
  28. find(arr, row + 1, column, moves);
  29.  
  30. }
  31. if (column != arr[0].length - 1) {
  32.  
  33. find(arr, row, column + 1, moves);
  34.  
  35. }
  36. if (row != 0) {
  37.  
  38. find(arr, row - 1, column, moves);
  39.  
  40. }
  41. if (column != 0) {
  42.  
  43. find(arr, row, column - 1, moves);
  44. }
  45.  
  46. return;
  47. }
  48.  
  49. public static void main(String[] args) {
  50. int index=0;
  51. Scanner s = new Scanner(System.in);
  52. char[][] arr = new char[8][8];
  53. for (int k = 0; k < 8; k++) {
  54. String line = s.next();
  55. for (int j = 0; j < 8; j++) {
  56. arr[k][j] = line.charAt(j);
  57. if(arr[k][j]=='S') {
  58. map.put("0", k+"-"+j);
  59. index++;
  60. }
  61. }
  62. }
  63. find(arr, 7,0 , 0);
  64.  
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement