-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserInput.py
More file actions
54 lines (46 loc) · 1.76 KB
/
userInput.py
File metadata and controls
54 lines (46 loc) · 1.76 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#script to work with user input moves on terminal for ChessG
#fkyros - build v1.1
## GGames Inc© All rights reserved
#https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.nicepng.com%2Fourpic%2Fu2q8a9t4u2u2o0q8_google-logo-png-transparent-google-g-logo-black%2F&psig=AOvVaw1tQ5fatKUODSipTTf8rupQ&ust=1645015346157000&source=images&cd=vfe&ved=0CAwQjhxqFwoTCKiL-ezdgfYCFQAAAAAdAAAAABAK
import sys
#according to v1, our moves should be type as "xy(from) xy(to)"
#example: "d5 d6"
#internally, this will be translated to our code for working coordinates on our matrix (array indexes)
#example: "d5 d6" -> cFrom = (3,4), cTo(3,5)
#given a proper input move, returns a string with the From coordinate
def sliceC1(move):
# if move[2]!=" ":
# return
slice = move.split(" ")
return slice[0]
#given a proper input move, returns a string with the To coordinate
def sliceC2(move):
# if move[2]!=" ":
# return
slice = move.split(" ")
return slice[1]
#returns None if not given a valid character from a-h
def extractX(c):
x = c[0:1] #x axis value
try:
intX = int(hex(ord(x)),base=16) #ASCII value from hex to decimal
if (intX >= 97 and intX <= 104): #lowercase a-h
return intX - 96 - 1
if (intX >= 65 and intX <= 72): #uppercase A-H
return intX - 64 - 1
#-1 to fit array numeration
except:
return None
#returns None if not given a number in char
def extractY(c):
try:
return 7 - (int(c[1:2]) - 1)
#subtracting 7 due to positions in the matrix
except:
return None
# move = "b1 b3" #1,7 / 1,5
# xFrom = extractX(sliceC1(move))
# yFrom = extractY(sliceC1(move))
# xTo = extractX(sliceC2(move))
# yTo = extractY(sliceC2(move))
# print(xFrom, yFrom, xTo, yTo)