Compare commits
No commits in common. "main" and "cleanup" have entirely different histories.
|
|
@ -1,9 +1,6 @@
|
||||||
package de.mannheim.th.chess;
|
package de.mannheim.th.chess;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.ui.MainFrame;
|
import de.mannheim.th.chess.ui.MainFrame;
|
||||||
import de.mannheim.th.chess.utl.OpeningRecognizer;
|
|
||||||
|
|
||||||
// import org.apache.logging.log4j.LogManager;
|
// import org.apache.logging.log4j.LogManager;
|
||||||
// import org.apache.logging.log4j.Logger;
|
// import org.apache.logging.log4j.Logger;
|
||||||
|
|
@ -23,10 +20,8 @@ public class App {
|
||||||
* Main-Methode.
|
* Main-Methode.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) {
|
||||||
OpeningRecognizer.loadOpenings();
|
|
||||||
new MainFrame();
|
new MainFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ public class ButtonAufgebenListener extends JFrame implements ActionListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
this.sf.enableControlPanelButtons();
|
|
||||||
|
|
||||||
sf.setButtonsActions();
|
sf.setButtonsActions();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,19 +41,19 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
this.sf.showResult("Spieler "+game.getActivePlayer()+" hat gewonnen!");
|
this.sf.showResult("Spieler "+game.getActivePlayer()+" hat gewonnen!");
|
||||||
} else {
|
} else {
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
this.sf.setBoardMode(BoardMode.normal);
|
||||||
if (game.getLastMove() != null) {
|
|
||||||
sf.aktualisiereAusgabe();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sf.setCursor(null);
|
this.sf.setCursor(null);
|
||||||
|
|
||||||
//hier rotieren markieren
|
//hier rotieren markieren
|
||||||
|
|
||||||
if (game.isRotieren())
|
if(game.isRotieren())sf.setWechsel(!sf.isWechsel());
|
||||||
sf.setWechsel(!sf.isWechsel());
|
|
||||||
|
|
||||||
this.sf.erstelleBrett();
|
this.sf.erstelleBrett();
|
||||||
|
|
||||||
|
if (game.getLastMove() != null) {
|
||||||
|
|
||||||
|
sf.aktualisiereAusgabe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package de.mannheim.th.chess.domain;
|
package de.mannheim.th.chess.domain;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -30,8 +29,6 @@ public class Game {
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
private boolean rotieren, zuruecknahme;
|
private boolean rotieren, zuruecknahme;
|
||||||
|
|
||||||
ArrayList<Piece> removedPieces;
|
|
||||||
|
|
||||||
private MoveList movelist;
|
private MoveList movelist;
|
||||||
private int viewPointer;
|
private int viewPointer;
|
||||||
|
|
||||||
|
|
@ -46,7 +43,6 @@ public class Game {
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
this.startPosFen = this.board.getFen();
|
this.startPosFen = this.board.getFen();
|
||||||
removedPieces = new ArrayList<>();
|
|
||||||
|
|
||||||
clock = new Clock("blitz");
|
clock = new Clock("blitz");
|
||||||
clock.start();
|
clock.start();
|
||||||
|
|
@ -67,7 +63,6 @@ public class Game {
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
|
|
||||||
clock = new Clock(modus);
|
clock = new Clock(modus);
|
||||||
removedPieces = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,14 +102,6 @@ public class Game {
|
||||||
* @param move the move to be played
|
* @param move the move to be played
|
||||||
*/
|
*/
|
||||||
public void playMove(Move move) {
|
public void playMove(Move move) {
|
||||||
Piece removedPiece = board.getPiece(move.getTo());
|
|
||||||
if (removedPiece != Piece.NONE) {
|
|
||||||
int removedPiecesCount = removedPieces.size();
|
|
||||||
removedPieces.add(removedPiece);
|
|
||||||
if (removedPiecesCount + 1 < removedPieces.size()) {
|
|
||||||
removedPieces.removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
this.movelist.add(move);
|
this.movelist.add(move);
|
||||||
clock.pressClock();
|
clock.pressClock();
|
||||||
|
|
@ -129,11 +116,7 @@ public class Game {
|
||||||
|
|
||||||
public void undo() {
|
public void undo() {
|
||||||
this.board.undoMove();
|
this.board.undoMove();
|
||||||
Move lastMove = this.movelist.removeLast();
|
this.movelist.removeLast();
|
||||||
Piece removedPiece = board.getPiece(lastMove.getTo());
|
|
||||||
if (removedPiece != Piece.NONE) {
|
|
||||||
removedPieces.remove(removedPiece);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,22 +153,13 @@ public class Game {
|
||||||
/**
|
/**
|
||||||
* Plays the move on the board and adds it to the movelist
|
* Plays the move on the board and adds it to the movelist
|
||||||
*
|
*
|
||||||
* @param origin The square from which it moves from.
|
* @param origin The square from wich it moves from.
|
||||||
* @param desination The square where it will move to.
|
* @param desination The square where it will move to.
|
||||||
*/
|
*/
|
||||||
public void playMove(Square origin, Square desination) {
|
public void playMove(Square origin, Square desination) {
|
||||||
Move move = new Move(origin, desination);
|
Move move = new Move(origin, desination);
|
||||||
Piece removedPiece = board.getPiece(desination);
|
|
||||||
if (removedPiece != Piece.NONE) {
|
|
||||||
int removedPiecesCount = removedPieces.size();
|
|
||||||
removedPieces.add(removedPiece);
|
|
||||||
if (removedPieces.size() > removedPiecesCount + 1) {
|
|
||||||
removedPieces.removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
this.movelist.add(move);
|
this.movelist.add(move);
|
||||||
clock.pressClock();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,10 +320,6 @@ public class Game {
|
||||||
return this.viewPointer;
|
return this.viewPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Piece> getRemovedPieces() {
|
|
||||||
return removedPieces;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRotieren() {
|
public boolean isRotieren() {
|
||||||
return rotieren;
|
return rotieren;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import javax.swing.JLabel;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
|
|
@ -33,11 +32,9 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public MainFrame() {
|
public MainFrame() {
|
||||||
|
|
||||||
|
|
||||||
setBackground(Color.LIGHT_GRAY);
|
setBackground(Color.LIGHT_GRAY);
|
||||||
setResizable(true);
|
setResizable(true);
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
|
@ -90,10 +87,6 @@ public class MainFrame extends JFrame {
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
JButton pgnLoaderButton = new JButton("Lade aus PGN Datei");
|
JButton pgnLoaderButton = new JButton("Lade aus PGN Datei");
|
||||||
pgnLoaderButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
pgnLoaderButton.setForeground(Color.BLACK);
|
|
||||||
pgnLoaderButton.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
pgnLoaderButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
pgnLoaderButton.addActionListener(e -> openPgnSelectFrame());
|
pgnLoaderButton.addActionListener(e -> openPgnSelectFrame());
|
||||||
contentPane.add(pgnLoaderButton);
|
contentPane.add(pgnLoaderButton);
|
||||||
|
|
||||||
|
|
@ -120,11 +113,10 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the spielframe and game in playmode
|
* Starts the spielframe and game in playmode
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void startGame() {
|
public void startGame() {
|
||||||
if (this.game != null) {
|
if (this.game != null) {
|
||||||
//this.game.stopClock();
|
this.game.stopClock();
|
||||||
new SpielFrame(this.game);
|
new SpielFrame(this.game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class ModeSelectionFrame extends JFrame {
|
||||||
// Frame-Eigenschaften
|
// Frame-Eigenschaften
|
||||||
setTitle("Modusauswahl");
|
setTitle("Modusauswahl");
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
setBounds(100, 100, 600, 600);
|
setBounds(100, 100, 500, 500);
|
||||||
setResizable(true);
|
setResizable(true);
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,9 @@ package de.mannheim.th.chess.ui;
|
||||||
import com.github.bhlangonijr.chesslib.Square;
|
import com.github.bhlangonijr.chesslib.Square;
|
||||||
import com.github.bhlangonijr.chesslib.move.Move;
|
import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
import com.github.bhlangonijr.chesslib.move.MoveList;
|
||||||
import com.github.bhlangonijr.chesslib.Piece;
|
|
||||||
import com.github.bhlangonijr.chesslib.Side;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
import de.mannheim.th.chess.utl.Clock;
|
import de.mannheim.th.chess.utl.Clock;
|
||||||
import de.mannheim.th.chess.utl.OpeningRecognizer;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
||||||
|
|
@ -50,7 +47,6 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.Toolkit;
|
|
||||||
|
|
||||||
public class SpielFrame extends JFrame {
|
public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
|
|
@ -61,10 +57,9 @@ public class SpielFrame extends JFrame {
|
||||||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
private HashMap<JButton, String> belegungen = new HashMap<>();
|
||||||
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
||||||
private JButton undo, undo2, aufgeben, aufgeben2;
|
private JButton undo, undo2, aufgeben, aufgeben2;
|
||||||
private JTextArea ausgabe, blackRemovedPieces, whiteRemovedPieces;
|
private JTextArea ausgabe;
|
||||||
private Game game;
|
private Game game;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
private String opening;
|
|
||||||
private ArrayList<String> anzeigeMoves = new ArrayList<String>();
|
private ArrayList<String> anzeigeMoves = new ArrayList<String>();
|
||||||
private boolean wechsel = false;
|
private boolean wechsel = false;
|
||||||
|
|
||||||
|
|
@ -72,14 +67,14 @@ public class SpielFrame extends JFrame {
|
||||||
private Square selectedSquare;
|
private Square selectedSquare;
|
||||||
|
|
||||||
public enum BoardMode {
|
public enum BoardMode {
|
||||||
normal, pieceSelected, finished
|
normal, pieceSelected, finished, gameEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
*/
|
*/
|
||||||
public SpielFrame(Game game) {
|
public SpielFrame(Game game) {
|
||||||
opening = "unbekannte Eröffnung";
|
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.clock = game.getClock();
|
this.clock = game.getClock();
|
||||||
this.clock.start();
|
this.clock.start();
|
||||||
|
|
@ -87,11 +82,7 @@ public class SpielFrame extends JFrame {
|
||||||
mode = BoardMode.normal;
|
mode = BoardMode.normal;
|
||||||
|
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
setBounds(100, 100, 1920, 1080);
|
||||||
//setBounds(100, 100, 1920, 1080);
|
|
||||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
|
||||||
setBounds(0,0, d.width, d.height);
|
|
||||||
setExtendedState(JFrame.MAXIMIZED_BOTH);
|
|
||||||
setTitle("Schach");
|
setTitle("Schach");
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
|
||||||
|
|
@ -253,6 +244,9 @@ public class SpielFrame extends JFrame {
|
||||||
case finished:
|
case finished:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case gameEnd:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +272,6 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void showWin(int player) {
|
public void showWin(int player) {
|
||||||
JFrame frame = new JFrame("Result");
|
JFrame frame = new JFrame("Result");
|
||||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
@ -315,6 +308,7 @@ public class SpielFrame extends JFrame {
|
||||||
jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png"));
|
jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png"));
|
||||||
int selectedPiece = index;
|
int selectedPiece = index;
|
||||||
jb.addActionListener(e -> {
|
jb.addActionListener(e -> {
|
||||||
|
System.out.println("Test");
|
||||||
result[0] = selectedPiece;
|
result[0] = selectedPiece;
|
||||||
dialog.dispose();
|
dialog.dispose();
|
||||||
});
|
});
|
||||||
|
|
@ -399,60 +393,36 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
// ----- ViewQuicksaveButton -----
|
// ----- ViewQuicksaveButton -----
|
||||||
JButton quicksave = new JButton("Quicksave");
|
JButton quicksave = new JButton("Quicksave");
|
||||||
quicksave.setBackground(Color.LIGHT_GRAY);
|
|
||||||
quicksave.setForeground(Color.BLACK);
|
|
||||||
quicksave.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
quicksave.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
quicksave.setEnabled(true);
|
quicksave.setEnabled(true);
|
||||||
quicksave.addActionListener(new ButtonQuicksaveListener(this.game));
|
quicksave.addActionListener(new ButtonQuicksaveListener(this.game));
|
||||||
this.controlPanel.add(quicksave);
|
this.controlPanel.add(quicksave);
|
||||||
|
|
||||||
// ----- ViewFirstButton -----
|
// ----- ViewFirstButton -----
|
||||||
JButton viewFirstButton = new JButton("<<");
|
JButton viewFirstButton = new JButton("<<-");
|
||||||
viewFirstButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewFirstButton.setForeground(Color.BLACK);
|
|
||||||
viewFirstButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewFirstButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewFirstButton.setEnabled(false);
|
viewFirstButton.setEnabled(false);
|
||||||
viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this));
|
viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this));
|
||||||
this.controlPanel.add(viewFirstButton);
|
this.controlPanel.add(viewFirstButton);
|
||||||
|
|
||||||
// ----- ViewBackButton -----
|
// ----- ViewBackButton -----
|
||||||
JButton viewBackButton = new JButton("←");
|
JButton viewBackButton = new JButton("<-");
|
||||||
viewBackButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewBackButton.setForeground(Color.BLACK);
|
|
||||||
viewBackButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewBackButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewBackButton.setEnabled(false);
|
viewBackButton.setEnabled(false);
|
||||||
viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this));
|
viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this));
|
||||||
this.controlPanel.add(viewBackButton);
|
this.controlPanel.add(viewBackButton);
|
||||||
|
|
||||||
// ----- ViewForwardButton -----
|
// ----- ViewForwardButton -----
|
||||||
JButton viewForwardButton = new JButton("→");
|
JButton viewForwardButton = new JButton("->");
|
||||||
viewForwardButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewForwardButton.setForeground(Color.BLACK);
|
|
||||||
viewForwardButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewForwardButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewForwardButton.setEnabled(false);
|
viewForwardButton.setEnabled(false);
|
||||||
viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this));
|
viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this));
|
||||||
this.controlPanel.add(viewForwardButton);
|
this.controlPanel.add(viewForwardButton);
|
||||||
|
|
||||||
// ----- ViewLastButton -----
|
// ----- ViewLastButton -----
|
||||||
JButton viewLastButton = new JButton(">>");
|
JButton viewLastButton = new JButton("->>");
|
||||||
viewLastButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewLastButton.setForeground(Color.BLACK);
|
|
||||||
viewLastButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewLastButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewLastButton.setEnabled(false);
|
viewLastButton.setEnabled(false);
|
||||||
viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this));
|
viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this));
|
||||||
this.controlPanel.add(viewLastButton);
|
this.controlPanel.add(viewLastButton);
|
||||||
|
|
||||||
// ----- ViewQuickloadButton -----
|
// ----- ViewQuickloadButton -----
|
||||||
JButton quickload = new JButton("Quickload");
|
JButton quickload = new JButton("Quickload");
|
||||||
quickload.setBackground(Color.LIGHT_GRAY);
|
|
||||||
quickload.setForeground(Color.BLACK);
|
|
||||||
quickload.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
quickload.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
quickload.setEnabled(true);
|
quickload.setEnabled(true);
|
||||||
quickload.addActionListener(new ButtonQuickloadListener(this.game, this));
|
quickload.addActionListener(new ButtonQuickloadListener(this.game, this));
|
||||||
this.controlPanel.add(quickload);
|
this.controlPanel.add(quickload);
|
||||||
|
|
@ -535,38 +505,18 @@ public class SpielFrame extends JFrame {
|
||||||
statistik.setBackground(new Color(90, 90, 90));
|
statistik.setBackground(new Color(90, 90, 90));
|
||||||
statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS));
|
statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
|
||||||
ausgabe = new JTextArea();
|
ausgabe = new JTextArea();
|
||||||
ausgabe.setEditable(false);
|
ausgabe.setEditable(false);
|
||||||
ausgabe.setBackground(new Color(75, 75, 75));
|
ausgabe.setBackground(new Color(75, 75, 75));
|
||||||
ausgabe.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
ausgabe.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||||
ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
|
ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
|
||||||
ausgabe.setForeground(Color.BLACK);
|
ausgabe.setForeground(Color.BLACK);
|
||||||
ausgabe.setText("\n Bisherige Züge:\n");
|
ausgabe.setText("\n Bisherige Züge:\n");
|
||||||
|
|
||||||
whiteRemovedPieces = new JTextArea();
|
|
||||||
whiteRemovedPieces.setPreferredSize(new Dimension(300, 100));
|
|
||||||
whiteRemovedPieces.setEditable(false);
|
|
||||||
whiteRemovedPieces.setBackground(new Color(75, 75, 75));
|
|
||||||
whiteRemovedPieces.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
|
||||||
whiteRemovedPieces.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 40));
|
|
||||||
whiteRemovedPieces.setForeground(Color.WHITE);
|
|
||||||
|
|
||||||
blackRemovedPieces = new JTextArea();
|
|
||||||
blackRemovedPieces.setPreferredSize(new Dimension(300, 100));
|
|
||||||
blackRemovedPieces.setEditable(false);
|
|
||||||
blackRemovedPieces.setBackground(new Color(75, 75, 75));
|
|
||||||
blackRemovedPieces.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
|
||||||
blackRemovedPieces.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 40));
|
|
||||||
blackRemovedPieces.setForeground(Color.BLACK);
|
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(ausgabe);
|
JScrollPane scrollPane = new JScrollPane(ausgabe);
|
||||||
scrollPane.setPreferredSize(new Dimension(500, 1000));
|
|
||||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
|
||||||
statistik.add(whiteRemovedPieces);
|
|
||||||
statistik.add(scrollPane);
|
statistik.add(scrollPane);
|
||||||
statistik.add(blackRemovedPieces);
|
|
||||||
|
|
||||||
return statistik;
|
return statistik;
|
||||||
}
|
}
|
||||||
|
|
@ -574,8 +524,7 @@ public class SpielFrame extends JFrame {
|
||||||
public void aktualisiereAusgabe() {
|
public void aktualisiereAusgabe() {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
opening = OpeningRecognizer.compareOpening(game.getMoveList(), opening);
|
sb.append("\n Bisherige Züge:\n");
|
||||||
sb.append("\n Bisherige Züge: " + opening + "\n");
|
|
||||||
|
|
||||||
MoveList l = game.getMoveList();
|
MoveList l = game.getMoveList();
|
||||||
anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n");
|
anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n");
|
||||||
|
|
@ -584,18 +533,6 @@ public class SpielFrame extends JFrame {
|
||||||
sb.append(line);
|
sb.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder whitePieces = new StringBuilder();
|
|
||||||
StringBuilder blackPieces = new StringBuilder();
|
|
||||||
for (Piece piece: game.getRemovedPieces()) {
|
|
||||||
if (piece.getPieceSide() == Side.BLACK) {
|
|
||||||
blackPieces.append(piece.getFanSymbol().toUpperCase());
|
|
||||||
} else {
|
|
||||||
whitePieces.append(piece.getFanSymbol().toUpperCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blackRemovedPieces.setText(blackPieces.toString());
|
|
||||||
whiteRemovedPieces.setText(whitePieces.toString());
|
|
||||||
|
|
||||||
ausgabe.setText(sb.toString());
|
ausgabe.setText(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -612,7 +549,6 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
ausgabe.setText(sb.toString());
|
ausgabe.setText(sb.toString());
|
||||||
anzeigeMoves.removeLast();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel getUiPlayerOne() {
|
private JPanel getUiPlayerOne() {
|
||||||
|
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
package de.mannheim.th.chess.utl;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
|
||||||
|
|
||||||
public class OpeningRecognizer {
|
|
||||||
private static class Opening {
|
|
||||||
String name;
|
|
||||||
String moves;
|
|
||||||
|
|
||||||
Opening(String name, String moves) {
|
|
||||||
this.name = name;
|
|
||||||
this.moves = moves;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Opening> openingList = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void loadOpenings() throws IOException {
|
|
||||||
BufferedReader openingReader = new BufferedReader(new FileReader("src/main/resources/openings.pgn"));
|
|
||||||
StringBuilder openingName = new StringBuilder();
|
|
||||||
String moves = null;
|
|
||||||
String line;
|
|
||||||
while ((line = openingReader.readLine()) != null) {
|
|
||||||
if ((line.startsWith("[Site") && openingName.toString().equals("")) || line.equals("") ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line.startsWith("[Site")) {
|
|
||||||
openingList.add(new Opening(openingName.toString(), moves));
|
|
||||||
moves = null;
|
|
||||||
openingName.delete(0, openingName.length());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line.startsWith("[White")) {
|
|
||||||
openingName.append(line.split("\"")[1].trim());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line.startsWith("[Black")) {
|
|
||||||
openingName.append(":").append(line.split("\"")[1].trim());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
moves = line;
|
|
||||||
|
|
||||||
}
|
|
||||||
openingReader.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String compareOpening(MoveList moves, String openingBefore) {
|
|
||||||
for (Opening o: openingList) {
|
|
||||||
if (o.moves.equals(moves.toSanWithMoveNumbers().trim())) {
|
|
||||||
return o.name;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return openingBefore;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,32 +0,0 @@
|
||||||
package de.mannheim.th.chess.utl;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.Square;
|
|
||||||
import com.github.bhlangonijr.chesslib.move.Move;
|
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OpeningRecognizerTest {
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void prepareOpenings() throws IOException {
|
|
||||||
OpeningRecognizer.loadOpenings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void test() {
|
|
||||||
Move m = new Move(Square.E2, Square.E4);
|
|
||||||
MoveList moves = new MoveList();
|
|
||||||
moves.add(m);
|
|
||||||
assertEquals(OpeningRecognizer.compareOpening(moves, "Unknown"), "King's pawn Opening");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue