From 5322bd74e56da99dd6fc42ac0283a5b000a03fb9 Mon Sep 17 00:00:00 2001 From: jalpp <92553013+jalpp@users.noreply.github.com> Date: Sun, 11 Feb 2024 19:59:59 -0500 Subject: [PATCH] Update LiseChessEngine.java --- src/main/java/engine/LiseChessEngine.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/engine/LiseChessEngine.java b/src/main/java/engine/LiseChessEngine.java index 16fcf15..bf61b04 100644 --- a/src/main/java/engine/LiseChessEngine.java +++ b/src/main/java/engine/LiseChessEngine.java @@ -102,11 +102,30 @@ public void resetBoard(){ this.board = new Board(); } + + public String getImageFromFEN(String fen, boolean isBlack, String boardColor, String pieceType){ + try{ + String img; + this.board.loadFromFen(fen); + String[] getImgCord = this.board.getFen().split(" "); + + if(fen.contains("w")){ + img = "https://lichess1.org/export/fen.gif?fen=" + getImgCord[0] + "&color=white&theme=" + boardColor + "&piece=" + pieceType; + }else{ + img = "https://lichess1.org/export/fen.gif?fen=" + getImgCord[0] + "&color=black&theme=" + boardColor + "&piece=" + pieceType; + } + + return img; + + }catch(Exception e){ + return "Please provide a valid FEN!"; + } + } + public String getImageOfCurrentBoard(boolean isBlack){ - ChessUtil chessUtil = new ChessUtil(); - return chessUtil.getImageFromFEN(this.board.getFen(), isBlack, "brown", "kosal"); + return this.getImageFromFEN(this.board.getFen(), isBlack, "brown", "kosal"); }