-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (42 loc) · 1.22 KB
/
main.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from board import (taxi, bus, underground, river)
print("Scotland Yard - The Pythonic Way")
def _predict(position: int, vehicle: str) -> list[int]:
ret = []
paths = []
match vehicle:
case "taxi":
paths = taxi
case "bus":
paths = bus
case "underground":
paths = underground
case "concealed":
paths = taxi + bus + underground + river
case _:
pass
for pair in paths:
pair = list(pair)
if position in pair:
index = bool(pair.index(position))
if pair[int(not index)] in ret:
continue
ret.append(pair[int(not index)])
return ret
def predict(positions: list[int], vehicle: str) -> list[int]:
ret = []
for position in positions:
_ret = _predict(position, vehicle)
if len(_ret) == 0:
continue
for x in _ret:
if x in ret:
continue
ret.append(x)
return ret
possible = [eval(input("Enter initial position: "))]
i = 1
while True:
print(f"\nRound {i}")
possible = predict(possible, input("Enter vehicle type: "))
print(f"Possible positions: {possible}")
i += 1