Repository navigation
Expand file tree
/
Copy pathUtils.java
More file actions
658 lines (527 loc) · 27.4 KB
/
Copy pathUtils.java
File metadata and controls
658 lines (527 loc) · 27.4 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
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
enum castles {
whiteKingSide, whiteQueenSide, blackKingSide, blackQueenSide
}
public class Utils {
final static Map<Integer, Character> indicesTofiles = Map.of(
0, 'a',
1, 'b',
2, 'c',
3, 'd',
4, 'e',
5, 'f',
6, 'g',
7, 'h');
final static Map<castles, List<Positon>> castlingSquares = Map.of(
castles.whiteKingSide, List.of(Utils.convert("f1"), Utils.convert("g1")),
castles.whiteQueenSide, List.of(Utils.convert("d1"), Utils.convert("c1"), Utils.convert("b1")),
castles.blackKingSide, List.of(Utils.convert("f8"), Utils.convert("g8")),
castles.blackQueenSide, List.of(Utils.convert("d8"), Utils.convert("c8"), Utils.convert("b8")));
public static Positon convert(String squareName) {
return new Positon(squareName.charAt(1) - '0', Chess.filesToIndices.get(squareName.charAt(0)));
}
public static String convertToSquareName(Positon positon) throws InvalidPosition {
positon.validate();
return String.valueOf(indicesTofiles.get(positon.getIndex())) + String.valueOf(positon.getRank());
}
public static void validateSquare(String position) throws InvalidSquare {
if (position.trim().length() != 2) {
throw new InvalidSquare("Length of the square must be 2 !!");
}
char ch = Character.toLowerCase(position.charAt(0));
if (ch < 'a' || ch > 'h') {
throw new InvalidSquare("Invalid char in the position !!");
}
if (!Character.isDigit(position.charAt(1))) {
throw new InvalidSquare("Invalid Number in the position !!");
}
int num = position.charAt(1) - '0';
if (num < 1 || num > Board.CHESS_CONSTANT) {
throw new InvalidSquare("Invalid number given !!");
}
}
public static List<Positon> validKnightMoves(Positon positon) throws InvalidPosition {
positon.validate();
List<Positon> validMoves = new ArrayList<>();
// upper four moves
if (positon.getRank() < Board.CHESS_CONSTANT - 1 && positon.getIndex() < Board.CHESS_CONSTANT - 1) {
validMoves.add(new Positon(positon.getRank() + 2, positon.getIndex() + 1));
}
if (positon.getRank() < Board.CHESS_CONSTANT && positon.getIndex() < Board.CHESS_CONSTANT - 2) {
validMoves.add(new Positon(positon.getRank() + 1, positon.getIndex() + 2));
}
if (positon.getRank() < Board.CHESS_CONSTANT - 1 && positon.getIndex() > 0) {
validMoves.add(new Positon(positon.getRank() + 2, positon.getIndex() - 1));
}
if (positon.getRank() < Board.CHESS_CONSTANT && positon.getIndex() > 1) {
validMoves.add(new Positon(positon.getRank() + 1, positon.getIndex() - 2));
}
// lower four moves
if (positon.getRank() > 2 && positon.getIndex() < Board.CHESS_CONSTANT - 1) {
validMoves.add(new Positon(positon.getRank() - 2, positon.getIndex() + 1));
}
if (positon.getRank() > 1 && positon.getIndex() < Board.CHESS_CONSTANT - 2) {
validMoves.add(new Positon(positon.getRank() - 1, positon.getIndex() + 2));
}
if (positon.getRank() > 2 && positon.getIndex() > 0) {
validMoves.add(new Positon(positon.getRank() - 2, positon.getIndex() - 1));
}
if (positon.getRank() > 1 && positon.getIndex() > 1) {
validMoves.add(new Positon(positon.getRank() - 1, positon.getIndex() - 2));
}
return validMoves;
}
public static List<Positon> validBishopMoves(Positon positon) throws InvalidPosition {
positon.validate();
List<Positon> validMoves = new ArrayList<>();
// right upper diagonals loop
int j = positon.getIndex() + 1;
for (int i = positon.getRank() + 1; i <= Board.CHESS_CONSTANT && j < Board.CHESS_CONSTANT; i++) {
validMoves.add(new Positon(i, j++));
}
// left upper diagonals loop
j = positon.getIndex() - 1;
for (int i = positon.getRank() + 1; i <= Board.CHESS_CONSTANT && j >= 0; i++) {
validMoves.add(new Positon(i, j--));
}
// right lower diagonals loop
j = positon.getIndex() + 1;
for (int i = positon.getRank() - 1; i > 0 && j < Board.CHESS_CONSTANT; i--) {
validMoves.add(new Positon(i, j++));
}
// left lower diagonals loop
j = positon.getIndex() - 1;
for (int i = positon.getRank() - 1; i > 0 && j >= 0; i--) {
validMoves.add(new Positon(i, j--));
}
return validMoves;
}
public static List<Positon> validKingMoves(Board board, Positon positon)
throws InvalidPosition {
positon.validate();
Piece king = board.getPiece(positon);
List<Positon> validMoves = new ArrayList<>();
AttackingInfo attackingInfo = Attacking.getAllAttackingPositions(board);
Set<Positon> enemyAttacking = king.getColor() == COLORS.WHITE ? attackingInfo.blackAttacking
: attackingInfo.whiteAttacking;
// top left square
if (positon.getRank() < Board.CHESS_CONSTANT && positon.getIndex() > 0) {
Positon current = new Positon(positon.getRank() + 1, positon.getIndex() - 1);
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// top top square
if (positon.getRank() < Board.CHESS_CONSTANT) {
Positon current = new Positon(positon.getRank() + 1, positon.getIndex());
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// top right square
if (positon.getRank() < Board.CHESS_CONSTANT && positon.getIndex() < Board.CHESS_CONSTANT - 1) {
Positon current = new Positon(positon.getRank() + 1, positon.getIndex() + 1);
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// right right square
if (positon.getIndex() < Board.CHESS_CONSTANT - 1) {
Positon current = new Positon(positon.getRank(), positon.getIndex() + 1);
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// bottom right square
if (positon.getRank() > 1 && positon.getIndex() < Board.CHESS_CONSTANT - 1) {
Positon current = new Positon(positon.getRank() - 1, positon.getIndex() + 1);
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// bottom bottom square
if (positon.getRank() > 1) {
Positon current = new Positon(positon.getRank() - 1, positon.getIndex());
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// bottom left square
if (positon.getRank() > 1 && positon.getIndex() > 0) {
Positon current = new Positon(positon.getRank() - 1, positon.getIndex() - 1);
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
// left left square
if (positon.getIndex() > 0) {
Positon current = new Positon(positon.getRank(), positon.getIndex() - 1);
if (board.getPiece(current) == null) {
if (!enemyAttacking.contains(current)) {
validMoves.add(current);
}
} else {
if (board.getPiece(current).getColor() != king.getColor() && !enemyAttacking.contains(current)) {
validMoves.add(current);
}
}
}
return validMoves;
}
public static boolean isChekmate(Board board, COLORS color, Positon kingPositon, AttackingInfo attackingInfo)
throws InvalidPosition, IllegalMove {
// find the piece that have given chek
if (board.getPiece(kingPositon) == null || board.getPiece(kingPositon).getName() != PIECES.KING
|| board.getPiece(kingPositon).getColor() != color) {
System.out.println("Incorrect input in checkmate function !!");
return false;
}
List<Positon> checkingPositions = Utils.getChekingPieces(board, color, kingPositon);
List<Positon> kingValidPositons = Utils.validKingMoves(board, kingPositon);
Set<Positon> currentAttackings = color == COLORS.WHITE ? attackingInfo.whiteAttacking
: attackingInfo.blackAttacking;
if (checkingPositions.isEmpty()) {
return false;
}
Positon checkFrom = checkingPositions.get(0);
if (checkingPositions.size() == 1) {
if ((board.getPiece(checkFrom).getName() == PIECES.PAWN
|| board.getPiece(checkFrom).getName() == PIECES.KNIGHT) && kingValidPositons.isEmpty()
&& !currentAttackings.contains(checkFrom)) {
return true;
} else if (board.getPiece(checkFrom).getName() == PIECES.ROOK) {
List<Positon> path = Utils.rookChekPath(board, checkFrom, kingPositon);
List<Positon> piecesToComeBetween = Utils.piecesToComeBetween(board, kingPositon, path, color);
if (piecesToComeBetween.isEmpty() && !currentAttackings.contains(checkFrom)
&& kingValidPositons.isEmpty()) {
return true;
}
} else if (board.getPiece(checkFrom).getName() == PIECES.BISHOP) {
List<Positon> path = Utils.bishopChekPath(board, checkFrom, kingPositon);
List<Positon> piecesToComeBetween = Utils.piecesToComeBetween(board, kingPositon, path, color);
if (piecesToComeBetween.isEmpty() && !currentAttackings.contains(checkFrom)
&& kingValidPositons.isEmpty()) {
return true;
}
} else if (board.getPiece(checkFrom).getName() == PIECES.QUEEN) {
List<Positon> validBishopMoves = Utils.validBishopMoves(checkFrom);
List<Positon> path;
if (validBishopMoves.contains(kingPositon)) {
path = Utils.bishopChekPath(board, checkFrom, kingPositon);
} else {
path = Utils.rookChekPath(board, checkFrom, kingPositon);
}
List<Positon> piecesToComeBetween = Utils.piecesToComeBetween(board, kingPositon, path, color);
if (piecesToComeBetween.isEmpty() && !currentAttackings.contains(checkFrom)
&& kingValidPositons.isEmpty()) {
return true;
}
}
} else {
if (kingValidPositons.isEmpty()) {
return true;
}
}
return false;
}
public static List<Positon> getChekingPieces(Board board, COLORS color, Positon kingPositon)
throws InvalidPosition {
List<Positon> chekingPositons = new ArrayList<>();
Attacking attacking = new Attacking();
for (Map.Entry<Integer, List<Square>> rank : board.getMap().entrySet()) {
List<Square> currentRank = rank.getValue();
for (int i = 0; i < currentRank.size(); i++) {
Square currentSquare = currentRank.get(i);
if (currentSquare.getPiece() != null && currentSquare.getPiece().getColor() != color) {
if (currentSquare.getPiece().getName() == PIECES.PAWN) {
List<Positon> pawnAttacking = attacking.pawn(board, new Positon(rank.getKey(), i));
if (pawnAttacking.contains(kingPositon)) {
chekingPositons.add(new Positon(rank.getKey(), i));
}
} else if (currentSquare.getPiece().getName() == PIECES.ROOK) {
List<Positon> rookAttacking = attacking.rook(board, new Positon(rank.getKey(), i));
if (rookAttacking.contains(kingPositon)) {
chekingPositons.add(new Positon(rank.getKey(), i));
}
} else if (currentSquare.getPiece().getName() == PIECES.KNIGHT) {
List<Positon> knightAttacking = attacking.knight(board, new Positon(rank.getKey(), i));
if (knightAttacking.contains(kingPositon)) {
chekingPositons.add(new Positon(rank.getKey(), i));
}
} else if (currentSquare.getPiece().getName() == PIECES.BISHOP) {
List<Positon> bishopAttacking = attacking.bishop(board, new Positon(rank.getKey(), i));
if (bishopAttacking.contains(kingPositon)) {
chekingPositons.add(new Positon(rank.getKey(), i));
}
} else if (currentSquare.getPiece().getName() == PIECES.QUEEN) {
List<Positon> queenAttacking = attacking.queen(board, new Positon(rank.getKey(), i));
if (queenAttacking.contains(kingPositon)) {
chekingPositons.add(new Positon(rank.getKey(), i));
}
}
}
}
}
return chekingPositons;
}
public static List<Positon> rookChekPath(Board board, Positon rookPositon, Positon kingPositon) {
List<Positon> path = new ArrayList<>();
// checking if moving horizontal or vertical ??
if (rookPositon.getIndex() == kingPositon.getIndex()) {
// checking if going down to up
if (rookPositon.getRank() < kingPositon.getRank()) {
for (int i = rookPositon.getRank() + 1; i < kingPositon.getRank(); i++) {
path.add(new Positon(i, rookPositon.getIndex()));
}
} else {
// going up to down
for (int i = rookPositon.getRank() - 1; i > kingPositon.getRank(); i--) {
path.add(new Positon(i, rookPositon.getIndex()));
}
}
} else if (rookPositon.getRank() == kingPositon.getRank()) {
// going left to right
if (rookPositon.getIndex() < kingPositon.getIndex()) {
for (int i = rookPositon.getIndex() + 1; i < kingPositon.getIndex(); i++) {
path.add(new Positon(rookPositon.getRank(), i));
}
} else {
for (int i = rookPositon.getIndex() - 1; i > kingPositon.getIndex(); i--) {
path.add(new Positon(rookPositon.getRank(), i));
}
}
}
return path;
}
public static List<Positon> bishopChekPath(Board board, Positon bishopPositon, Positon kingPositon) {
List<Positon> path = new ArrayList<>();
// going upper right
if (bishopPositon.getIndex() < kingPositon.getIndex() && bishopPositon.getRank() < kingPositon.getRank()) {
int j = bishopPositon.getIndex() + 1;
for (int i = bishopPositon.getRank() + 1; i < kingPositon.getRank() && j < kingPositon.getIndex(); i++) {
path.add(new Positon(i, j++));
}
} else if (bishopPositon.getRank() < kingPositon.getRank()
&& bishopPositon.getIndex() > kingPositon.getIndex()) {
// going upper left
int j = bishopPositon.getIndex() - 1;
for (int i = bishopPositon.getRank() + 1; i < kingPositon.getRank() && j > kingPositon.getIndex(); i++) {
path.add(new Positon(i, j--));
}
} else if (bishopPositon.getRank() > kingPositon.getRank()
&& bishopPositon.getIndex() < kingPositon.getIndex()) {
// going lower right
int j = bishopPositon.getIndex() + 1;
for (int i = bishopPositon.getRank() - 1; i > kingPositon.getRank() && j < kingPositon.getIndex(); i--) {
path.add(new Positon(i, j++));
}
} else if (bishopPositon.getRank() > kingPositon.getRank()
&& bishopPositon.getIndex() > kingPositon.getIndex()) {
// going lower left
int j = bishopPositon.getIndex() - 1;
for (int i = bishopPositon.getRank() - 1; i > kingPositon.getRank() && j > kingPositon.getIndex(); i--) {
path.add(new Positon(i, j--));
}
}
return path;
}
enum promotion {
queen, knight, bishop, rook
}
public static void promotion(Board board, Positon promoteOn) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Piece to promote ( queen / knight / bishop / rook ) : ");
promotion piece = null;
try {
piece = promotion.valueOf(scanner.nextLine().trim().toLowerCase());
} catch (Exception e) {
System.out.println("Invalid promotion piece name !!");
Utils.promotion(board, promoteOn);
}
scanner.close();
COLORS current = board.getPiece(promoteOn).getColor();
try {
if (piece == promotion.queen) {
board.place(Utils.convertToSquareName(promoteOn), new Piece(PIECES.QUEEN, current));
} else if (piece == promotion.bishop) {
board.place(Utils.convertToSquareName(promoteOn), new Piece(PIECES.BISHOP, current));
} else if (piece == promotion.knight) {
board.place(Utils.convertToSquareName(promoteOn), new Piece(PIECES.KNIGHT, current));
} else if (piece == promotion.rook) {
board.place(Utils.convertToSquareName(promoteOn), new Piece(PIECES.ROOK, current));
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
// when in chek This function returns the pieces that can come between and
// remove the chek
public static List<Positon> piecesToComeBetween(Board board, Positon kingPositon,
List<Positon> chekPath, COLORS color) throws InvalidPosition, IllegalMove {
List<Positon> positons = new ArrayList<>();
Attacking attacking = new Attacking();
Map<Integer, List<Square>> innerMap = board.getMap();
for (Map.Entry<Integer, List<Square>> rank : innerMap.entrySet()) {
List<Square> currentRank = rank.getValue();
for (int i = 0; i < currentRank.size(); i++) {
Piece currentPiece = currentRank.get(i).getPiece();
if (currentPiece != null && currentPiece.getColor() == color) {
if (currentPiece.getName() == PIECES.PAWN) {
ValidateMoves validateMoves = new ValidateMoves();
List<Positon> pawnPositons = validateMoves.pawn(board, new Positon(rank.getKey(), i));
boolean canComeBetween = false;
Positon pawnPositon = null;
for (Positon positon : pawnPositons) {
if (chekPath.contains(positon)) {
canComeBetween = true;
pawnPositon = positon;
break;
}
}
if (canComeBetween) {
board.move(board, new Positon(rank.getKey(), i), pawnPositon);
AttackingInfo newattackingInfo = Attacking.getAllAttackingPositions(board);
Set<Positon> opponentAttacking = color == COLORS.WHITE ? newattackingInfo.blackAttacking
: newattackingInfo.whiteAttacking;
if (!opponentAttacking.contains(kingPositon)) {
positons.add(new Positon(rank.getKey(), i));
}
board.informalMove(pawnPositon, new Positon(rank.getKey(), i));
}
} else if (currentPiece.getName() == PIECES.ROOK) {
List<Positon> rookAttacking = attacking.rook(board, new Positon(rank.getKey(), i));
boolean canComeBetween = false;
Positon rookPositon = null;
for (Positon positon : rookAttacking) {
if (chekPath.contains(positon)) {
canComeBetween = true;
rookPositon = positon;
break;
}
}
if (canComeBetween) {
board.move(board, new Positon(rank.getKey(), i), rookPositon);
AttackingInfo newattackingInfo = Attacking.getAllAttackingPositions(board);
Set<Positon> opponentAttacking = color == COLORS.WHITE ? newattackingInfo.blackAttacking
: newattackingInfo.whiteAttacking;
if (!opponentAttacking.contains(kingPositon)) {
positons.add(new Positon(rank.getKey(), i));
}
board.informalMove(rookPositon, new Positon(rank.getKey(), i));
}
} else if (currentPiece.getName() == PIECES.BISHOP) {
List<Positon> bishopAttacking = attacking.bishop(board, new Positon(rank.getKey(), i));
boolean canComeBetween = false;
Positon bishopPositon = null;
for (Positon positon : bishopAttacking) {
if (chekPath.contains(positon)) {
canComeBetween = true;
bishopPositon = positon;
break;
}
}
if (canComeBetween) {
board.move(board, new Positon(rank.getKey(), i), bishopPositon);
AttackingInfo newattackingInfo = Attacking.getAllAttackingPositions(board);
Set<Positon> opponentAttacking = color == COLORS.WHITE ? newattackingInfo.blackAttacking
: newattackingInfo.whiteAttacking;
if (!opponentAttacking.contains(kingPositon)) {
positons.add(new Positon(rank.getKey(), i));
}
board.informalMove(bishopPositon, new Positon(rank.getKey(), i));
}
} else if (currentPiece.getName() == PIECES.KNIGHT) {
List<Positon> knightPositons = attacking.knight(board, new Positon(rank.getKey(), i));
boolean canComeBetween = false;
Positon knightPositon = null;
for (Positon positon : knightPositons) {
if (chekPath.contains(positon)) {
canComeBetween = true;
knightPositon = positon;
break;
}
}
if (canComeBetween) {
board.move(board, new Positon(rank.getKey(), i), knightPositon);
AttackingInfo newattackingInfo = Attacking.getAllAttackingPositions(board);
Set<Positon> opponentAttacking = color == COLORS.WHITE ? newattackingInfo.blackAttacking
: newattackingInfo.whiteAttacking;
if (!opponentAttacking.contains(kingPositon)) {
positons.add(new Positon(rank.getKey(), i));
}
board.informalMove(knightPositon, new Positon(rank.getKey(), i));
}
} else if (currentPiece.getName() == PIECES.QUEEN) {
List<Positon> queenPositons = attacking.queen(board, new Positon(rank.getKey(), i));
boolean canComeBetween = false;
Positon queenPositon = null;
for (Positon positon : queenPositons) {
if (chekPath.contains(positon)) {
canComeBetween = true;
queenPositon = positon;
break;
}
}
if (canComeBetween) {
board.move(board, new Positon(rank.getKey(), i), queenPositon);
AttackingInfo newattackingInfo = Attacking.getAllAttackingPositions(board);
Set<Positon> opponentAttacking = color == COLORS.WHITE ? newattackingInfo.blackAttacking
: newattackingInfo.whiteAttacking;
if (!opponentAttacking.contains(kingPositon)) {
positons.add(new Positon(rank.getKey(), i));
}
board.informalMove(queenPositon, new Positon(rank.getKey(), i));
}
}
}
}
}
return positons;
}
}