Skip to content

Commit

Permalink
Merge pull request #32 from chenle02/hotfix-branch-Mau
Browse files Browse the repository at this point in the history
Better pr for topo
  • Loading branch information
chenle02 authored Apr 2, 2024
2 parents a7b3904 + d13fbdd commit 624e96d
Showing 1 changed file with 18 additions and 34 deletions.
52 changes: 18 additions & 34 deletions tetris_ballistic/tetris_ballistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,43 +1708,15 @@ def depth_first_search(row, col):

return hole_counter

def hole_statistics(self, substrate):
"""
Computes the statistics of the holes in the substrate.
Args:
substrate (numpy.ndarray): The substrate to compute the statistics of the holes in.
Returns:
tuple: A tuple containing the number of holes, the average hole size, the maximum hole size, and the minimum hole size.
"""
def depth_first_search(row, col):
# Checking boundaries and if cell is a 0
if 0 <= row < len(substrate_copy) and 0 <= col < len(substrate_copy[0]) and substrate_copy[row][col] == 0:
substrate_copy[row][col] = -1
depth_first_search(row + 1, col)
depth_first_search(row - 1, col)
depth_first_search(row, col + 1)
depth_first_search(row, col - 1)
def hole_statistics(self, interval = 10):
steps = self.height // interval

hole_counter = 0
hole_sizes = []
substrate_copy = substrate.copy()
hole_hist = {}

for i in range(len(substrate_copy)):
for j in range(len(substrate_copy[0])):
if substrate_copy[i][j] == 0:
hole_size = 0
depth_first_search(i, j)
for k in range(len(substrate_copy)):
for l in range(len(substrate_copy[0])):
if substrate_copy[k][l] == -1:
hole_size += 1
substrate_copy[k][l] = 0
hole_sizes.append(hole_size)
hole_counter += 1
for i in range(interval):
hole_hist[min(int(i*steps), self.height-1)] = self.count_holes_stack(min(int(i*steps), self.height-1))

return hole_counter, np.mean(hole_sizes), np.max(hole_sizes), np.min(hole_sizes)
return hole_hist

def count_holes_stack(self, frame_id=None, verbose=False):
"""
Expand Down Expand Up @@ -1798,6 +1770,18 @@ def dfs_stack(r, c):

return hole_count

def height_to_frame(self, height):
"""
This will return the minimum frame number of a given substrate given the
height of a substrate. This can be used with count_holes_stack to
identify the number of holes given a specific height of the substrate.
"""

frame_id = self.substrate[height, :]
frame_id = int( (np.min(frame_id[np.nonzero(frame_id)])) )

return frame_id

def PrintStatus(self, brief: bool = False, tostring: bool = False) -> str:
"""
Print the step/status of the class
Expand Down

0 comments on commit 624e96d

Please sign in to comment.