New convertPieceToDTO method in ChessEngine
parent
f07c534205
commit
86eb04d391
|
|
@ -1,5 +1,9 @@
|
|||
package de.hs_mannheim.informatik.chess.model;
|
||||
|
||||
import de.hs_mannheim.informatik.chess.model.MoveDTO;
|
||||
import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
||||
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -71,6 +75,14 @@ public class ChessEngine {
|
|||
}
|
||||
}
|
||||
|
||||
private PieceDTO convertPieceToDTO(Piece piece) {
|
||||
if (piece == null || piece.equals(Piece.NONE)) return null;
|
||||
String color = piece.name().startsWith("WHITE") ? "WHITE" : "BLACK";
|
||||
String type = piece.name().substring(piece.name().indexOf('_') + 1); // "PAWN", "KING"...
|
||||
String symbol = pieceToUnicode(piece);
|
||||
return new PieceDTO(type, color, symbol);
|
||||
}
|
||||
|
||||
public boolean isMated() {
|
||||
return board.isMated();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue