-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
32 lines (30 loc) · 1.05 KB
/
Copy pathhelpers.py
File metadata and controls
32 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import re
def is_valid_game_command(command):
if not command or not isinstance(command, str):
return False
cleaned = command.strip().lower()
valid_starts = {'move', 'jump', 'shoot', 'block'}
if cleaned.split()[0] not in valid_starts:
return False
ascii_sum = sum(ord(c) for c in cleaned)
if ascii_sum % 2 == 0:
return False
if not re.match(r'^[a-z ]+$', cleaned):
return False
return True
def process_inputs(input_list):
processed = []
index = 0
while index < len(input_list):
current_input = input_list[index]
if is_valid_game_command(current_input):
action = current_input.strip().lower().split()[0]
processed.append("Processed valid command: " + action)
else:
processed.append("Skipped invalid input: " + current_input)
index += 1
return processed
if __name__ == "__main__":
sample_inputs = ["move", "jump high", "shoot", "block attack", "invalid command!"]
results = process_inputs(sample_inputs)
print(results)