Skip to content

Commit

Permalink
Fixed minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangoMango committed Sep 16, 2023
1 parent 76dfd6e commit b77b56b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/main/java/com/orangomango/chess/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public String getOutput(int time){

public String getBestMove(Board b){
writeCommand("position fen "+b.getFEN());
writeCommand(String.format("go wtime %s btime %s winc %s binc %s", b.getTime(Color.WHITE), b.getTime(Color.BLACK), b.getIncrementTime(), b.getIncrementTime()));
if (b.getMoves().size() < 5){
writeCommand("go movetime 500");
} else {
writeCommand(String.format("go wtime %s btime %s winc %s binc %s", b.getTime(Color.WHITE), b.getTime(Color.BLACK), b.getIncrementTime(), b.getIncrementTime()));
}
String output = "";
while (true) {
try {
Expand Down
49 changes: 27 additions & 22 deletions src/main/java/com/orangomango/chess/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class MainApplication extends Application{
private static boolean LANDSCAPE = true;
private static double WIDTH = 850;
private static double HEIGHT = 490;
private static int SQUARE_SIZE = (int)(LANDSCAPE ? WIDTH*0.05 : WIDTH*0.09);
private static Point2D SPACE = new Point2D(LANDSCAPE ? WIDTH*0.15 : WIDTH*0.18, (HEIGHT-SQUARE_SIZE*8)/2);
private static int SQUARE_SIZE = (int)(LANDSCAPE ? WIDTH*0.05 : WIDTH/8);
private static Point2D SPACE = new Point2D(LANDSCAPE ? WIDTH*0.15 : (WIDTH-SQUARE_SIZE*8)/2, (HEIGHT-SQUARE_SIZE*8)/2);
private static final int FPS = 40;
private static final String STARTPOS = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";

Expand Down Expand Up @@ -144,7 +144,7 @@ public void start(Stage stage){
}
}
} else {
if (!this.uiScreen.isDisabled()){
if (!this.uiScreen.isDisabled() && (LANDSCAPE || !this.showBoard)){
for (UiObject obj : this.uiScreen.getChildren()){
if (obj instanceof Clickable){
((Clickable)obj).click(e.getX(), e.getY());
Expand Down Expand Up @@ -200,11 +200,9 @@ public void start(Stage stage){
}
});

if (!LANDSCAPE){
canvas.setOnScroll(e -> {
this.showBoard = e.getDeltaY() < 0;
});
}
canvas.setOnScroll(e -> {
if (!LANDSCAPE) this.showBoard = e.getDeltaY() < 0;
});

canvas.setOnMouseReleased(e -> {
String h = getNotation(e);
Expand Down Expand Up @@ -267,7 +265,7 @@ public void start(Stage stage){
}

private UiScreen buildHomeScreen(GraphicsContext gc){
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : SPACE.getX()*1.5, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : (WIDTH-SQUARE_SIZE*6)/2, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
uiScreen.setDisabled(!this.gameFinished && (this.board.getMoves().size() > 0 || this.client != null || this.httpServer != null));
UiButton whiteButton = new UiButton(uiScreen, gc, new Rectangle2D(0.1, 0.08, 0.2, 0.2), PLAY_WHITE_IMAGE, () -> this.viewPoint = Color.WHITE);
UiButton blackButton = new UiButton(uiScreen, gc, new Rectangle2D(0.35, 0.08, 0.2, 0.2), PLAY_BLACK_IMAGE, () -> this.viewPoint = Color.BLACK);
Expand All @@ -277,6 +275,9 @@ private UiScreen buildHomeScreen(GraphicsContext gc){
UiButton singleButton = new UiButton(uiScreen, gc, new Rectangle2D(0.1, 0.3, 0.8, 0.2), SINGLE_IMAGE, () -> {
this.overTheBoard = false;
this.engineMove = true;
if (this.viewPoint == Color.BLACK){
makeEngineMove(false);
}
});
UiButton boardButton = new UiButton(uiScreen, gc, new Rectangle2D(0.1, 0.5, 0.8, 0.2), MULTI_IMAGE, () -> {
this.overTheBoard = true;
Expand Down Expand Up @@ -339,7 +340,7 @@ private UiScreen buildHomeScreen(GraphicsContext gc){
}

private UiScreen buildClockScreen(GraphicsContext gc){
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : SPACE.getX()*1.5, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : (WIDTH-SQUARE_SIZE*6)/2, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
uiScreen.setDisabled(!this.gameFinished && (this.board.getMoves().size() > 0 || this.client != null || this.httpServer != null));
UiButton backButton = new UiButton(uiScreen, gc, new Rectangle2D(0.1, 0.8, 0.2, 0.2), BACK_IMAGE, () -> this.uiScreen = buildHomeScreen(gc));
UiTextField timeField = new UiTextField(uiScreen, gc, new Rectangle2D(0.1, 0.1, 0.8, 0.2), "600");
Expand All @@ -359,7 +360,7 @@ private UiScreen buildClockScreen(GraphicsContext gc){
}

private UiScreen buildLanScreen(GraphicsContext gc){
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : SPACE.getX()*1.5, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : (WIDTH-SQUARE_SIZE*6)/2, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
uiScreen.setDisabled(!this.gameFinished && (this.board.getMoves().size() > 0 || this.client != null || this.httpServer != null));
UiButton backButton = new UiButton(uiScreen, gc, new Rectangle2D(0.1, 0.8, 0.2, 0.2), BACK_IMAGE, () -> this.uiScreen = buildHomeScreen(gc));
UiTextField ipField = new UiTextField(uiScreen, gc, new Rectangle2D(0.1, 0.1, 0.8, 0.2), "127.0.0.1");
Expand Down Expand Up @@ -427,7 +428,7 @@ private UiScreen buildLanScreen(GraphicsContext gc){
}

private UiScreen buildServerScreen(GraphicsContext gc){
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : SPACE.getX()*1.5, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
UiScreen uiScreen = new UiScreen(gc, new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : (WIDTH-SQUARE_SIZE*6)/2, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
uiScreen.setDisabled(!this.gameFinished && (this.board.getMoves().size() > 0 || this.client != null || this.httpServer != null));
UiButton backButton = new UiButton(uiScreen, gc, new Rectangle2D(0.1, 0.8, 0.2, 0.2), BACK_IMAGE, () -> this.uiScreen = buildHomeScreen(gc));
UiTextField roomField = new UiTextField(uiScreen, gc, new Rectangle2D(0.1, 0.1, 0.8, 0.2), "room-"+(int)(Math.random()*100000));
Expand Down Expand Up @@ -476,11 +477,11 @@ private void resize(double w, double h, Canvas canvas){
WIDTH = w;
HEIGHT = h;
LANDSCAPE = w > h;
SQUARE_SIZE = LANDSCAPE ? (int)Math.min(HEIGHT/8*0.6, WIDTH*0.05) : (int)(WIDTH*0.09);
SPACE = new Point2D(LANDSCAPE ? WIDTH*0.15 : WIDTH*0.18, (HEIGHT-SQUARE_SIZE*8)/2);
SQUARE_SIZE = (int)(LANDSCAPE ? Math.min(HEIGHT/8*0.6, WIDTH*0.05) : WIDTH/8);
SPACE = new Point2D(LANDSCAPE ? WIDTH*0.15 : (WIDTH-SQUARE_SIZE*8)/2, (HEIGHT-SQUARE_SIZE*8)/2);
canvas.setWidth(w);
canvas.setHeight(h);
this.uiScreen.setRect(new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : SPACE.getX()*1.5, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
this.uiScreen.setRect(new Rectangle2D(LANDSCAPE ? SPACE.getX()*1.5+SQUARE_SIZE*8 : (WIDTH-SQUARE_SIZE*6)/2, SPACE.getY(), SQUARE_SIZE*6, SQUARE_SIZE*8));
}

private Point2D getClickPoint(double x, double y){
Expand Down Expand Up @@ -722,8 +723,8 @@ private void update(GraphicsContext gc){
int bm = this.board.getMaterial(Color.BLACK);
int wm = this.board.getMaterial(Color.WHITE);
int diff = wm-bm;
if (diff < 0) gc.fillText(Integer.toString(-diff), WIDTH*0.135, this.viewPoint == Color.WHITE ? wd : bd);
if (diff > 0) gc.fillText(Integer.toString(diff), WIDTH*0.135, this.viewPoint == Color.WHITE ? bd : wd);
if (diff < 0) gc.fillText("+"+Integer.toString(-diff), WIDTH*0.135, this.viewPoint == Color.WHITE ? wd : bd);
if (diff > 0) gc.fillText("+"+Integer.toString(diff), WIDTH*0.135, this.viewPoint == Color.WHITE ? bd : wd);

// Captured pieces
List<Piece> black = this.board.getMaterialList(Color.BLACK);
Expand Down Expand Up @@ -779,14 +780,14 @@ private void update(GraphicsContext gc){

gc.save();
gc.setTextAlign(TextAlignment.RIGHT);
gc.fillText((this.httpServer == null ? "" : "Room: "+this.httpServer.getRoom()+", ")+"Eval: "+this.eval, WIDTH*0.95, HEIGHT*0.9);
gc.fillText((this.httpServer == null ? "" : "Room: "+this.httpServer.getRoom()+", ")+"Eval: "+this.eval, WIDTH*0.95, HEIGHT*0.93);
gc.restore();

// Moves played
int count = 0;
double wMove = SQUARE_SIZE*2;
double hMove = SQUARE_SIZE*0.75;
int movesAmount = LANDSCAPE ? (int)(HEIGHT/hMove) : (int)(WIDTH/wMove);
int movesAmount = LANDSCAPE ? (int)((HEIGHT-60)/hMove) : (int)(WIDTH/wMove);
for (int i = Math.max(this.board.getMoves().size()-movesAmount, 0); i < this.board.getMoves().size(); i++){
gc.setStroke(Color.BLACK);
gc.setFill(i % 2 == 0 ? Color.web("#F58B23") : Color.web("#7D4711"));
Expand All @@ -795,13 +796,17 @@ private void update(GraphicsContext gc){
xp = 10;
yp = 30+(count++)*hMove;
} else {
xp = 10+(count++)*wMove;
xp = (WIDTH-movesAmount*wMove)/2+(count++)*wMove;
yp = 30;
}
gc.fillRect(xp, yp, wMove, hMove);
gc.strokeRect(xp, yp, wMove, hMove);
gc.save();
gc.setFill(Color.BLACK);
gc.fillText((i/2+1)+"."+this.board.getMoves().get(i), xp+wMove*0.1, yp+hMove*0.75);
gc.setFont(new Font("sans-serif", hMove*0.5));
gc.setTextAlign(TextAlignment.CENTER);
gc.fillText((i/2+1)+"."+this.board.getMoves().get(i), xp+wMove*0.5, yp+hMove*0.65);
gc.restore();
}

// Time remaining
Expand Down Expand Up @@ -848,7 +853,7 @@ private void update(GraphicsContext gc){

// UI
this.uiScreen.setDisabled(!this.gameFinished && (this.board.getMoves().size() > 0 || this.client != null || this.httpServer != null));
if (!showBoard || LANDSCAPE) this.uiScreen.render();
if (!this.showBoard || LANDSCAPE) this.uiScreen.render();

if (!this.gameFinished) this.board.tick();
}
Expand Down

0 comments on commit b77b56b

Please sign in to comment.