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();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,22 +38,22 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
this.sf.enableControlPanelButtons();
|
this.sf.enableControlPanelButtons();
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -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