Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public class EstadoCaballo implements EstadoBT<Table<Integer,Integer,Integer>, Integer> {
  2.  
  3. Integer[] movx = null;
  4. Integer[] movy = null;
  5. Table<Integer,Integer,Integer> tablero= null;
  6. Integer posx = null;
  7. Integer posy = null;
  8. int casillasProcesadas = 0;
  9. int tam = 8;
  10.  
  11. public EstadoCaballo() {
  12. tam = ProblemaCaballo.getTamTablero();
  13. casillasProcesadas = 1;
  14. posx = ProblemaCaballo.getCasillaInicialX();
  15. posy = ProblemaCaballo.getCasillaInicialY();
  16. movx = ProblemaCaballo.getMovimientosX();
  17. movy = ProblemaCaballo.getMovimientosY();
  18. tablero = HashBasedTable.create();
  19. tablero.put(posx, posy, casillasProcesadas);
  20. }
  21.  
  22.  
  23. @Override
  24. public void avanza(Integer movimiento) {
  25. // TODO
  26. casillasProcesadas++;
  27. posx += movx[movimiento];
  28. posy += movy[movimiento];
  29. tablero.put(posx, posy, casillasProcesadas);
  30. }
  31.  
  32. @Override
  33. public void retrocede(Integer movimiento) {
  34. // TODO
  35. tablero.remove(posx, posy);
  36. posx -= movx[movimiento];
  37. posy -= movy[movimiento];
  38. casillasProcesadas--;
  39. }
  40.  
  41. @Override
  42. public List<Integer> getAlternativas() {
  43. // TODO
  44.  
  45. // Java 7
  46. // List<Integer> ls = Lists.newArrayList();
  47. //
  48. // for(int m = 0; m < movx.length; m++){
  49. // if(1 <= posx + movx[m] && posx + movx[m] <= tam && 1 <= posy + movy[m] && posy + movy[m] <= tam &&
  50. // tablero.get(posx + movx[m], posy + movy[m]) == null){
  51. //
  52. // ls.add(m);
  53. //
  54. // }
  55. // }
  56. // return ls;
  57.  
  58. // Java 8
  59. return IntStream.range(0, movx.length).boxed().filter(m -> 0 <= posx + movx[m]
  60. && posx + movx[m] < tam
  61. && 0 <= posy + movy[m] && posy + movy[m] < tam
  62. && tablero.get(posx + movx[m], posy + movy[m]) == null).collect(Collectors.toList());
  63. }
  64.  
  65. @Override
  66. public Table<Integer, Integer, Integer> getSolucion() {
  67. // TODO
  68. return HashBasedTable.create(tablero);
  69. }
  70.  
  71. @Override
  72. public boolean isFinal() {
  73. // TODO
  74. return casillasProcesadas == tam * tam;
  75. }
  76.  
  77. @Override
  78. public int size() {
  79. // TODO
  80. return (tam * tam) - casillasProcesadas;
  81. }
  82.  
  83. @Override
  84. public Double getObjetivo() {
  85. return Double.MIN_VALUE;
  86. }
  87.  
  88. @Override
  89. public Double getObjetivoEstimado(Integer a) {
  90. return Double.MAX_VALUE;
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement