@Test public void testFindNeighbours2() { System.out.println("findNeighbours"); Cell Cell = new Cell(0,0); Set<Cell> liveCells =new HashSet<Cell>(); liveCells.add(new Cell(0,0)); liveCells.add(new Cell(0,1)); liveCells.add(new Cell(1,0)); liveCells.add(new Cell(1,1)); Set<Cell> expResult = new HashSet<Cell>(); expResult.add(new Cell(0,0)); expResult.add(new Cell(0,1)); expResult.add(new Cell(1,0)); expResult.add(new Cell(1,1)); Set result = AbstractGameStratedgy.findNeighbours(Cell, liveCells); assertEquals(expResult, result); }
@Override public Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells) { HashSet<Cell> neighbours=new HashSet<Cell>(); int x=cell.getX(); int y=cell.getY(); Cell tempCell; for(int i=x-1;i<=x+1;i++) { if(i<0) continue; for(int j=y-1;j<=y+1;j++) { if(j<0) continue; tempCell=new Cell(i, j); if(liveCells.contains(tempCell)) { tempCell.setState(State.LIVE); } neighbours.add(tempCell); } } return neighbours; }
AbstractGameStratedgy implements GameStratedy { @Override public Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells) { HashSet<Cell> neighbours=new HashSet<Cell>(); int x=cell.getX(); int y=cell.getY(); Cell tempCell; for(int i=x-1;i<=x+1;i++) { if(i<0) continue; for(int j=y-1;j<=y+1;j++) { if(j<0) continue; tempCell=new Cell(i, j); if(liveCells.contains(tempCell)) { tempCell.setState(State.LIVE); } neighbours.add(tempCell); } } return neighbours; } }
AbstractGameStratedgy implements GameStratedy { @Override public Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells) { HashSet<Cell> neighbours=new HashSet<Cell>(); int x=cell.getX(); int y=cell.getY(); Cell tempCell; for(int i=x-1;i<=x+1;i++) { if(i<0) continue; for(int j=y-1;j<=y+1;j++) { if(j<0) continue; tempCell=new Cell(i, j); if(liveCells.contains(tempCell)) { tempCell.setState(State.LIVE); } neighbours.add(tempCell); } } return neighbours; }  }
AbstractGameStratedgy implements GameStratedy { @Override public Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells) { HashSet<Cell> neighbours=new HashSet<Cell>(); int x=cell.getX(); int y=cell.getY(); Cell tempCell; for(int i=x-1;i<=x+1;i++) { if(i<0) continue; for(int j=y-1;j<=y+1;j++) { if(j<0) continue; tempCell=new Cell(i, j); if(liveCells.contains(tempCell)) { tempCell.setState(State.LIVE); } neighbours.add(tempCell); } } return neighbours; }  @Override void setRules(Rule[] rules); @Override Rule[] getRules(); @Override Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells); }
AbstractGameStratedgy implements GameStratedy { @Override public Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells) { HashSet<Cell> neighbours=new HashSet<Cell>(); int x=cell.getX(); int y=cell.getY(); Cell tempCell; for(int i=x-1;i<=x+1;i++) { if(i<0) continue; for(int j=y-1;j<=y+1;j++) { if(j<0) continue; tempCell=new Cell(i, j); if(liveCells.contains(tempCell)) { tempCell.setState(State.LIVE); } neighbours.add(tempCell); } } return neighbours; }  @Override void setRules(Rule[] rules); @Override Rule[] getRules(); @Override Set<Cell> findNeighbours(Cell cell,Set<Cell> liveCells);  }