<commit_before>import numpy as np

# start points for matching
_TOP_LEFT = 0
_TOP_RIGHT = 1
_BOTTOM_LEFT = 2
_BOTTOM_RIGHT = 3


"""
Updates the "player_relative" matrix by pushing units with "unit_id"
to the foreground, when there is some overlapping.

This operation could generate some errors in some ambiguous cases:
some pixels which don't contain the unit could be set to unit_id anyway.

Keyword arguments:
player_relative, unit_density -- observation layers
unit_id -- id of the units to move to the foreground
"""
def _move_to_foreground(player_relative, unit_density, unit_id):
	return

# Builds a disk mask using midpoint circle algorithm<commit_msg>Implemented move_to_foreground function<commit_after>import numpy as np

# start points for matching
_TOP_LEFT = 0
_TOP_RIGHT = 1
_BOTTOM_LEFT = 2
_BOTTOM_RIGHT = 3


"""
Updates the "player_relative" matrix by pushing units with "unit_id"
to the foreground, when there is some overlapping.

This operation could generate some errors in some ambiguous cases:
some pixels which don't contain the unit could be set to unit_id anyway.

Keyword arguments:
player_relative, unit_density -- observation layers
unit_id -- id of the units to move to the foreground
"""
def _move_to_foreground(player_relative, unit_density, unit_id):
	# Stores whether a pixel has changed in player_relative
	processed = np.zeros((len(player_relative), len(player_relative[0])))

	for i in range(len(player_relative)):
		for j in range(len(player_relative[0])):
			if processed[i][j] == 0 and player_relative[i][j] == unit_id:

				# Explores contiguous pixels with DFS
				# and moves them to foreground when necessary 
				stack = []
				stack.append((i, j))

				def to_foreground(i, j, player_relative, unit_density, unit_id):
					if unit_density[i, j] > 1:
						player_relative[i, j] = unit_id

				def process_pixel(i, j, player_relative, unit_density, processed, unit_id, stack):
					if processed[i, j] != 0:
						return

					processed[i, j] = 1
					to_foreground(i, j, player_relative, unit_density, unit_id)
					if player_relative[i, j] == unit_id:
						stack.append((i, j))

				while len(stack) > 0:
					cur = stack.pop()

					process_pixel(cur[0] - 1, cur[1], player_relative, unit_density, processed, unit_id, stack)
					process_pixel(cur[0] + 1, cur[1], player_relative, unit_density, processed, unit_id, stack)
					process_pixel(cur[0], cur[1] - 1, player_relative, unit_density, processed, unit_id, stack)
					process_pixel(cur[0], cur[1] + 1, player_relative, unit_density, processed, unit_id, stack)


# Builds a disk mask using midpoint circle algorithm
{'fraction_non_alphanumeric': 0.08889736741701641, 'fraction_numerical': 0.01030141167493323, 'mean_word_length': 4.578723404255319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '745825', 'n_tokens_mistral': 928, 'n_tokens_neox': 807, 'n_words': 287}