Thinking about the features of a Cell, a Cell should probably have a Position. A Position could be a point in 2 or 3 dimensional space (or maybe additional dimensions as well in case I'm being short sighted). The important feature of a Position should be that it can calculate distance from another Position. Cells can use this distance to figure out who their neighbors are. Consider this code:
class Cell {
...
public boolean isNeighbor(Cell c){
/* this assumes the neigbor distance limit is 1 unit
as in Conway's Life */
return (this.position().distanceTo(c.position()) <= 1.0)
}
public Position position(){
return p;
}
private Position p;
}
Can also create subsets of our Game World's Cell set by filtering on Cell's isNeighbor(Cell) function, thereby just having to get the size of the subset to determine the number of neighbors.
And thinking about what the presentation will need to display the Game World, I think the model will need to have a query to get a copy of the Cell set.
No comments:
Post a Comment