forked from bishweashwarsukla/hactoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chess_Game.py
49 lines (49 loc) · 1.33 KB
/
Chess_Game.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
def findFinalPosition(startPosition, movements):
rows = ['1', '2', '3', '4', '5', '6', '7', '8']
columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
fp = [startPosition[0], startPosition[1]]
out = ''
for i in range(len(movements)):
a = movements[i]
if a[0] == 'u':
b = int(a[1])
c = rows.index(fp[1]) + 1
c += b
c = str(c)
if c in rows:
fp[1] = c
else:
out = 'Invalid input'
break
if a[0] == 'd':
b = int(a[1])
c = rows.index(fp[1]) + 1
c -= b
c = str(c)
if c in rows:
fp[1] = c
else:
out = 'Invalid input'
break
if a[0] == 'r':
b = int(a[1])
c = columns.index(fp[0])
c += b
if c < 8:
fp[0] = columns[c]
else:
out = 'Invalid input'
break
if a[0] == 'l':
b = int(a[1])
c = columns.index(fp[0])
c -= b
if c > -1:
fp[0] = columns[c]
else:
out = 'Invalid input'
break
if out == '':
print(str(fp[0]) + str(fp[1]))
else:
print(out)