-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlanguages.py
368 lines (322 loc) · 11.8 KB
/
languages.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import chess
class English:
def __init__(self):
self.game_started = "Game started"
self.move_failed = "Move registration failed. Please redo your move."
def name(self, piece_type):
if piece_type == chess.PAWN:
return "pawn"
elif piece_type == chess.KNIGHT:
return "knight"
elif piece_type == chess.BISHOP:
return "bishop"
elif piece_type == chess.ROOK:
return "rook"
elif piece_type == chess.QUEEN:
return "queen"
elif piece_type == chess.KING:
return "king"
def comment(self, board, move):
check = ""
if board.is_checkmate():
check = " checkmate"
elif board.is_check():
check = " check"
board.pop()
if board.is_kingside_castling(move):
board.push(move)
return "castling short" + check
if board.is_queenside_castling(move):
board.push(move)
return "castling long" + check
piece = board.piece_at(move.from_square)
from_square = chess.square_name(move.from_square)
to_square = chess.square_name(move.to_square)
promotion = move.promotion
is_capture = board.is_capture(move)
board.push(move)
comment = ""
comment += self.name(piece.piece_type)
comment += " " + from_square
comment += " takes" if is_capture else " to"
comment += " " + to_square
if promotion:
comment += " promotion to " + self.name(promotion)
comment += check
return comment
class German:
def __init__(self):
self.game_started = "Das Spiel hat gestartet."
self.move_failed = "Der Zug ist ungültig, bitte wiederholen."
def name(self, piece_type):
if piece_type == chess.PAWN:
return "Bauer"
elif piece_type == chess.KNIGHT:
return "Springer"
elif piece_type == chess.BISHOP:
return "Läufer"
elif piece_type == chess.ROOK:
return "Turm"
elif piece_type == chess.QUEEN:
return "Dame"
elif piece_type == chess.KING:
return "König"
def comment(self, board, move):
check = ""
if board.is_checkmate():
check = " Schachmatt"
elif board.is_check():
check = " Schach"
board.pop()
if board.is_kingside_castling(move):
board.push(move)
return "kurze Rochade" + check
if board.is_queenside_castling(move):
board.push(move)
return "lange Rochade" + check
piece = board.piece_at(move.from_square)
from_square = chess.square_name(move.from_square)
to_square = chess.square_name(move.to_square)
promotion = move.promotion
is_capture = board.is_capture(move)
board.push(move)
comment = ""
comment += self.name(piece.piece_type)
comment += " " + from_square
comment += " schlägt" if is_capture else " nach"
comment += " " + to_square
if promotion:
comment += " Umwandlung in " + self.name(promotion)
comment += check
return comment
class Russian:
def __init__(self):
self.game_started = "игра началась"
self.move_failed = "Ошибка регистрации хода. Пожалуйста, повторите свой ход"
def name(self, piece_type):
if piece_type == chess.PAWN:
return "пешка"
elif piece_type == chess.KNIGHT:
return "конь"
elif piece_type == chess.BISHOP:
return "слон"
elif piece_type == chess.ROOK:
return "ладья"
elif piece_type == chess.QUEEN:
return "ферзь"
elif piece_type == chess.KING:
return "король"
def comment(self, board, move):
check = ""
if board.is_checkmate():
check = " шах и мат"
elif board.is_check():
check = " шах"
board.pop()
if board.is_kingside_castling(move):
board.push(move)
return "короткая рокировка" + check
if board.is_queenside_castling(move):
board.push(move)
return "длинная рокировка" + check
piece = board.piece_at(move.from_square)
from_square = chess.square_name(move.from_square)
to_square = chess.square_name(move.to_square)
promotion = move.promotion
is_capture = board.is_capture(move)
board.push(move)
comment = ""
comment += self.name(piece.piece_type)
comment += " " + from_square
comment += " бьёт" if is_capture else ""
comment += " " + to_square
if promotion:
comment += " превращение в " + self.name(promotion)
comment += check
return comment
class Turkish:
def __init__(self):
self.game_started = "Oyun başladı."
self.move_failed = "Hamle geçersiz. Lütfen hamlenizi yeniden yapın."
def capture_suffix(self, to_square):
if to_square[-1] in "158":
return "i"
elif to_square[-1] in "27":
return "yi"
elif to_square[-1] in "34":
return "ü"
else: # 6
return "yı"
def from_suffix(self, from_square):
if from_square[-1] in "1278":
return "den"
elif from_square[-1] in "345":
return "ten"
else: # 6
return "dan"
def to_suffix(self, to_square):
if to_square[-1] in "13458":
return "e"
elif to_square[-1] in "27":
return "ye"
else: # 6
return "ya"
def comment(self, board, move):
check = ""
if board.is_checkmate():
check = " şahmat"
elif board.is_check():
check = " şah"
board.pop()
if board.is_kingside_castling(move):
board.push(move)
return "kısa rok" + check
if board.is_queenside_castling(move):
board.push(move)
return "uzun rok" + check
piece = board.piece_at(move.from_square)
from_square = chess.square_name(move.from_square)
to_square = chess.square_name(move.to_square)
promotion = move.promotion
is_capture = board.is_capture(move)
board.push(move)
comment = ""
if piece.piece_type == chess.PAWN:
comment += "piyon"
elif piece.piece_type == chess.KNIGHT:
comment += "at"
elif piece.piece_type == chess.BISHOP:
comment += "fil"
elif piece.piece_type == chess.ROOK:
comment += "kale"
elif piece.piece_type == chess.QUEEN:
comment += "vezir"
elif piece.piece_type == chess.KING:
comment += "şah"
comment += " " + from_square
if is_capture:
comment += " alır"
comment += " " + to_square + "'" + self.capture_suffix(to_square)
else:
comment += "'" + self.from_suffix(from_square) + " " + to_square + "'" + self.to_suffix(to_square)
if promotion:
comment += " "
if promotion == chess.KNIGHT:
comment += "ata"
elif promotion == chess.BISHOP:
comment += "file"
elif promotion == chess.ROOK:
comment += "kaleye"
elif promotion == chess.QUEEN:
comment += "vezire"
comment += " terfi"
comment += check
return comment
class Italian:
def __init__(self):
self.game_started = "Gioco iniziato"
self.move_failed = "Registrazione spostamento non riuscita. Per favore rifai la tua mossa."
def name(self, piece_type):
if piece_type == chess.PAWN:
return "pedone"
elif piece_type == chess.KNIGHT:
return "cavallo"
elif piece_type == chess.BISHOP:
return "alfiere"
elif piece_type == chess.ROOK:
return "torre"
elif piece_type == chess.QUEEN:
return "regina"
elif piece_type == chess.KING:
return "re"
def prefix_name(self, piece_type):
if piece_type == chess.PAWN:
return "il pedone"
elif piece_type == chess.KNIGHT:
return "il cavallo"
elif piece_type == chess.BISHOP:
return "l'alfiere"
elif piece_type == chess.ROOK:
return "la torre"
elif piece_type == chess.QUEEN:
return "la regina"
elif piece_type == chess.KING:
return "il re"
def comment(self, board, move):
check = ""
if board.is_checkmate():
check = " scacco matto"
elif board.is_check():
check = " scacco"
board.pop()
if board.is_kingside_castling(move):
board.push(move)
return "arrocco corto" + check
if board.is_queenside_castling(move):
board.push(move)
return "arrocco lungo" + check
piece = board.piece_at(move.from_square)
from_square = chess.square_name(move.from_square)
to_square = chess.square_name(move.to_square)
promotion = move.promotion
is_capture = board.is_capture(move)
board.push(move)
comment = ""
if is_capture:
comment += self.prefix_name(piece.piece_type)
comment += " " + from_square
comment += " cattura"
comment += " " + to_square
else:
comment += self.name(piece.piece_type)
comment += " da " + from_square
comment += " a " + to_square
if promotion:
comment += " promuove a " + self.name(promotion)
comment += check
return comment
class French:
def __init__(self):
self.game_started = "Partie démarrée"
self.move_failed = "La reconnaissance a échoué. Veuillez réessayer."
def name(self, piece_type):
if piece_type == chess.PAWN:
return "pion"
elif piece_type == chess.KNIGHT:
return "cavalier"
elif piece_type == chess.BISHOP:
return "fou"
elif piece_type == chess.ROOK:
return "tour"
elif piece_type == chess.QUEEN:
return "reine"
elif piece_type == chess.KING:
return "roi"
def comment(self, board, move):
check = ""
if board.is_checkmate():
check = " échec et mat"
elif board.is_check():
check = " échec"
board.pop()
if board.is_kingside_castling(move):
board.push(move)
return "petit roc" + check
if board.is_queenside_castling(move):
board.push(move)
return "grand roc" + check
piece = board.piece_at(move.from_square)
from_square = chess.square_name(move.from_square)
to_square = chess.square_name(move.to_square)
promotion = move.promotion
is_capture = board.is_capture(move)
board.push(move)
comment = ""
comment += self.name(piece.piece_type)
comment += " " + from_square
comment += " prend" if is_capture else " vers"
comment += " " + to_square
if promotion:
comment += " promu en " + self.name(promotion)
comment += check
return comment