generated from Code-Institute-Org/p3-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconstants.py
178 lines (151 loc) · 4.79 KB
/
constants.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
constants.py
Various Constants used throughout the program
"""
import re
# maximum recursive calls for the function evaluate()
# 5 normal play; 3 dumber and quicker
MAXLEVEL = 5
# Negative number used to represent Black
COMPUTER = -1
# Positive number used to represent White
PLAYER = 1
# Values of each piece
VALUE_OF_COMPUTER_KING = -7500 # Black
VALUE_OF_PLAYER_KING = 5000 # White
# Value of each Chess Piece
KING_VALUE = 5000
QUEEN_VALUE = 900
ROOK_VALUE = 500
BISHOP_VALUE = 300
KNIGHT_VALUE = 270
PAWN_VALUE = 100
ASCII_SPACE = 32
ASCII_A_MINUS1 = 96
ASCII_A = 97
ASCII_ZERO = 48
ASCII_EIGHT = 56
BLANK = 0
# Seven Tag Rosters expected
STR_TOTAL = 7
# 7 Characters being the longest Move Text (e.g., "Qa6xb7#", "fxg1=Q+")
LINESIZE = 80 - 7
FILE_SIZE_LIMIT = 10000
EVALUATE_THRESHOLD_SCORE = 10000
# If the 'evaluate' functions computes a score less than this value,
# then the Computer will resign
STALEMATE_THRESHOLD_SCORE = -2500
DESTINATION_SQUARE_ONLY = 1 # EG e4 OR Ne2
PAWN_CAPTURE_FILE = 2 # EG exd4
PIECE_DESTINATION_SQUARE = 3 # EG Qxe1
PIECE_FILE_MOVE = 4 # EG Nge2 Nfxe4
PIECE_RANK_MOVE = 5 # EG N2d4 N6xe4
PIECE_BOTH_SQUARES = 6 # EG Nd2xe4
LONG_NOTATION = 7 # EG Ng1f3
CASTLING_MOVE = 8 # O-O or O-O-O
PLAYER_SIDE_RANK = "1" # White - Bottom row
COMPUTER_SIDE_RANK = "8" # Black - Top row
# kingside rook must be present in file 'h' in order to be castled
KINGSIDE_ROOK_FILE = "h"
# queenside rook must be present in file "a" in order to be castled
QUEENSIDE_ROOK_FILE = "a"
# A king must be present in file 'e' in order to be castled
CASTLING_KING_FILE = "e"
# Note: the ranks are always ordered from White's perspective,
# so it is labelled White's fourth rank
# Likewise for the fifth rank
FOURTH_RANK = "4" # a4...h4
FIFTH_RANK = "5" # a5...h5
# The rank (row) of white pieces
PLAYER_PAWNS_RANK = "2" # a2...h2
# The rank (row) of black pieces
COMPUTER_PAWNS_RANK = "7" # a7...h7
NOVALUE = -1
INVALID = 1
VALID = 2
ALREADY_CASTLED = 3
NO_KING_ROOK = 4
KING_MOVED = 5
ROOK_MOVED = 6
NOT_ALL_BLANK = 7
KING_IN_CHECK = 8
THROUGH_CHECK = 9
END_UP_IN_CHECK = 10
KINGSIDE = 11
QUEENSIDE = 12
TAB = "\t"
SPACE = " "
CHECK_INDICATION = "+"
CHECKMATE_INDICATION = "#"
CASTLING_KINGSIDE = "O-O"
CASTLING_QUEENSIDE = "O-O-O"
# Defined this way to keep the linter happy :)
# Note the SPACE at the end
BAD_CHESS_MOVE_FROMFILE = ("Legal Chess Move Expected From Input File. "
"Instead: "
)
# Note the SPACE at the end
BAD_EN_PASSANT_FROMFILE = "Illegal En Passant Read From Input File: "
PLAYER_WON = "1-0"
COMPUTER_WON = "0-1"
DRAW = "1/2-1/2"
KING_LETTER = "K"
QUEEN_LETTER = "Q"
ROOK_LETTER = "R"
BISHOP_LETTER = "B"
KNIGHT_LETTER = "N"
PAWN_LETTER = "P"
"""
Generate a list of the entire chessboard coordinates
['a1', 'a2' ... 'h7', 'h8']
In order to save time with 'evaluate'
generated such a list from scratch
"""
PRESET_CHESSBOARD = [chr(j+97) + chr(k+49)
for j in range(8)
for k in range(8)]
# FILE I/O
INPUT_PGN_NAME = "input.pgn"
OUTPUT_PGN_NAME = "output.pgn"
# Pauses
# Pause 2 seconds
SLEEP_VALUE = 2
# Pause longer after a Castling Move or En Passant Move
CASTLING_EP_SLEEP_VALUE = 3
# When reading & playing moves from an input file
# Pause for 4 seconds
COMPUTER_FILEIO_SLEEP_VALUE = 4
# Regular Expressions
parens_pattern = re.compile(r"[()]")
percent_pattern = re.compile(r"(\A%)|(\n%)")
en_passant_pattern = re.compile(r"\A(e\.p\.[ \n]*)+")
nag_pattern = re.compile(r"\A\$[0-9]+")
chess_move_suffix_pattern = re.compile(r"\A[A-Za-z0-9+#=:\-]*")
castling_inputfile_pattern = re.compile(r"\A((O-O-O)|(O-O)|(0-0-0)|(0-0))")
game_termination_pattern = re.compile(r"\A((1-0)|(0-1)|(1/2-1/2)|[*])")
number_periods_pattern = re.compile(r"\A([0-9]+|[.]+)")
move_number_pattern = re.compile(r"\A([0-9]+)[. ]*")
move_number_suffix_pattern = re.compile(r"\A[.][ \n]*")
castling_keyboard_pattern = re.compile(r"\A((O-O-O)|(O-O)|(0-0-0)|(0-0))\Z")
chess_move_pattern = re.compile(r"([a-h][1-8]){2}")
# 1
long_notation_pattern = re.compile(r"\A([KQRBN]?)([a-h][1-8])([a-h][1-8])",
flags=re.ASCII)
# 2
capture_2squares_pattern = re.compile(r"\A([KQRBN]?)([a-h][1-8])x([a-h][1-8])",
flags=re.ASCII)
# 3
one_square_pattern = re.compile(r"\A([KQRBN]?)([a-h][1-8])",
flags=re.ASCII)
# 4
pawn_capture_pattern = re.compile(r"\A([a-h])x([a-h][1-8])",
flags=re.ASCII)
# 5
nonpawn_capture_pattern = re.compile(r"\A([KQRBN])x([a-h][1-8])",
flags=re.ASCII)
# 6
file_pattern = re.compile(r"\A([KQRBN])([a-h])x?([a-h][1-8])",
flags=re.ASCII)
# 7
rank_pattern = re.compile(r"\A([KQRBN])([1-8])x?([a-h][1-8])",
flags=re.ASCII)