# HG changeset patch # User indvdum (gotoindvdum[at]gmail[dot]com) # Date 1342429683 -14400 # Node ID daa0ff48b7d055580eecf86d0dbf70db9f2d39b5 # Parent 27b98e7297160760fd2b3d1c1019cb8059ea65bf Add adjacent cells searching diff -r 27b98e729716 -r daa0ff48b7d0 icfp-model/src/main/java/ru/bosony/model/mine/Mine.java --- a/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Mon Jul 16 04:36:47 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/mine/Mine.java Mon Jul 16 13:08:03 2012 +0400 @@ -220,6 +220,13 @@ return cells; } + public Set getAdjacentCells(Cell cell) { + Set cells = new HashSet(); + for (Coordinate coordinate : cell.getCoordinate().getAdjacentCoordinates()) + cells.add(getCell(coordinate)); + return cells; + } + public Set findCells(CellContent content) { Set finded = new HashSet(); for (int y = sizeY - 1; y >= 0; y--) { diff -r 27b98e729716 -r daa0ff48b7d0 icfp-model/src/main/java/ru/bosony/model/moving/Coordinate.java --- a/icfp-model/src/main/java/ru/bosony/model/moving/Coordinate.java Mon Jul 16 04:36:47 2012 +0400 +++ b/icfp-model/src/main/java/ru/bosony/model/moving/Coordinate.java Mon Jul 16 13:08:03 2012 +0400 @@ -3,54 +3,53 @@ import java.util.HashSet; import java.util.Set; - /** - * @author indvdum (gotoindvdum[at]gmail[dot]com)
- * 14.07.2012 1:07:51 - * + * @author indvdum (gotoindvdum[at]gmail[dot]com)
+ * 14.07.2012 1:07:51 + * */ public class Coordinate { - + public Coordinate(int x, int y) { this.x = x; this.y = y; } - - public int x; - public int y; - + + public int x; + public int y; + public Coordinate left() { return new Coordinate(x - 1, y); } - + public Coordinate up() { return new Coordinate(x, y + 1); } - + public Coordinate right() { return new Coordinate(x + 1, y); } - + public Coordinate down() { return new Coordinate(x, y - 1); } - + public Coordinate leftAndUp() { return new Coordinate(x - 1, y + 1); } - + public Coordinate rightAndUp() { return new Coordinate(x + 1, y + 1); } - + public Coordinate rightAndDown() { return new Coordinate(x + 1, y - 1); } - + public Coordinate leftAndDown() { return new Coordinate(x - 1, y - 1); } - + public Set getNeighboringCoordinates() { Set coords = new HashSet(); coords.add(left()); @@ -63,7 +62,16 @@ coords.add(leftAndDown()); return coords; } - + + public Set getAdjacentCoordinates() { + Set coords = new HashSet(); + coords.add(left()); + coords.add(up()); + coords.add(right()); + coords.add(down()); + return coords; + } + public Movement getNecessaryMovement(Coordinate nCoordinate) { if (left().equals(nCoordinate)) return Movement.LEFT; @@ -84,8 +92,8 @@ @Override public boolean equals(Object obj) { if (obj instanceof Coordinate) - return x == ((Coordinate)obj).x && y == ((Coordinate)obj).y; + return x == ((Coordinate) obj).x && y == ((Coordinate) obj).y; return super.equals(obj); } - + }