MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / play

Function play

matrix/matrix_based_game.py:220–240  ·  view source on GitHub ↗

Processes a single move, updating the matrix and calculating the score. >>> play([['R', 'G'], ['R', 'G']], 0, 0, 2) ([['G', '-'], ['G', '-']], 3)

(
    matrix_g: list[list[str]], pos_x: int, pos_y: int, size: int
)

Source from the content-addressed store, hash-verified

218
219
220def play(
221 matrix_g: list[list[str]], pos_x: int, pos_y: int, size: int
222) -> tuple[list[list[str]], int]:
223 """
224 Processes a single move, updating the matrix and calculating the score.
225
226 >>> play([['R', 'G'], ['R', 'G']], 0, 0, 2)
227 ([['G', '-'], ['G', '-']], 3)
228 """
229
230 same_colors = find_repeat(matrix_g, pos_x, pos_y, size)
231
232 if len(same_colors) != 0:
233 for pos in same_colors:
234 matrix_g[pos[0]][pos[1]] = "-"
235 for column in range(size):
236 matrix_g = move_x(matrix_g, column, size)
237
238 matrix_g = move_y(matrix_g, size)
239
240 return (matrix_g, increment_score(len(same_colors)))
241
242
243def process_game(size: int, matrix: list[str], moves: list[tuple[int, int]]) -> int:

Callers 1

process_gameFunction · 0.85

Calls 4

find_repeatFunction · 0.85
move_xFunction · 0.85
move_yFunction · 0.85
increment_scoreFunction · 0.85

Tested by

no test coverage detected