.
, 4x4 x 0 4 0 3.
- (1 3) , .
isAdjacent(other) . , : if self.x == other.x & plusmn; 1 self.x == other.x & plusmn; 1. y 8 -1, 0, 1 x, -1, 0, 1.
. self.y == other.y & plusmn; 1 self.x == other.x . x , . x - (0, 2, 4), , self.y == other.y self.y == other.y + 1. , x - (1, 3), . , .
" "? . grid.get(). , . .
, isAdjacent(), , ?
, , . enum_adjacent_vert(y_offset) enum_adjacent_horiz(x_offset). , (self.x-1, self.y+y_offset), (self.x, self.y+y_offset), (self.x+1, self.y+y_offset). , , self.x : (self.x+x_offset, self.y), (self.x+x_offset, self.y+1). self.x : (self.x+x_offset, self.y), (self.x+x_offset, self.y-1).
. , "" "" .
Say you go from left to right (increase x). You want to find a neighboring cell in the list enum_adjacent_horiz. To go from top to bottom (increase y), you will find a neighboring cell in the list enum_adjancent_vert.
source
share