Skip to content

Commit

Permalink
Fixes UCI engine problems + Adds coordinates on board
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Mar 14, 2024
1 parent ec029a7 commit c5d6c83
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A Swing chess application and a UCI engine based on [JChess-core](https://github.com/fathzer-games/jchess-core).

## Requirements
Java 11+ to run the application and mvn to build it.
Java 17+ to run the application and mvn to build it.

## How to compile the project

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>jchess-uci</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fathzer</groupId>
Expand All @@ -54,7 +54,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -67,7 +67,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.2</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/com/fathzer/jchess/swing/ChessBoardPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fathzer.jchess.Piece;
import com.fathzer.jchess.PieceKind;

/** A Swing panel that represents a chess board.
*/
public class ChessBoardPanel extends JPanel implements MouseListener {
private static final long serialVersionUID = 1L;
public static final String SELECTION = "Selection";
Expand Down Expand Up @@ -50,6 +52,9 @@ public class ChessBoardPanel extends JPanel implements MouseListener {
private boolean manualMoves = true;
private boolean showPossibleMoves = true;
private boolean touchMove = true;
private boolean showCoordinates = true;
private Color whiteColor = new Color(255,200,100);
private Color blackColor = new Color(150,50,30);

static {
try {
Expand Down Expand Up @@ -90,6 +95,11 @@ public void setChessRules(GameBuilder<Board<Move>> rules) {
this.repaint();
}

public void setCellColors(Color whiteColor, Color blackColor) {
this.whiteColor = whiteColor;
this.blackColor = blackColor;
}

public void setShowPossibleMoves(boolean display) {
this.showPossibleMoves = display;
this.repaint();
Expand Down Expand Up @@ -117,7 +127,11 @@ private void updatePossibleMoves() {
}
}

public void setUpsideDownColor(com.fathzer.games.Color color) {
public void setShowCoordinates(boolean showCoordinates) {
this.showCoordinates = showCoordinates;
}

public void setUpsideDownColor(com.fathzer.games.Color color) {
this.invertedColor = color;
}

Expand Down Expand Up @@ -224,14 +238,27 @@ protected void drawGhost(Graphics g) {
this.sprites.draw(g);
}
protected void drawBoard(Graphics g) {
final Color white = new Color(255,200,100);
final Color black = new Color(150,50,30);
for (int row=0;row<dimension.getHeight();row++) {
for (int col=0;col<dimension.getWidth();col++) {
g.setColor((row+col)%2==0 ? white : black);
g.setColor((row+col)%2==0 ? whiteColor : blackColor);
g.fillRect(offsetX+col*squareSize, offsetY+row*squareSize, squareSize, squareSize);
}
}
if (showCoordinates) {
int fontHeight = g.getFontMetrics().getAscent();
for (int row=0;row<dimension.getHeight();row++) {
final String coordinate = Integer.toString(reverted ? row+1 : dimension.getHeight()-row);
int width = g.getFontMetrics().stringWidth(coordinate);
g.setColor(row%2==0 ? whiteColor : blackColor);
g.drawString(coordinate, offsetX+dimension.getWidth()*squareSize-width-2,offsetY+row*squareSize+fontHeight);
}
fontHeight = g.getFontMetrics().getDescent();
for (int col=0;col<dimension.getWidth();col++) {
final String coordinate = Character.toString(reverted ? 'a' + dimension.getWidth() - col -1 : 'a'+col);
g.setColor(col%2==0 ? whiteColor : blackColor);
g.drawString(coordinate, offsetX+col*squareSize+2,offsetY+dimension.getHeight()*squareSize-fontHeight);
}
}
}

protected void drawSelection(Graphics g) {
Expand Down

0 comments on commit c5d6c83

Please sign in to comment.