Skip to content

Commit

Permalink
섹션 생성 시 주변 섹션에 적용 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
onee-only committed Dec 11, 2024
1 parent aec1c59 commit 8715204
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 51 deletions.
2 changes: 1 addition & 1 deletion board/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .internal.point import Point
from .internal.section import Section, for_each_neighbor
from .internal.section import Section
from .internal.tile import Tile
from .internal.tiles import Tiles
from .internal.tile_exception import InvalidTileException
30 changes: 29 additions & 1 deletion board/data/handler/internal/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,35 @@ def _get_or_create_section(x: int, y: int) -> Section:

if x not in BoardHandler.sections[y]:
new_section = Section.create(Point(x, y))
# TODO: 주변 섹션과의 접경타일들 숫자 업데이트

# (x, y)
delta = [
(0, 1), (0, -1), (-1, 0), (1, 0), # 상하좌우
(-1, 1), (1, 1), (-1, -1), (1, -1), # 좌상 우상 좌하 우하
]

# 주변 섹션과 새로운 섹션의 인접 타일을 서로 적용시킨다.
for dx, dy in delta:
nx, ny = x+dx, y+dy
neighbor = BoardHandler._get_section_or_none(nx, ny)
# 주변 섹션이 없을 수 있음.
if neighbor is None:
continue

if dx != 0 and dy != 0:
neighbor.apply_neighbor_diagonal(new_section)
elif dx != 0:
neighbor.apply_neighbor_horizontal(new_section)
elif dy != 0:
neighbor.apply_neighbor_vertical(new_section)

BoardHandler.sections[ny][nx] = neighbor

BoardHandler.sections[y][x] = new_section

return BoardHandler.sections[y][x]

@staticmethod
def _get_section_or_none(x: int, y: int) -> Section | None:
if y in BoardHandler.sections and x in BoardHandler.sections[y]:
return BoardHandler.sections[y][x]
10 changes: 0 additions & 10 deletions board/data/handler/test/board_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ def test_fetch(self, data, expect):

self.assertEqual(data, expect)

def test_fetch_out_of_bounds(self):
# 오른쪽 섹션 추가
start = Point(4, 3)
end = Point(6, 1)

BoardHandler.fetch(start, end)

sx, sy = 1, 0
self.assertIsNotNone(BoardHandler.sections[sy][sx])

def test_update_tile(self):
p = Point(-1, -1)

Expand Down
Loading

0 comments on commit 8715204

Please sign in to comment.