Skip to content

Commit b27d2a7

Browse files
committed
Merge branch 'test' into main
# Conflicts: # .idea/misc.xml
2 parents b981214 + ba5779d commit b27d2a7

28 files changed

+175
-94
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
/.gradle/
2+
/build/
13
/imgui.ini
24
/PureProg 12.ttf

.idea/Chess.iml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.idea/libraries-with-intellij-classes.xml

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Mon Nov 25 01:15:20 EET 2019
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

src/main/java/com/syntech/chess/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ private void disposeWindow() {
256256
Objects.requireNonNull(glfwSetErrorCallback(null)).free();
257257
}
258258

259-
@NotNull
260-
private byte[] loadFromResources(final String fileName) {
259+
private byte @NotNull [] loadFromResources(final String fileName) {
261260
try (InputStream is = Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(fileName));
262261
ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
263262

src/main/java/com/syntech/chess/ai/AI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class AI extends Thread {
1717
private final int depth;
1818
private Board board;
1919
private Move bestMove;
20-
private Move[] currentMoves;
21-
private ArrayList<Hashtable<Move, Integer>> deepMoveScores;
22-
private ArrayList<Hashtable<Move, Integer>> deepMoveCounts;
20+
private final Move[] currentMoves;
21+
private final ArrayList<Hashtable<Move, Integer>> deepMoveScores;
22+
private final ArrayList<Hashtable<Move, Integer>> deepMoveCounts;
2323
private int currentDepth = 0;
2424
private static final int MAX_DISPLAYED_DEPTH = 3;
2525
private boolean shouldRun = false;

src/main/java/com/syntech/chess/graphic/FileChooser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class FileChooser extends Thread {
2828
/**
2929
* Whether the menu is used for saving or opening a file.
3030
*/
31-
private boolean save;
31+
private final boolean save;
3232

3333
/**
3434
* Constructs a file chooser with the specified mode ("open" by default, "save" if specified).

src/main/java/com/syntech/chess/logic/Board.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
public class Board implements Cloneable {
2626
private static final Point pieceNone = new Point(-1, -1);
27-
private int width, height;
27+
private final int width, height;
28+
protected final boolean priority;
2829
private ArrayList<Point> pieces;
2930
private ArrayList<Point> movablePieces = new ArrayList<>();
3031
protected ArrayList<Move> availableMoves = new ArrayList<>();
@@ -55,8 +56,9 @@ public class Board implements Cloneable {
5556
private Object[] errorArguments = null;
5657
private static final Piece none = PieceFactory.none();
5758

58-
private Board(@NotNull Piece[][] board, boolean initialize, boolean update, int turn) {
59+
private Board(@NotNull Piece @NotNull [] @NotNull [] board, boolean priority, boolean initialize, boolean update, int turn) {
5960
this.translation = Translation.EN_US;
61+
this.priority = priority;
6062
this.turn = turn;
6163
height = board.length;
6264
width = board.length > 0 ? board[0].length : 0;
@@ -87,24 +89,24 @@ private Board(@NotNull Piece[][] board, boolean initialize, boolean update, int
8789
}
8890
}
8991

90-
public Board(@NotNull Piece[][] board, boolean initialize, boolean update) {
91-
this(board, initialize, update, 0);
92+
public Board(@NotNull Piece[][] board, boolean priority, boolean initialize, boolean update) {
93+
this(board, priority, initialize, update, 0);
9294
}
9395

94-
public Board(@NotNull Piece[][] board, int turn) {
95-
this(board, false, false, turn);
96+
public Board(@NotNull Piece[][] board, boolean priority, int turn) {
97+
this(board, priority, false, false, turn);
9698
}
9799

98100
public Board(@NotNull String errorMessage, Object... errorArguments) {
99-
this(new Piece[0][0], false, false, 0);
101+
this(new Piece[0][0], false, false, false, 0);
100102
this.errorMessage = errorMessage;
101103
this.errorArguments = errorArguments;
102104
}
103105

104106
@Override
105107
public Object clone() throws CloneNotSupportedException {
106108
Board clone = (Board) super.clone();
107-
Board copy = new Board(board, turn);
109+
Board copy = new Board(board, priority, turn);
108110
clone.board = copy.board;
109111
clone.previousBoard = previousBoard;
110112
clone.selectedPiece = pieceNone;
@@ -140,6 +142,10 @@ public Translation getTranslation() {
140142
return translation;
141143
}
142144

145+
public boolean hasPriority() {
146+
return priority;
147+
}
148+
143149
public void setTranslation(Translation translation) {
144150
this.translation = translation;
145151
status = getStatusConditions(getTurnSide());
@@ -297,7 +303,8 @@ protected void move(int startRow, int startCol, int endRow, int endCol, boolean
297303
if (enPassantPoint.x == endRow && enPassantPoint.y == endCol
298304
&& (piece.getType() == PieceType.PAWN)
299305
&& startCol != endCol) {
300-
placePiece(PieceFactory.cell(), endRow + MovementRules.getPawnMoveDirection(enPassantPiece.getSide()), endCol);
306+
Point captured = new Point(endRow + MovementRules.getPawnMoveDirection(enPassantPiece.getSide()), endCol);
307+
placePiece(PieceFactory.cell(), captured);
301308
move.setCaptureFlag();
302309
}
303310
enPassantPoint = getEnPassantPoint(getTurnSide());
@@ -458,6 +465,7 @@ public void placePiece(Piece piece, int row, int col) {
458465
try {
459466
board[row][col] = piece;
460467
getPiece(row, col).setPosition(row, col);
468+
updatePiece(row, col);
461469
} catch (ArrayIndexOutOfBoundsException ignored) {
462470
}
463471
}
@@ -485,13 +493,20 @@ private Color getColor(int row, int col) {
485493
return cellColorIsWhite(row, col) ? Color.WHITE : Color.BLACK;
486494
}
487495

496+
public void updatePiece(int row, int col) {
497+
Piece piece = getPiece(row, col);
498+
sideCache[row][col] = piece.getSide();
499+
typeCache[row][col] = piece.getType();
500+
}
501+
502+
public void updatePiece(@NotNull Point pos) {
503+
updatePiece(pos.x, pos.y);
504+
}
505+
488506
public void updatePieces() {
489507
pieces = new ArrayList<>();
490508
for (int row = 0; row < getHeight(); row++) {
491509
for (int col = 0; col < getWidth(); col++) {
492-
Piece piece = getPiece(row, col);
493-
sideCache[row][col] = piece.getSide();
494-
typeCache[row][col] = piece.getType();
495510
if (!isFree(row, col)) {
496511
pieces.add(new Point(row, col));
497512
}
@@ -542,7 +557,7 @@ public ArrayList<Move> getAllAvailableMoves(Side side) {
542557
moves.addAll(getPiece(p.x, p.y).getAvailableCaptures(this));
543558
}
544559
}
545-
moves = MovePriorities.topPriorityMoves(moves);
560+
if (priority) moves = MovePriorities.topPriorityMoves(moves);
546561
if (side == Side.WHITE) allAvailableWhiteMoves = moves;
547562
if (side == Side.BLACK) allAvailableBlackMoves = moves;
548563
return moves;
@@ -594,7 +609,7 @@ protected void selectPiece(int row, int col) {
594609
private ArrayList<Move> getAvailableMoves(int row, int col) {
595610
if (getSide(row, col) == getTurnSide()) {
596611
ArrayList<Move> availableMoves = getPiece(row, col).getAvailableMoves(this);
597-
availableMoves = topPriorityMoves(availableMoves, row, col);
612+
if (priority) availableMoves = topPriorityMoves(availableMoves, row, col);
598613
return availableMoves;
599614
}
600615
return new ArrayList<>();
@@ -604,7 +619,7 @@ private ArrayList<Move> getAvailableMoves(int row, int col) {
604619
private ArrayList<Move> getAvailableCaptures(int row, int col) {
605620
if (getSide(row, col) == getTurnSide()) {
606621
ArrayList<Move> availableCaptures = getPiece(row, col).getAvailableCaptures(this);
607-
availableCaptures = topPriorityMoves(availableCaptures, row, col);
622+
if (priority) availableCaptures = topPriorityMoves(availableCaptures, row, col);
608623
return availableCaptures;
609624
}
610625
return new ArrayList<>();
@@ -654,7 +669,7 @@ private void advanceTurn() {
654669
}
655670

656671
public Board getMoveResultWithoutPromotion(Move move) {
657-
Board moveResult = new Board(board, turn);
672+
Board moveResult = new Board(board, priority, turn);
658673
if (move != null) {
659674
moveResult.move(move.getStartRow(), move.getStartCol(), move.getEndRow(), move.getEndCol(), false);
660675
}
@@ -779,7 +794,7 @@ public void saveToPGN(@NotNull String path, Setup setup) throws IOException {
779794
if (result.length() > 1) {
780795
sb.append(result);
781796
}
782-
printWriter.print(sb.toString());
797+
printWriter.print(sb);
783798
printWriter.close();
784799
}
785800

src/main/java/com/syntech/chess/logic/Board3D.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import java.awt.*;
88

99
public class Board3D extends Board {
10-
private int boardWidth;
10+
private final int boardWidth;
1111

12-
public Board3D(@NotNull Piece[][] board, int boardWidth, boolean initialize, boolean update) {
13-
super(board, initialize, false);
12+
public Board3D(@NotNull Piece[][] board, boolean priority, int boardWidth, boolean initialize, boolean update) {
13+
super(board, priority, initialize, false);
1414
this.boardWidth = boardWidth;
1515
if (update) {
1616
updateMovablePieces();
1717
}
1818
}
1919

20-
public Board3D(@NotNull Piece[][] board, int boardWidth, int turn) {
21-
super(board, turn);
20+
public Board3D(@NotNull Piece[][] board, boolean priority, int boardWidth, int turn) {
21+
super(board, priority, turn);
2222
this.boardWidth = boardWidth;
2323
}
2424

@@ -66,7 +66,7 @@ public int getPromotionCoordinate(@NotNull Point position) {
6666

6767
@Override
6868
public Board getMoveResultWithoutPromotion(Move move) {
69-
Board3D nextTurn = new Board3D(getBoard(), boardWidth, turn);
69+
Board3D nextTurn = new Board3D(getBoard(), priority, boardWidth, turn);
7070
if (move != null) {
7171
nextTurn.move(move.getStartRow(), move.getStartCol(), move.getEndRow(), move.getEndCol(), false);
7272
}

src/main/java/com/syntech/chess/logic/CyclicBoard.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import java.util.ArrayList;
77

88
public class CyclicBoard extends Board {
9-
public CyclicBoard(@NotNull Piece[][] board, boolean initialize, boolean update) {
10-
super(board, initialize, update);
9+
public CyclicBoard(@NotNull Piece[][] board, boolean priority, boolean initialize, boolean update) {
10+
super(board, priority, initialize, update);
1111
}
1212

13-
public CyclicBoard(@NotNull Piece[][] board, int turn) {
14-
super(board, turn);
13+
public CyclicBoard(@NotNull Piece[][] board, boolean priority, int turn) {
14+
super(board, priority, turn);
1515
}
1616

1717
private int getColumn(int col) {
@@ -53,7 +53,7 @@ public ArrayList<Move> getAllAvailableMoves(Side side) {
5353

5454
@Override
5555
public Board getMoveResultWithoutPromotion(Move move) {
56-
CyclicBoard nextTurn = new CyclicBoard(getBoard(), turn);
56+
CyclicBoard nextTurn = new CyclicBoard(getBoard(), priority, turn);
5757
if (move != null) {
5858
nextTurn.move(move.getStartRow(), move.getStartCol(), move.getEndRow(), move.getEndCol(), false);
5959
}

src/main/java/com/syntech/chess/logic/LevellingData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum LevellingData {
1313
FORCE_DOWN(false, true, false, false, true),
1414
FORCE_UP_DOWN(true, true, false, false, true);
1515

16-
private boolean canLevelUp, canLevelDown, hasResistance, hasPower, forceInvolution;
16+
private final boolean canLevelUp, canLevelDown, hasResistance, hasPower, forceInvolution;
1717

1818
LevellingData(boolean canLevelUp, boolean canLevelDown, boolean hasResistance, boolean hasPower, boolean forceInvolution) {
1919
this.canLevelUp = canLevelUp;

src/main/java/com/syntech/chess/logic/Move.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public static Move fromPGN(@NotNull String pgn, Board board) {
335335
pgn = pgn.substring(1);
336336
}
337337

338-
if (pgn.substring(pgn.length() - 1).equals("#") || pgn.substring(pgn.length() - 1).equals("+")) {
338+
if (pgn.endsWith("#") || pgn.endsWith("+")) {
339339
pgn = pgn.substring(0, pgn.length() - 1);
340340
}
341341

@@ -359,7 +359,7 @@ public static Move fromPGN(@NotNull String pgn, Board board) {
359359
pgn = pgn.substring(1);
360360
}
361361

362-
if (pgn.charAt(0) == 'x') {
362+
if (pgn.startsWith("x")) {
363363
pgn = pgn.substring(1);
364364
}
365365
}

src/main/java/com/syntech/chess/logic/PromotionInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.syntech.chess.logic;
22

33
public class PromotionInfo implements Cloneable {
4-
private int promotionCoordinate;
4+
private final int promotionCoordinate;
55
private PieceType[] possiblePromotionPieces;
66

77
public PromotionInfo(int promotionCoordinate, PieceType... pieces) {

0 commit comments

Comments
 (0)