-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
29 lines (23 loc) · 767 Bytes
/
util.py
File metadata and controls
29 lines (23 loc) · 767 Bytes
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
import re
#usi, uci
def isusi(move):
return bool(re.match("([1-9][a-i][1-9][a-i]\+?$)|([PLNSGBR]\*[1-9][a-i]$)", move))
def isuci(move):
return bool(re.match("([a-i][1-9][a-i][1-9]\+?$)|([PLNSGBR]\*[a-i][1-9]$)", move))
# changes uci to usi and usi to uci
def switchusiuci(move) -> str:
transtable = {97: 57, 98: 56, 99: 55, 100: 54, 101: 53, 102: 52, 103: 51, 104: 50, 105: 49 }
transtable.update({v: k for k, v in transtable.items()})
return move.translate(transtable)
# makes sure the move is usi
def makeusi(move) -> str:
if(isuci(move)):
return switchusiuci(move)
else:
return move
# makes sure the move is uci
def makeuci(move) -> str:
if(isusi(move)):
return switchusiuci(move)
else:
return move