Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EstadoCaballo implements EstadoBT<Table<Integer,Integer,Integer>, Integer> {
- Integer[] movx = null;
- Integer[] movy = null;
- Table<Integer,Integer,Integer> tablero= null;
- Integer posx = null;
- Integer posy = null;
- int casillasProcesadas = 0;
- int tam = 8;
- public EstadoCaballo() {
- tam = ProblemaCaballo.getTamTablero();
- casillasProcesadas = 1;
- posx = ProblemaCaballo.getCasillaInicialX();
- posy = ProblemaCaballo.getCasillaInicialY();
- movx = ProblemaCaballo.getMovimientosX();
- movy = ProblemaCaballo.getMovimientosY();
- tablero = HashBasedTable.create();
- tablero.put(posx, posy, casillasProcesadas);
- }
- @Override
- public void avanza(Integer movimiento) {
- // TODO
- casillasProcesadas++;
- posx += movx[movimiento];
- posy += movy[movimiento];
- tablero.put(posx, posy, casillasProcesadas);
- }
- @Override
- public void retrocede(Integer movimiento) {
- // TODO
- tablero.remove(posx, posy);
- posx -= movx[movimiento];
- posy -= movy[movimiento];
- casillasProcesadas--;
- }
- @Override
- public List<Integer> getAlternativas() {
- // TODO
- // Java 7
- // List<Integer> ls = Lists.newArrayList();
- //
- // for(int m = 0; m < movx.length; m++){
- // if(1 <= posx + movx[m] && posx + movx[m] <= tam && 1 <= posy + movy[m] && posy + movy[m] <= tam &&
- // tablero.get(posx + movx[m], posy + movy[m]) == null){
- //
- // ls.add(m);
- //
- // }
- // }
- // return ls;
- // Java 8
- return IntStream.range(0, movx.length).boxed().filter(m -> 0 <= posx + movx[m]
- && posx + movx[m] < tam
- && 0 <= posy + movy[m] && posy + movy[m] < tam
- && tablero.get(posx + movx[m], posy + movy[m]) == null).collect(Collectors.toList());
- }
- @Override
- public Table<Integer, Integer, Integer> getSolucion() {
- // TODO
- return HashBasedTable.create(tablero);
- }
- @Override
- public boolean isFinal() {
- // TODO
- return casillasProcesadas == tam * tam;
- }
- @Override
- public int size() {
- // TODO
- return (tam * tam) - casillasProcesadas;
- }
- @Override
- public Double getObjetivo() {
- return Double.MIN_VALUE;
- }
- @Override
- public Double getObjetivoEstimado(Integer a) {
- return Double.MAX_VALUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement