Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4.  
  5. public class GameTactic {
  6. char[][] matrix;
  7. int size;
  8.  
  9. public GameTactic(char[][] matrix, int size) {
  10. this.matrix = matrix;
  11. this.size = size;
  12. }
  13.  
  14. public int GenerateCost(Node n){
  15. if(this.matrix[n.getRow()][n.getCol()]=='R'){
  16. return 1;
  17. }
  18. if(this.matrix[n.getRow()][n.getCol()]=='D'){
  19. return 3;
  20. }
  21. if(this.matrix[n.getRow()][n.getCol()]=='H'){
  22. return 10;
  23. }
  24. return -1;
  25. }
  26.  
  27. public List<Node> GetPossibleNeigh(Node n){
  28. int row=n.getRow();
  29. int col=n.getCol();
  30. List<Node> possibleNeigh=new ArrayList<>();
  31. //R
  32. if(col<size && matrix[row][col+1]!='W') {
  33. Node R = new Node(row,col+1);
  34. R.setPath("R");
  35. possibleNeigh.add(R);
  36. }
  37. //RD
  38. if(col<size && row<size && matrix[row][col+1]!='W' && matrix[row+1][col]!='W' && matrix[row+1][col+1]!='W') {
  39. Node RD = new Node(row+1,col+1);
  40. RD.setPath("RD");
  41. possibleNeigh.add(RD);
  42. }
  43. //D
  44. if(row<size && matrix[row+1][col]!='W') {
  45. Node D = new Node(row+1,col);
  46. D.setPath("D");
  47. possibleNeigh.add(D);
  48. }
  49. //DL
  50. if(col>0 && row<size && matrix[row+1][col-1]!='W' && matrix[row+1][col]!='W' && matrix[row][col-1]!='W') {
  51. Node DL = new Node(row+1,col-1);
  52. DL.setPath("DL");
  53. possibleNeigh.add(DL);
  54. }
  55. //L
  56. if(col>0 && matrix[row][col-1]!='W') {
  57. Node L = new Node(row,col-1);
  58. L.setPath("L");
  59. possibleNeigh.add(L);
  60. }
  61. //LU
  62. if(col>0 && row>0 && matrix[row-1][col-1]!='W' && matrix[row-1][col]!='W' && matrix[row][col-1]!='W') {
  63. Node LU = new Node(row-1,col-1);
  64. LU.setPath("LU");
  65. possibleNeigh.add(LU);
  66. }
  67. //U
  68. if(row>0 && matrix[row-1][col]!='W') {
  69. Node U = new Node(row-1,col);
  70. U.setPath("U");
  71. possibleNeigh.add(U);
  72. }
  73. //RU
  74. if(col<size && row>0 && matrix[row-1][col+1]!='W' && matrix[row-1][col]!='W' && matrix[row][col+1]!='W') {
  75. Node RU = new Node(row-1,col+1);
  76. RU.setPath("RU");
  77. possibleNeigh.add(RU);
  78. }
  79. return possibleNeigh;
  80. }
  81. public boolean IsGoal(Node n){
  82. if(n.getRow()==size-1 && n.getCol()==size-1){
  83. return true;
  84. }
  85. return false;
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement