Add adjacent cells searching
authorindvdum (gotoindvdum[at]gmail[dot]com)
Mon, 16 Jul 2012 13:08:03 +0400
changeset 40daa0ff48b7d0
parent 39 27b98e729716
child 41 ce8e85452c3b
Add adjacent cells searching
icfp-model/src/main/java/ru/bosony/model/mine/Mine.java
icfp-model/src/main/java/ru/bosony/model/moving/Coordinate.java
     1.1 --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java	Mon Jul 16 04:36:47 2012 +0400
     1.2 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java	Mon Jul 16 13:08:03 2012 +0400
     1.3 @@ -220,6 +220,13 @@
     1.4  		return cells;
     1.5  	}
     1.6  
     1.7 +	public Set<Cell> getAdjacentCells(Cell cell) {
     1.8 +		Set<Cell> cells = new HashSet<Cell>();
     1.9 +		for (Coordinate coordinate : cell.getCoordinate().getAdjacentCoordinates())
    1.10 +			cells.add(getCell(coordinate));
    1.11 +		return cells;
    1.12 +	}
    1.13 +
    1.14  	public Set<Cell> findCells(CellContent content) {
    1.15  		Set<Cell> finded = new HashSet<Cell>();
    1.16  		for (int y = sizeY - 1; y >= 0; y--) {
     2.1 --- a/icfp-model/src/main/java/ru/bosony/model/moving/Coordinate.java	Mon Jul 16 04:36:47 2012 +0400
     2.2 +++ b/icfp-model/src/main/java/ru/bosony/model/moving/Coordinate.java	Mon Jul 16 13:08:03 2012 +0400
     2.3 @@ -3,54 +3,53 @@
     2.4  import java.util.HashSet;
     2.5  import java.util.Set;
     2.6  
     2.7 -
     2.8  /**
     2.9 - * @author 	indvdum (gotoindvdum[at]gmail[dot]com) <br>
    2.10 - * 			14.07.2012 1:07:51
    2.11 - *
    2.12 + * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
    2.13 + *         14.07.2012 1:07:51
    2.14 + * 
    2.15   */
    2.16  public class Coordinate {
    2.17 -	
    2.18 +
    2.19  	public Coordinate(int x, int y) {
    2.20  		this.x = x;
    2.21  		this.y = y;
    2.22  	}
    2.23 -	
    2.24 -	public int x;
    2.25 -	public int y;
    2.26 -	
    2.27 +
    2.28 +	public int	x;
    2.29 +	public int	y;
    2.30 +
    2.31  	public Coordinate left() {
    2.32  		return new Coordinate(x - 1, y);
    2.33  	}
    2.34 -	
    2.35 +
    2.36  	public Coordinate up() {
    2.37  		return new Coordinate(x, y + 1);
    2.38  	}
    2.39 -	
    2.40 +
    2.41  	public Coordinate right() {
    2.42  		return new Coordinate(x + 1, y);
    2.43  	}
    2.44 -	
    2.45 +
    2.46  	public Coordinate down() {
    2.47  		return new Coordinate(x, y - 1);
    2.48  	}
    2.49 -	
    2.50 +
    2.51  	public Coordinate leftAndUp() {
    2.52  		return new Coordinate(x - 1, y + 1);
    2.53  	}
    2.54 -	
    2.55 +
    2.56  	public Coordinate rightAndUp() {
    2.57  		return new Coordinate(x + 1, y + 1);
    2.58  	}
    2.59 -	
    2.60 +
    2.61  	public Coordinate rightAndDown() {
    2.62  		return new Coordinate(x + 1, y - 1);
    2.63  	}
    2.64 -	
    2.65 +
    2.66  	public Coordinate leftAndDown() {
    2.67  		return new Coordinate(x - 1, y - 1);
    2.68  	}
    2.69 -	
    2.70 +
    2.71  	public Set<Coordinate> getNeighboringCoordinates() {
    2.72  		Set<Coordinate> coords = new HashSet<Coordinate>();
    2.73  		coords.add(left());
    2.74 @@ -63,7 +62,16 @@
    2.75  		coords.add(leftAndDown());
    2.76  		return coords;
    2.77  	}
    2.78 -	
    2.79 +
    2.80 +	public Set<Coordinate> getAdjacentCoordinates() {
    2.81 +		Set<Coordinate> coords = new HashSet<Coordinate>();
    2.82 +		coords.add(left());
    2.83 +		coords.add(up());
    2.84 +		coords.add(right());
    2.85 +		coords.add(down());
    2.86 +		return coords;
    2.87 +	}
    2.88 +
    2.89  	public Movement getNecessaryMovement(Coordinate nCoordinate) {
    2.90  		if (left().equals(nCoordinate))
    2.91  			return Movement.LEFT;
    2.92 @@ -84,8 +92,8 @@
    2.93  	@Override
    2.94  	public boolean equals(Object obj) {
    2.95  		if (obj instanceof Coordinate)
    2.96 -			return x == ((Coordinate)obj).x && y == ((Coordinate)obj).y;
    2.97 +			return x == ((Coordinate) obj).x && y == ((Coordinate) obj).y;
    2.98  		return super.equals(obj);
    2.99  	}
   2.100 -	
   2.101 +
   2.102  }