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

Function validate_moves

matrix/matrix_based_game.py:92–102  ·  view source on GitHub ↗

>>> validate_moves([(1, 2), (-1, 0)], 3) Traceback (most recent call last): ... ValueError: Move is out of bounds for a matrix.

(moves: list[tuple[int, int]], size: int)

Source from the content-addressed store, hash-verified

90
91
92def validate_moves(moves: list[tuple[int, int]], size: int) -> None:
93 """
94 >>> validate_moves([(1, 2), (-1, 0)], 3)
95 Traceback (most recent call last):
96 ...
97 ValueError: Move is out of bounds for a matrix.
98 """
99 for move in moves:
100 x, y = move
101 if not (0 <= x < size and 0 <= y < size):
102 raise ValueError("Move is out of bounds for a matrix.")
103
104
105def parse_moves(input_str: str) -> list[tuple[int, int]]:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected