Skip to content

Commit

Permalink
handle copies differently, make neighbors init by value and not by re…
Browse files Browse the repository at this point in the history
…ference
  • Loading branch information
mwinkens committed May 18, 2024
1 parent a69dfa8 commit 4477022
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/logic/tile_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def __init__(self, neighbors: list):
if len(neighbors) != EIGHT_NEIGHBORS:
raise ValueError(f"Neighbors are not {EIGHT_NEIGHBORS}")
for i in range(EIGHT_NEIGHBORS):
if neighbors[i] < 0 or neighbors[i] >= NUM_NEIGHBOR_STATES:
raise ValueError(f"neighbor[{i}] not in range [0 2]")
self._neighbors = neighbors
if neighbors[i] < 0 or neighbors[i] >= 3:
raise ValueError(f"neighbor[{i}] not in [0, 1]")
self._neighbors = neighbors.copy()

def encode(self) -> int:
return self._encode(NUM_NEIGHBOR_BITS)
Expand Down Expand Up @@ -101,7 +101,7 @@ def __eq__(self, other):
return NotImplemented

def __copy__(self):
return TileConnection(self._neighbors.copy())
return TileConnection(self._neighbors)

def getNeighbors(self):
return self._neighbors
Expand All @@ -111,11 +111,11 @@ def getNeighbors(self):
"""

def getFull(self) -> "TileConnection":
neighbors = self._neighbors.copy()
neighbors = self._neighbors
return TileConnection([min(n, 1) for n in neighbors])

def getEmpty(self) -> "TileConnection":
neighbors = self._neighbors.copy()
neighbors = self._neighbors
return TileConnection([n % 2 for n in neighbors])

def setNeighbor(self, neighbor_id, state):
Expand All @@ -126,6 +126,7 @@ def setNeighbor(self, neighbor_id, state):
self._neighbors[neighbor_id] = state


"""
def decode(encoded_val: int):
neighbors = []
for _ in range(EIGHT_NEIGHBORS):
Expand All @@ -135,6 +136,7 @@ def decode(encoded_val: int):
raise ValueError(f"Could not decode {encoded_val}, because it contains too much information")
neighbors.reverse()
return TileConnection(neighbors)
"""


def encodeListSmall(tile_connection_list: List[TileConnection]) -> Set[int]:
Expand Down

0 comments on commit 4477022

Please sign in to comment.