Skip to content

Commit

Permalink
cambios
Browse files Browse the repository at this point in the history
  • Loading branch information
Macro21 committed Mar 14, 2018
1 parent d2367a8 commit 4612739
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 27 deletions.
Binary file modified Practica 1/bin/aStar/Board$6$1.class
Binary file not shown.
Binary file modified Practica 1/bin/aStar/Board$6.class
Binary file not shown.
Binary file modified Practica 1/bin/aStar/Board.class
Binary file not shown.
Binary file modified Practica 1/bin/aStar/Star.class
Binary file not shown.
Binary file modified Practica 1/bin/dataStructures/Cell.class
Binary file not shown.
8 changes: 7 additions & 1 deletion Practica 1/src/aStar/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ public void ready() {
public void actionPerformed(ActionEvent e) {
String err = "Los datos introducidos son incorrectos!";
try{
/*startX = 3;
startY = 9;
goalX = 8;
goalY = 8;
for(int j = 1; j<=11; j++)
matrix[6][j].setBarrier(barrierColor);*/
Star s = new Star(matrix);
if(startX == 0 || startY == 0 || goalX == 0 || goalY == 0) {
startX = Integer.parseInt(txtStartX.getText());
Expand All @@ -446,7 +452,7 @@ public void actionPerformed(ActionEvent e) {
if(matrix[startX][startY].isBarrier())
throw new Exception("Error, inicio en obstaculo!");
if(matrix[goalX][goalY].isBarrier())
throw new Exception("Error, fin en obstaculo!");
throw new Exception("Error, fin en obstaculo!");
nClicks = 0;
s.play(startX,startY,goalX,goalY);
pathPaint(s.getPath());
Expand Down
34 changes: 14 additions & 20 deletions Practica 1/src/aStar/Star.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public Cell[][] play(int startX, int startY, int goalX, int goalY) {
//Si no es meta en cerrada se meten sus hijos
else {
Cell a = this.close.get(this.close.size()-1);
getChildrens(a.getX(), a.getY(), goalX, goalY);
getChildrens(a.getX(), a.getY(), goalX, goalY,startX,startY);
}
}
return matrix;
}

//Mete en abierta todos los nodos hijos de la casilla x y
private void getChildrens(int x, int y, int goalX, int goalY) {
private void getChildrens(int x, int y, int goalX, int goalY, int startX, int startY) {
Cell m = matrix[x][y];
double sTwo = Math.sqrt(2);
double mg = m.getG();

//down
if(x+1 < N && !matrix[x+1][y].isBarrier()) {
Cell c = new Cell();
Expand All @@ -103,9 +103,9 @@ private void getChildrens(int x, int y, int goalX, int goalY) {

c.setH(stim);//stim es la distancia estimada desde este hijo al objetivo
c.setF(c.getG() + stim);

c.setFather(matrix[x+1][y].getFather());
//si no tenia padre, le pongo padre
if(matrix[x+1][y].getFather() == null) {
if(c.getFather() == null) {
c.setFather(m);
}
Data d = existsCell(this.open, x+1, y);
Expand All @@ -116,7 +116,7 @@ private void getChildrens(int x, int y, int goalX, int goalY) {
matrix[x+1][y] = c;
}

else if (d.isFound() && d.getCell().getG() >= c.getG()) {
else if (d.isFound() && d.getCell().getG() > c.getG()) {
d.getCell().setFather(m);
d.getCell().setG(m.getG() + 1);
}
Expand All @@ -128,26 +128,24 @@ else if (d.isFound() && d.getCell().getG() >= c.getG()) {
c.setX(x+1);
c.setY(y+1);
c.setG(mg + sTwo);
c.setFather(matrix[x+1][y+1].getFather());

double a = ((x+1) - goalX);
double b = ((y+1) - goalY);
double stim = Math.sqrt((Math.pow(a, 2) + Math.pow(b, 2)));

c.setH(stim);
c.setF(c.getG() + stim);

Data d = existsCell(this.open, x+1, y+1);
Data d2 = existsCell(this.close, x+1, y+1);
if(matrix[x+1][y+1].getFather() == null) {

if(c.getFather() == null) {
c.setFather(m);
}

if(!d.isFound() && !d2.isFound()) {
add(c);
matrix[x+1][y+1] = c;
}

else if ( d.isFound() && d.getCell().getG() > c.getG()) {
d.getCell().setFather(m);
d.getCell().setG(m.getG() + sTwo);
Expand All @@ -173,9 +171,7 @@ else if ( d.isFound() && d.getCell().getG() > c.getG()) {

if(matrix[x+1][y-1].getFather() == null) {
c.setFather(m);

}

if(!d.isFound() && !d2.isFound()) {
add(c);
matrix[x+1][y-1] = c;
Expand All @@ -193,6 +189,7 @@ else if ( d.isFound() && d.getCell().getG() > c.getG()) {
c.setX(x);
c.setY(y+1);
c.setG(mg + 1);
c.setFather(matrix[x][y+1].getFather());

double a = (x - goalX);
double b = ((y+1) - goalY);
Expand All @@ -204,15 +201,13 @@ else if ( d.isFound() && d.getCell().getG() > c.getG()) {
Data d = existsCell(this.open, x, y+1);
Data d2 = existsCell(this.close, x, y+1);

if(matrix[x][y+1].getFather() == null) {
if(c.getFather() == null) {
c.setFather(m);
}

if(!d.isFound() && !d2.isFound()) {
add(c);
matrix[x][y+1] = c;
}

else if ( d.isFound() && d.getCell().getG() > c.getG()) {
d.getCell().setFather(m);
d.getCell().setG(m.getG() + 1);
Expand Down Expand Up @@ -240,12 +235,10 @@ else if ( d.isFound() && d.getCell().getG() > c.getG()) {
if(matrix[x][y-1].getFather() == null) {
c.setFather(m);
}

if(!d.isFound() && !d2.isFound()) {
add(c);
matrix[x][y-1] = c;
}

else if ( d.isFound() && d.getCell().getG() > c.getG()) {
d.getCell().setFather(m);
d.getCell().setG(m.getG() + 1);
Expand Down Expand Up @@ -335,13 +328,14 @@ else if ( d.isFound() && d.getCell().getG() > c.getG()) {
add(c);
matrix[x-1][y-1] = c;
}
else if ( d.isFound() && d.getCell().getG() > c.getG()) {
else if (d.isFound() && d.getCell().getG() > c.getG()) {
d.getCell().setFather(m);
d.getCell().setG(m.getG() + sTwo);
}
}
}



private Data existsCell(ArrayList<Cell> list, int x, int y){
boolean ok = false;
Cell found = null;
Expand Down
7 changes: 1 addition & 6 deletions Practica 1/src/dataStructures/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,9 @@ public void setY(int y) {
}

public int compareTo(Cell c2) {
if(this.h < c2.getH()) {
if(this.h + this.g < c2.getH() + c2.getG()) {
return -1;
}
else if (this.h == c2.getH()) {
if(this.f < c2.getF()) {
return -1;
}
}
return 1;
}

Expand Down

0 comments on commit 4612739

Please sign in to comment.