Compare commits
No commits in common. "Main" and "GitBranch" have entirely different histories.
|
|
@ -1,259 +0,0 @@
|
||||||
1. Methode toPGN ist vorhanden in Klasse Game.java!!! Mit MoveGenerator werden schon alle legalen züge angezeigt!!!
|
|
||||||
|
|
||||||
2. Klassen von GPT zusammengefasst:
|
|
||||||
https://chatgpt.com/share/684326dc-4ea0-8012-8c10-8b34993140b7
|
|
||||||
|
|
||||||
Event:
|
|
||||||
|
|
||||||
Die Klasse Event beschreibt ein Schachturnier oder -ereignis mit Name, Ort, Datum, Zeitkontrollen, Rundenstruktur und referenzierten PGN-Daten.
|
|
||||||
|
|
||||||
|
|
||||||
EventType:
|
|
||||||
|
|
||||||
EventType beschreibt den strukturellen Typ eines Schachturniers (z. B. KO-System, Rundenturnier oder Analyseveranstaltung).
|
|
||||||
|
|
||||||
|
|
||||||
Game:
|
|
||||||
|
|
||||||
Die Klasse Game speichert und verwaltet alle Informationen einer Schachpartie – wie Züge, Spieler, Kommentare und Metadaten – und erlaubt deren Analyse, Bearbeitung und Ausgabe im PGN-Format.
|
|
||||||
|
|
||||||
|
|
||||||
GameContext:
|
|
||||||
|
|
||||||
Die Klasse GameContext stellt alle benötigten Informationen und Methoden bereit, um Rochaden und Schachvarianten (z. B. Chess960) regelkonform zu verwalten und korrekt zu validieren.
|
|
||||||
|
|
||||||
|
|
||||||
GameFactory:
|
|
||||||
|
|
||||||
GameFactory stellt statische Hilfsmethoden bereit, um neue Schachobjekte (Spiel, Spieler, Runde, Event) schnell und einheitlich zu erzeugen.
|
|
||||||
|
|
||||||
|
|
||||||
GameMode:
|
|
||||||
|
|
||||||
GameMode legt fest, ob eine Partie zwischen Menschen, Maschinen oder gemischt (z. B. Engine vs Mensch) gespielt wird.
|
|
||||||
|
|
||||||
|
|
||||||
GameResult:
|
|
||||||
|
|
||||||
GameResult beschreibt, wie eine Schachpartie geendet hat (Sieg, Remis oder noch laufend) und verknüpft dies mit der entsprechenden PGN-Notation.
|
|
||||||
|
|
||||||
|
|
||||||
MoveGeneratorException
|
|
||||||
|
|
||||||
MoveGeneratorException signalisiert Fehler beim Generieren von Schachzügen und erlaubt dabei flexible Fehlerbeschreibungen.
|
|
||||||
|
|
||||||
|
|
||||||
MoveList
|
|
||||||
|
|
||||||
MoveList verwaltet eine Folge von Schachzügen und erlaubt deren Umwandlung, Validierung und Darstellung in verschiedenen Notationen basierend auf einer Ausgangsstellung.
|
|
||||||
|
|
||||||
|
|
||||||
GameLoader:
|
|
||||||
|
|
||||||
Die Klasse GameLoader lädt eine vollständige Schachpartie inklusive aller Metadaten und Züge aus einem PGN-Dateiiterator und wandelt sie in ein Game-Objekt um.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GenericPlayer:
|
|
||||||
|
|
||||||
Die Klasse GenericPlayer implementiert das Player-Interface und speichert die wichtigsten Eigenschaften eines Schachspielers wie Name, Elo, Typ (Mensch/Maschine) und Beschreibung.
|
|
||||||
|
|
||||||
|
|
||||||
Mode:
|
|
||||||
|
|
||||||
Mode beschreibt den Austragungsort einer Partie: entweder als Präsenzspiel am Brett (OTB) oder über einen Online-Server (ICS).
|
|
||||||
|
|
||||||
|
|
||||||
MovePerTime:
|
|
||||||
|
|
||||||
MovePerTime beschreibt eine Zeitkontrolle, bei der eine bestimmte Anzahl an Zügen in einer definierten Zeit (in Millisekunden) gespielt werden muss, z. B. 40/5400 (40 Züge in 90 Minuten).
|
|
||||||
|
|
||||||
|
|
||||||
Player:
|
|
||||||
|
|
||||||
Player ist ein Interface, das die grundlegenden Eigenschaften und Methoden eines Schachspielers festlegt, darunter ID, Name, Elo, Typ und eine ausführliche Beschreibung.
|
|
||||||
|
|
||||||
|
|
||||||
PlayerType:
|
|
||||||
|
|
||||||
PlayerType unterscheidet, ob ein Spieler ein Mensch (HUMAN) oder eine Engine (ENGINE) ist.
|
|
||||||
|
|
||||||
|
|
||||||
Round:
|
|
||||||
|
|
||||||
Round speichert eine bestimmte Runde eines Schachturniers und enthält eine Liste aller Partien (Game), die in dieser Runde gespielt werden.
|
|
||||||
|
|
||||||
|
|
||||||
Termination:
|
|
||||||
|
|
||||||
Termination gibt an, warum eine Partie beendet wurde, z. B. regulär, durch Zeitüberschreitung, Regelverstoß oder Abbruch.
|
|
||||||
|
|
||||||
|
|
||||||
TimeControl:
|
|
||||||
|
|
||||||
TimeControl speichert verschiedene Zeitregelungen für eine Partie – etwa klassische Zeitkontrollen, Bonuszeiten (Inkrement), feste Zugvorgaben, Knoten-/Tiefenlimits (für Engines) und gibt sie als PGN-kompatible Zeichenkette zurück.
|
|
||||||
|
|
||||||
|
|
||||||
TimeControlType:
|
|
||||||
|
|
||||||
TimeControlType gibt an, in welchem Modus eine Zeitkontrolle funktioniert, z. B. klassisches Zeitlimit mit Inkrement, Zeit pro Zug, feste Tiefe oder Knotenzahl (für Engines).
|
|
||||||
|
|
||||||
|
|
||||||
VariationType:
|
|
||||||
|
|
||||||
VariationType gibt an, welche Schachvariante gespielt wird – z. B. Standard-Schach, Chess960 oder Varianten mit speziellen Rochaderegeln oder Figurenmechaniken.
|
|
||||||
|
|
||||||
|
|
||||||
Move:
|
|
||||||
|
|
||||||
Move repräsentiert einen einzelnen Schachzug mit Start- und Zielfeld, optionaler Bauernumwandlung sowie SAN-Notation, und kann als Ereignis (BoardEvent) weiterverarbeitet werden.
|
|
||||||
|
|
||||||
|
|
||||||
MoveConversionException:
|
|
||||||
|
|
||||||
MoveConversionException signalisiert, dass ein Zug nicht korrekt aus einem Text (z. B. "e2e99" oder "z9z8Q") in ein gültiges Move-Objekt umgewandelt werden konnte.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MoveException:
|
|
||||||
|
|
||||||
MoveException signalisiert, dass ein Zug nicht auf dem aktuellen Spielstand ausgeführt werden kann – typischerweise, weil er regelwidrig, unmöglich oder logisch inkonsistent ist.
|
|
||||||
|
|
||||||
|
|
||||||
MoveGenerator:
|
|
||||||
|
|
||||||
MoveGenerator stellt statische Hilfsmethoden bereit, um aus einem gegebenen Schachbrettzustand alle möglichen Züge (pseudo-legal oder legal) zu erzeugen, einschließlich Spezialzüge wie Rochade oder Bauernumwandlungen.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PgnException
|
|
||||||
|
|
||||||
Die Klasse PgnException signalisiert Laufzeitfehler beim Parsen oder Einlesen von PGN-Schachpartien.
|
|
||||||
|
|
||||||
|
|
||||||
PgnHolder
|
|
||||||
|
|
||||||
Die Klasse PgnHolder verwaltet das Einlesen, Speichern und Abrufen von Schachpartien aus PGN-Dateien und organisiert dabei Spieler, Events und Spiele zentral in einer leicht zugänglichen Struktur.
|
|
||||||
|
|
||||||
|
|
||||||
PgnIterator
|
|
||||||
|
|
||||||
Die Klasse PgnIterator ermöglicht das speicherschonende Durchiterieren von Schachpartien in einer PGN-Datei, indem sie zeilenweise liest und jede Partie einzeln verarbeitet.
|
|
||||||
|
|
||||||
|
|
||||||
PgnLoadListener
|
|
||||||
|
|
||||||
Die Schnittstelle PgnLoadListener erlaubt es, auf Fortschritte beim Laden von PGN-Partien zu reagieren, indem sie bei jedem Ladefortschritt benachrichtigt wird.
|
|
||||||
|
|
||||||
|
|
||||||
PgnProperty
|
|
||||||
|
|
||||||
|
|
||||||
Die Klasse PgnProperty modelliert eine einzelne PGN-Eigenschaft (Tag) und stellt Hilfsmethoden bereit, um sie aus einer Textzeile zu erkennen und zu extrahieren.
|
|
||||||
|
|
||||||
|
|
||||||
UnicodePrinter
|
|
||||||
|
|
||||||
|
|
||||||
Die Klasse UnicodePrinter druckt ein Schachbrett-Objekt (Board) als ASCII-Art mit Unicode-Schachsymbolen zeilenweise in die Konsole oder in einen beliebigen Ausgabestrom.
|
|
||||||
|
|
||||||
|
|
||||||
LargeFile
|
|
||||||
|
|
||||||
|
|
||||||
Die Klasse LargeFile erlaubt das effiziente und speicherschonende zeilenweise Lesen großer Textdateien oder Eingabeströme durch Bereitstellung eines einfachen Java-Iterators.
|
|
||||||
|
|
||||||
|
|
||||||
StringUtil
|
|
||||||
|
|
||||||
|
|
||||||
Die Klasse StringUtil stellt nützliche Methoden zur Verfügung, um Zeichenketten effizient zu analysieren, zu verändern und zu übersetzen – insbesondere bei der Verarbeitung von Schach-PGN-Daten.
|
|
||||||
|
|
||||||
|
|
||||||
XorShiftRandom
|
|
||||||
|
|
||||||
Die Klasse XorShiftRandom implementiert einen leistungsfähigen, einfachen Pseudozufallszahlengenerator auf Basis des Xorshift-Verfahrens, der deterministische long-Werte durch Bitoperationen erzeugt.
|
|
||||||
|
|
||||||
|
|
||||||
Bitboard
|
|
||||||
|
|
||||||
Die Klasse Bitboard stellt für jedes Schachfeld und diverse Feldergruppen (Reihen, Linien, Diagonalen) Bitmasken bereit, um Schachpositionen effizient mit Bitoperationen zu verarbeiten.
|
|
||||||
|
|
||||||
|
|
||||||
Board
|
|
||||||
|
|
||||||
Die Klasse Board modelliert ein vollständiges Schachbrett inklusive Spielregeln, Figurenpositionen, Zugverlauf und ermöglicht die Validierung, Durchführung und Rücknahme von Schachzügen.
|
|
||||||
|
|
||||||
|
|
||||||
BoardEvent
|
|
||||||
|
|
||||||
Das Interface BoardEvent definiert die Struktur für Ereignisse, die beim Ändern des Schachbretts ausgelöst und an Listener weitergegeben werden können.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BoardEventListener
|
|
||||||
|
|
||||||
Das Interface BoardEventListener erlaubt es, auf Ereignisse wie Züge oder Statusänderungen des Schachbretts zu reagieren, indem es über die Methode onEvent() benachrichtigt wird.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BoardEventType
|
|
||||||
|
|
||||||
Das Enum BoardEventType definiert die Arten von Ereignissen, die auf einem Schachbrett ausgelöst und über Event-Listener verarbeitet werden können – etwa beim Ziehen, Zurücknehmen oder Laden.
|
|
||||||
|
|
||||||
|
|
||||||
CastleRight
|
|
||||||
|
|
||||||
Das Enum CastleRight beschreibt, ob eine Seite im Schach kurz, lang, beides oder gar nicht rochieren darf.
|
|
||||||
|
|
||||||
|
|
||||||
Constants
|
|
||||||
|
|
||||||
Die Klasse Constants bündelt feste, zentrale Informationen und Züge wie die Start-FEN, Rochadepfade und Figur-Notation, um typische Schachsituationen schnell und konsistent abrufen zu können.
|
|
||||||
|
|
||||||
|
|
||||||
DiagonalA1H8
|
|
||||||
|
|
||||||
Die Enum DiagonalA1H8 listet alle rechtsschiefen (↘️) Diagonalen des Schachbretts als konstante Werte mit eindeutiger Namensgebung der Begrenzungsfelder auf.
|
|
||||||
|
|
||||||
|
|
||||||
DiagonalH1A8
|
|
||||||
|
|
||||||
Die Enum DiagonalH1A8 listet alle linksschiefen (↙️) Diagonalen des Schachbretts auf, wobei jede Diagonale durch ihre Randfelder eindeutig benannt ist.
|
|
||||||
|
|
||||||
|
|
||||||
File
|
|
||||||
|
|
||||||
Das Enum File beschreibt die Spalten (A–H) des Schachbretts samt zugehöriger Notation und ermöglicht deren einfache Nutzung in Code und Notationen.
|
|
||||||
|
|
||||||
|
|
||||||
MoveBackup
|
|
||||||
|
|
||||||
Die Klasse MoveBackup speichert alle relevanten Zustandsinformationen eines Schachbretts vor einem Zug, um diesen später vollständig rückgängig machen zu können.
|
|
||||||
|
|
||||||
|
|
||||||
Piece
|
|
||||||
|
|
||||||
Die Klasse Piece repräsentiert jede konkrete Schachfigur mit Farbe und Typ und bietet Methoden zur Erstellung und Notation dieser Figuren.
|
|
||||||
|
|
||||||
|
|
||||||
PieceType
|
|
||||||
|
|
||||||
PieceType beschreibt die Typen von Schachfiguren (z. B. Turm, König) und verknüpft sie mit ihrer algebraischen Notation für einfache Identifikation und Verarbeitung.
|
|
||||||
|
|
||||||
|
|
||||||
Rank
|
|
||||||
|
|
||||||
Rank beschreibt die horizontalen Reihen des Schachbretts und stellt deren numerische Notation zur Verfügung, um Positionen eindeutig identifizieren zu können.
|
|
||||||
|
|
||||||
|
|
||||||
Side
|
|
||||||
|
|
||||||
Side repräsentiert eine der beiden Spielerparteien im Schach – Weiß oder Schwarz – und ermöglicht den einfachen Wechsel der Seite mit der Methode flip().
|
|
||||||
|
|
||||||
|
|
||||||
Square
|
|
||||||
|
|
||||||
Square ist ein mächtiges enum, das jedes Schachfeld eindeutig repräsentiert und dabei zahlreiche Hilfsmethoden zur Brettlogik und Bitboard-Darstellung bereitstellt. Es ist eine der Grundpfeiler des gesamten Schachsystems.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
Quellen
|
|
||||||
|
|
||||||
Thomas Müller | 3021788
|
|
||||||
Timer https://chatgpt.com/c/6857ff1e-7ff4-8006-aba3-60d3a2dd59b4
|
|
||||||
|
|
||||||
Valentin Weller | 3019075
|
|
||||||
|
|
||||||
Junit: https://chatgpt.com/share/6859a713-4b98-8012-8cb2-a9f3c7fb37c8
|
|
||||||
QuickSave: https://chatgpt.com/share/6859a73f-e750-8012-a168-f9fa7c5487bd
|
|
||||||
PGNs: https://chatgpt.com/share/6859a8f1-d3c4-8012-98f4-6ae4b057be73
|
|
||||||
https://chatgpt.com/share/6859a95a-cca8-8012-bbbe-4e4b4517d5d9
|
|
||||||
|
|
||||||
Eröffnungserkennung: https://github.com/hell-sh/CompactChessOpenings/blob/master/src/sh/hell/compactchess/game/Opening.java
|
|
||||||
|
|
||||||
Quellen
|
|
||||||
|
|
||||||
Justin Muravjev 3014931
|
|
||||||
|
|
||||||
ChatGPT:
|
|
||||||
https://chatgpt.com/share/685a60b4-dad0-8012-86a8-ca9a7e6eb76b
|
|
||||||
|
|
||||||
|
|
@ -10,12 +10,13 @@
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>schach</name>
|
<name>schach</name>
|
||||||
<description>A simple schach project</description>
|
<description>A simple schach.</description>
|
||||||
<url>http://www.example.com</url>
|
<url>http://www.example.com</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.release>17</maven.compiler.release>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
@ -26,31 +27,29 @@
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Schachlib -->
|
<!-- Schachlib (bhlangonijr) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.bhlangonijr</groupId>
|
<groupId>com.github.bhlangonijr</groupId>
|
||||||
<artifactId>chesslib</artifactId>
|
<artifactId>chesslib</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.3.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>5.10.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mockito damit man Controller und Gui besser testen kann-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>5.10.2</version>
|
<version>5.11.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Mockito -->
|
</dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>5.11.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
@ -91,58 +90,12 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
<plugins>
|
|
||||||
<!-- Java Compiler Plugin -->
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<release>17</release>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- PMD Plugin -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-pmd-plugin</artifactId>
|
|
||||||
<version>3.21.0</version>
|
|
||||||
<configuration>
|
|
||||||
<!-- Set to 17 until PMD supports 21 -->
|
|
||||||
<targetJdk>17</targetJdk>
|
|
||||||
<failOnViolation>false</failOnViolation>
|
|
||||||
<printFailingErrors>true</printFailingErrors>
|
|
||||||
<linkXRef>false</linkXRef>
|
|
||||||
<rulesets>
|
|
||||||
<ruleset>rulesets/java/quickstart.xml</ruleset>
|
|
||||||
<ruleset>rulesets/java/basic.xml</ruleset>
|
|
||||||
<ruleset>rulesets/java/braces.xml</ruleset>
|
|
||||||
<ruleset>rulesets/java/unusedcode.xml</ruleset>
|
|
||||||
<ruleset>rulesets/java/imports.xml</ruleset>
|
|
||||||
</rulesets>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- Surefire Plugin for tests -->
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>3.3.0</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
<version>3.6.1</version>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,15 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.game.Game;
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
|
||||||
import de.hs_mannheim.informatik.chess.model.MoveDTO;
|
import de.hs_mannheim.informatik.chess.model.MoveDTO;
|
||||||
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
||||||
import de.hs_mannheim.informatik.chess.model.Timer;
|
|
||||||
import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||||
|
import de.hs_mannheim.informatik.chess.view.MainGui;
|
||||||
|
|
||||||
public class GameController {
|
public class GameController {
|
||||||
GameGui gui;
|
GameGui gui;
|
||||||
|
|
@ -25,58 +23,25 @@ public class GameController {
|
||||||
GameEndCallback callback;
|
GameEndCallback callback;
|
||||||
|
|
||||||
private boolean gameOver = false;
|
private boolean gameOver = false;
|
||||||
private int selectedRow = -1;
|
private int selectedRow = -1, selectedCol = -1;
|
||||||
private int selectedCol = -1;
|
|
||||||
private List<int[]> highlightedFields = new ArrayList<>();
|
private List<int[]> highlightedFields = new ArrayList<>();
|
||||||
private boolean gameWasResignedOrDrawn = false;
|
|
||||||
private GameMode gameMode;
|
|
||||||
|
|
||||||
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback, GameMode gameMode) {
|
|
||||||
this(gui, engine, callback); // ruft anderen Konstruktor auf
|
|
||||||
this.gameMode = gameMode;
|
|
||||||
if (gameMode != null) {
|
|
||||||
engine.initTimers(gameMode.minutes, gameMode.incrementSeconds);
|
|
||||||
setupAndStartTimers();
|
|
||||||
}
|
|
||||||
addWindowCloseListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Für Creative/PGN-Mode (ohne Zeit)
|
|
||||||
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback) {
|
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback) {
|
||||||
this.gui = gui;
|
this.gui = gui;
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.gameMode = null;
|
engine.initTimers(3, 0);
|
||||||
addWindowCloseListener();
|
time();
|
||||||
// KEINE Timer initialisieren
|
|
||||||
initListeners();
|
initListeners();
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
}
|
}
|
||||||
|
private void time() {
|
||||||
private void setupAndStartTimers() {
|
engine.getWhiteTimer().setOnTick(secs -> gui.updateWhiteTimerLabel(secs));
|
||||||
if (engine.getWhiteTimer() != null) {
|
engine.getBlackTimer().setOnTick(secs -> gui.updateBlackTimerLabel(secs));
|
||||||
engine.getWhiteTimer().setOnTick(secs -> gui.updateWhiteTimerLabel(secs));
|
engine.getWhiteTimer().setOnTimeout(() -> onTimeout("WHITE"));
|
||||||
engine.getWhiteTimer().setOnTimeout(() -> onTimeout("WHITE"));
|
engine.getBlackTimer().setOnTimeout(() -> onTimeout("BLACK"));
|
||||||
engine.getWhiteTimer().stop(); // <-- WICHTIG!
|
engine.getWhiteTimer().start();
|
||||||
}
|
|
||||||
if (engine.getBlackTimer() != null) {
|
|
||||||
engine.getBlackTimer().setOnTick(secs -> gui.updateBlackTimerLabel(secs));
|
|
||||||
engine.getBlackTimer().setOnTimeout(() -> onTimeout("BLACK"));
|
|
||||||
engine.getBlackTimer().stop(); // <-- WICHTIG!
|
|
||||||
}
|
|
||||||
// Timer-Labels initial setzen
|
|
||||||
if (engine.getWhiteTimer() != null) gui.updateWhiteTimerLabel(engine.getWhiteTimer().getSecondsLeft());
|
|
||||||
if (engine.getBlackTimer() != null) gui.updateBlackTimerLabel(engine.getBlackTimer().getSecondsLeft());
|
|
||||||
|
|
||||||
// Aktuellen Spieler-Timer starten:
|
|
||||||
if (engine.getCurrentPlayer().equals("WHITE")) {
|
|
||||||
engine.getWhiteTimer().start();
|
|
||||||
} else {
|
|
||||||
engine.getBlackTimer().start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int flipRow(int row) {
|
private int flipRow(int row) {
|
||||||
return gui.isFlipped() ? 7 - row : row;
|
return gui.isFlipped() ? 7 - row : row;
|
||||||
}
|
}
|
||||||
|
|
@ -84,20 +49,6 @@ public class GameController {
|
||||||
return gui.isFlipped() ? 7 - col : col;
|
return gui.isFlipped() ? 7 - col : col;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWindowCloseListener() {
|
|
||||||
if (gui.getFrame() != null) {
|
|
||||||
gui.getFrame().addWindowListener(new java.awt.event.WindowAdapter() {
|
|
||||||
@Override
|
|
||||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
|
||||||
if (!gameOver) {
|
|
||||||
engine.quicksave();
|
|
||||||
MainController.engineRAM = engine;
|
|
||||||
}
|
|
||||||
new MainController();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void initListeners() {
|
private void initListeners() {
|
||||||
for (int row = 0; row < 8; row++) {
|
for (int row = 0; row < 8; row++) {
|
||||||
for (int col = 0; col < 8; col++) {
|
for (int col = 0; col < 8; col++) {
|
||||||
|
|
@ -175,42 +126,42 @@ public class GameController {
|
||||||
// --- AUFGEBEN-BUTTON ---
|
// --- AUFGEBEN-BUTTON ---
|
||||||
gui.getResignButton().addActionListener(e -> {
|
gui.getResignButton().addActionListener(e -> {
|
||||||
if (gameOver) return;
|
if (gameOver) return;
|
||||||
int answer = JOptionPane.showConfirmDialog(
|
|
||||||
|
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||||
null,
|
null,
|
||||||
"Willst du wirklich aufgeben?",
|
"Willst du wirklich aufgeben?",
|
||||||
"Aufgeben",
|
"Aufgeben",
|
||||||
JOptionPane.YES_NO_OPTION
|
javax.swing.JOptionPane.YES_NO_OPTION
|
||||||
);
|
);
|
||||||
if (answer == JOptionPane.YES_OPTION) {
|
if (answer == javax.swing.JOptionPane.YES_OPTION) {
|
||||||
gameOver = true;
|
gameOver = true;
|
||||||
gameWasResignedOrDrawn = true; // <<<<<<
|
|
||||||
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||||
gui.displayMessage(winner + " gewinnt durch Aufgabe!");
|
gui.displayMessage(winner + " gewinnt durch Aufgabe!");
|
||||||
if (engine.getWhiteTimer() != null) engine.getWhiteTimer().stop();
|
engine.getWhiteTimer().stop();
|
||||||
if (engine.getBlackTimer() != null) engine.getBlackTimer().stop();
|
engine.getBlackTimer().stop();
|
||||||
askForRestart();
|
askForRestart();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --- PATT-/REMIS-BUTTON ---
|
||||||
gui.getDrawButton().addActionListener(e -> {
|
gui.getDrawButton().addActionListener(e -> {
|
||||||
if (gameOver) return;
|
if (gameOver) return;
|
||||||
int answer = JOptionPane.showConfirmDialog(
|
|
||||||
|
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||||
null,
|
null,
|
||||||
"Remis anbieten? (Das Spiel endet sofort unentschieden)",
|
"Remis anbieten? (Das Spiel endet sofort unentschieden)",
|
||||||
"Remis",
|
"Remis",
|
||||||
JOptionPane.YES_NO_OPTION
|
javax.swing.JOptionPane.YES_NO_OPTION
|
||||||
);
|
);
|
||||||
if (answer == JOptionPane.YES_OPTION) {
|
if (answer == javax.swing.JOptionPane.YES_OPTION) {
|
||||||
gameOver = true;
|
gameOver = true;
|
||||||
gameWasResignedOrDrawn = true; // <<<<<<
|
|
||||||
gui.displayMessage("Remis! (durch Einigung)");
|
gui.displayMessage("Remis! (durch Einigung)");
|
||||||
if (engine.getWhiteTimer() != null) engine.getWhiteTimer().stop();
|
engine.getWhiteTimer().stop();
|
||||||
if (engine.getBlackTimer() != null) engine.getBlackTimer().stop();
|
engine.getBlackTimer().stop();
|
||||||
askForRestart();
|
askForRestart();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
gui.getUndoButton().addActionListener(e -> {
|
gui.getUndoButton().addActionListener(e -> {
|
||||||
// Wer ist am Zug? (Das ist der, der gefragt wird)
|
// Wer ist am Zug? (Das ist der, der gefragt wird)
|
||||||
String currentPlayer = engine.getCurrentPlayer(); // "WHITE" oder "BLACK"
|
String currentPlayer = engine.getCurrentPlayer(); // "WHITE" oder "BLACK"
|
||||||
|
|
@ -329,8 +280,6 @@ public class GameController {
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---- HIER ist die Matt/Patt/Remis-Prüfung ----
|
// ---- HIER ist die Matt/Patt/Remis-Prüfung ----
|
||||||
if (engine.isMated()) {
|
if (engine.isMated()) {
|
||||||
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||||
|
|
@ -356,25 +305,12 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchTimers() {
|
private void switchTimers() {
|
||||||
GameMode mode = engine.getGameMode();
|
|
||||||
Timer whiteTimer = engine.getWhiteTimer();
|
|
||||||
Timer blackTimer = engine.getBlackTimer();
|
|
||||||
|
|
||||||
// Wenn KEIN Modus (also kein Timer): NICHTS machen!
|
|
||||||
if (mode == null || whiteTimer == null || blackTimer == null) return;
|
|
||||||
|
|
||||||
if (engine.getCurrentPlayer().equals("WHITE")) {
|
if (engine.getCurrentPlayer().equals("WHITE")) {
|
||||||
if (mode.incrementSeconds > 0) {
|
engine.getBlackTimer().stop();
|
||||||
blackTimer.addSeconds(mode.incrementSeconds);
|
engine.getWhiteTimer().start();
|
||||||
}
|
|
||||||
blackTimer.stop();
|
|
||||||
whiteTimer.start();
|
|
||||||
} else {
|
} else {
|
||||||
if (mode.incrementSeconds > 0) {
|
engine.getWhiteTimer().stop();
|
||||||
whiteTimer.addSeconds(mode.incrementSeconds);
|
engine.getBlackTimer().start();
|
||||||
}
|
|
||||||
whiteTimer.stop();
|
|
||||||
blackTimer.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -399,32 +335,20 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void askForRestart() {
|
private void askForRestart() {
|
||||||
int answer = JOptionPane.showConfirmDialog(
|
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||||
null,
|
null,
|
||||||
"Neue Partie starten?",
|
"Neue Partie starten?",
|
||||||
"Spiel beendet",
|
"Spiel beendet",
|
||||||
JOptionPane.YES_NO_OPTION
|
javax.swing.JOptionPane.YES_NO_OPTION
|
||||||
);
|
);
|
||||||
javax.swing.SwingUtilities.getWindowAncestor(gui.getField(0, 0)).dispose();
|
javax.swing.SwingUtilities.getWindowAncestor(gui.getField(0, 0)).dispose();
|
||||||
if (answer == JOptionPane.YES_OPTION) {
|
if (answer == javax.swing.JOptionPane.YES_OPTION) {
|
||||||
engine.clearQuicksave();
|
|
||||||
MainController.engineRAM = null;
|
|
||||||
callback.onNewGameRequested();
|
callback.onNewGameRequested();
|
||||||
} else {
|
} else {
|
||||||
// HIER: QuickSave **NUR** falls das Spiel NICHT durch Aufgabe/Remis/Patt beendet wurde!
|
|
||||||
if (!gameWasResignedOrDrawn) {
|
|
||||||
engine.quicksave();
|
|
||||||
MainController.engineRAM = engine;
|
|
||||||
} else {
|
|
||||||
engine.clearQuicksave();
|
|
||||||
MainController.engineRAM = null;
|
|
||||||
}
|
|
||||||
callback.onReturnToMenu();
|
callback.onReturnToMenu();
|
||||||
}
|
}
|
||||||
gameWasResignedOrDrawn = false; // Reset für nächstes Spiel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void resetFieldBackground(int row, int col) {
|
private void resetFieldBackground(int row, int col) {
|
||||||
Color LIGHT = new Color(0xe0e1dd);
|
Color LIGHT = new Color(0xe0e1dd);
|
||||||
Color DARK = new Color(0x778da9);
|
Color DARK = new Color(0x778da9);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import de.hs_mannheim.informatik.chess.view.PgnGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.PgnSelectionGui;
|
import de.hs_mannheim.informatik.chess.view.PgnSelectionGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.CreativeGui;
|
import de.hs_mannheim.informatik.chess.view.CreativeGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameModeSelector;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -16,11 +15,9 @@ import javax.swing.JOptionPane;
|
||||||
import com.github.bhlangonijr.chesslib.game.Game;
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
|
||||||
|
|
||||||
public class MainController {
|
public class MainController {
|
||||||
private MainGui mainGui;
|
private MainGui mainGui;
|
||||||
static ChessEngine engineRAM = null;
|
|
||||||
|
|
||||||
public MainController() {
|
public MainController() {
|
||||||
mainGui = new MainGui();
|
mainGui = new MainGui();
|
||||||
|
|
@ -31,54 +28,18 @@ public class MainController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNormalMode() {
|
private void startNormalMode() {
|
||||||
// Prüfe, ob es im RAM ein Quicksave gibt:
|
|
||||||
if (engineRAM != null && engineRAM.quickload()) {
|
|
||||||
int choice = JOptionPane.showConfirmDialog(
|
|
||||||
null,
|
|
||||||
"Letzte Partie fortsetzen?",
|
|
||||||
"Quicksave gefunden",
|
|
||||||
JOptionPane.YES_NO_OPTION
|
|
||||||
);
|
|
||||||
if (choice == JOptionPane.YES_OPTION) {
|
|
||||||
GameGui gameGui = new GameGui();
|
|
||||||
GameEndCallback callback = new GameEndCallback() {
|
|
||||||
public void onNewGameRequested() { startNormalMode(); }
|
|
||||||
public void onReturnToMenu() { new MainController(); }
|
|
||||||
};
|
|
||||||
new GameController(gameGui, engineRAM, callback); // KEIN initTimers, KEIN neuer Engine!
|
|
||||||
// --- Timerlabels aktualisieren
|
|
||||||
gameGui.updateWhiteTimerLabel(engineRAM.getWhiteTimer().getSecondsLeft());
|
|
||||||
gameGui.updateBlackTimerLabel(engineRAM.getBlackTimer().getSecondsLeft());
|
|
||||||
// --- Timer des aktuellen Spielers starten
|
|
||||||
if (engineRAM.getCurrentPlayer().equals("WHITE")) {
|
|
||||||
engineRAM.getWhiteTimer().start();
|
|
||||||
} else {
|
|
||||||
engineRAM.getBlackTimer().start();
|
|
||||||
}
|
|
||||||
mainGui.close();
|
|
||||||
return; // Fertig!
|
|
||||||
} else {
|
|
||||||
engineRAM.clearQuicksave();
|
|
||||||
engineRAM = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Neues Spiel normal starten:
|
|
||||||
GameMode mode = GameModeSelector.selectGameMode();
|
|
||||||
if (mode == null) return;
|
|
||||||
mainGui.close();
|
mainGui.close();
|
||||||
ChessEngine engine = new ChessEngine(mode);
|
|
||||||
engineRAM = engine; // Für spätere Quicksaves merken!
|
|
||||||
GameGui gameGui = new GameGui();
|
GameGui gameGui = new GameGui();
|
||||||
|
ChessEngine engine = new ChessEngine();
|
||||||
GameEndCallback callback = new GameEndCallback() {
|
GameEndCallback callback = new GameEndCallback() {
|
||||||
public void onNewGameRequested() {
|
public void onNewGameRequested() {
|
||||||
startNormalMode();
|
startNormalMode();
|
||||||
}
|
}
|
||||||
public void onReturnToMenu() {
|
public void onReturnToMenu() {
|
||||||
new MainController();
|
new MainController();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
new GameController(gameGui, engine, callback, mode);
|
new GameController(gameGui, engine, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCreativeMode() {
|
private void startCreativeMode() {
|
||||||
|
|
@ -86,25 +47,6 @@ public class MainController {
|
||||||
CreativeGui creativegui = new CreativeGui();
|
CreativeGui creativegui = new CreativeGui();
|
||||||
ChessEngine engine = new ChessEngine();
|
ChessEngine engine = new ChessEngine();
|
||||||
new CreativeController(creativegui, engine);
|
new CreativeController(creativegui, engine);
|
||||||
|
|
||||||
creativegui.setStartGameCallback(fen -> {
|
|
||||||
// 1. Modus-Auswahl-Dialog zeigen!
|
|
||||||
GameMode mode = GameModeSelector.selectGameMode(); // (Dialog, wie beim Normal Mode)
|
|
||||||
|
|
||||||
if (mode == null) return; // User hat abgebrochen → nichts machen
|
|
||||||
|
|
||||||
|
|
||||||
ChessEngine newEngine = new ChessEngine(mode); // Engine mit Modus (Timer)
|
|
||||||
newEngine.setPositionFromFEN(fen);
|
|
||||||
|
|
||||||
GameGui gameGui = new GameGui();
|
|
||||||
GameEndCallback callback = new GameEndCallback() {
|
|
||||||
public void onNewGameRequested() { startCreativeMode(); }
|
|
||||||
public void onReturnToMenu() { new MainController(); }
|
|
||||||
};
|
|
||||||
new GameController(gameGui, newEngine, callback, mode); // mit Timer/ohne je nach Modus
|
|
||||||
creativegui.close();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startLoadGameMode() {
|
private void startLoadGameMode() {
|
||||||
|
|
@ -126,6 +68,5 @@ public class MainController {
|
||||||
JOptionPane.showMessageDialog(null, "Fehler beim Laden der PGN-Datei:\n" + ex.getMessage());
|
JOptionPane.showMessageDialog(null, "Fehler beim Laden der PGN-Datei:\n" + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mainGui.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,6 @@ public class PgnController {
|
||||||
BoardDTO board = engine.getBoardAsDTO();
|
BoardDTO board = engine.getBoardAsDTO();
|
||||||
gui.updateBoard(board);
|
gui.updateBoard(board);
|
||||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||||
gui.setOpeningLabel(engine.getOpeningName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetFieldBackground(int row, int col) {
|
private void resetFieldBackground(int row, int col) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package de.hs_mannheim.informatik.chess.model;
|
package de.hs_mannheim.informatik.chess.model;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.ConsoleHandler;
|
import java.util.logging.ConsoleHandler;
|
||||||
|
|
@ -20,505 +18,399 @@ import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
||||||
import com.github.bhlangonijr.chesslib.game.*;
|
import com.github.bhlangonijr.chesslib.game.*;
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
import com.github.bhlangonijr.chesslib.move.MoveList;
|
||||||
|
import java.time.LocalDate;
|
||||||
import com.github.bhlangonijr.chesslib.Side;
|
import com.github.bhlangonijr.chesslib.Side;
|
||||||
|
|
||||||
|
|
||||||
public class ChessEngine {
|
public class ChessEngine {
|
||||||
private Board board;
|
private Board board;
|
||||||
private List<Move> moves = new ArrayList<>();
|
private List<Move> moves = new ArrayList<>();
|
||||||
private String initialFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
|
||||||
private static final Logger logger = Logger.getLogger(ChessEngine.class.getName());
|
private static final Logger logger = Logger.getLogger(ChessEngine.class.getName());
|
||||||
private int quicksaveWhiteTimeLeft = -1;
|
|
||||||
private int quicksaveBlackTimeLeft = -1;
|
|
||||||
private int currentMoveIndex = 0;
|
private int currentMoveIndex = 0;
|
||||||
private Timer whiteTimer;
|
private Timer whiteTimer;
|
||||||
private Timer blackTimer;
|
private Timer blackTimer;
|
||||||
private final GameMode mode;
|
|
||||||
private String quicksaveFen = null;
|
|
||||||
private List<Move> quicksaveMoves = null;
|
|
||||||
private int quicksaveMoveIndex = 0;
|
|
||||||
private Opening detectedOpening = null;
|
private Opening detectedOpening = null;
|
||||||
|
|
||||||
public ChessEngine() {
|
public ChessEngine() {
|
||||||
this.mode = null;
|
logging();
|
||||||
logging();
|
board = new Board();
|
||||||
board = new Board();
|
}
|
||||||
}
|
public boolean move(MoveDTO move) {
|
||||||
|
String from = "" + (char)('A' + move.getFromCol()) + (8 - move.getFromRow());
|
||||||
|
String to = "" + (char)('A' + move.getToCol()) + (8 - move.getToRow());
|
||||||
|
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to));
|
||||||
|
if (board.legalMoves().contains(libMove)) {
|
||||||
|
board.doMove(libMove);
|
||||||
|
|
||||||
public ChessEngine(GameMode mode) {
|
// Replay? Dann abschneiden
|
||||||
this.mode = mode;
|
if (currentMoveIndex < moves.size()) {
|
||||||
whiteTimer = new Timer(mode.minutes, mode.seconds);
|
logger.info("Replay-Modus: Züge nach " + currentMoveIndex + " werden entfernt.");
|
||||||
blackTimer = new Timer(mode.minutes, mode.seconds);
|
moves = new ArrayList<>(moves.subList(0, currentMoveIndex));
|
||||||
logging();
|
}
|
||||||
board = new Board();
|
moves.add(libMove);
|
||||||
}
|
currentMoveIndex++;
|
||||||
|
logger.info("Zug erfolgreich durchgeführt: " + libMove);
|
||||||
|
|
||||||
public boolean move(MoveDTO move) {
|
// Opening-Erkennung nach jedem erfolgreichen Zug
|
||||||
String from = "" + (char) ('A' + move.getFromCol()) + (8 - move.getFromRow());
|
String playedMovesUci = movesToUciString(moves);
|
||||||
String to = "" + (char) ('A' + move.getToCol()) + (8 - move.getToRow());
|
detectedOpening = Opening.detect(playedMovesUci);
|
||||||
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to));
|
|
||||||
if (board.legalMoves().contains(libMove)) {
|
|
||||||
board.doMove(libMove);
|
|
||||||
|
|
||||||
if (currentMoveIndex < moves.size()) {
|
if (detectedOpening != null) {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
logger.info("Aktuelles Opening erkannt: " + detectedOpening.getEco() + " - " + detectedOpening.getName());
|
||||||
logger.info("Replay-Modus: Züge nach " + currentMoveIndex + " werden entfernt.");
|
// Optional: Speichere das Opening in ein Feld, falls benötigt
|
||||||
}
|
}
|
||||||
moves = new ArrayList<>(moves.subList(0, currentMoveIndex));
|
return true;
|
||||||
}
|
}
|
||||||
moves.add(libMove);
|
logger.warning("Ungültiger Zug: " + libMove);
|
||||||
currentMoveIndex++;
|
return false;
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
}
|
||||||
logger.info("Zug erfolgreich durchgeführt: " + libMove);
|
|
||||||
}
|
|
||||||
|
|
||||||
String playedMovesUci = movesToUciString(moves);
|
public String getOpeningName() {
|
||||||
detectedOpening = Opening.detect(playedMovesUci);
|
if (detectedOpening != null) {
|
||||||
|
return detectedOpening.getEco() + " - " + detectedOpening.getName();
|
||||||
|
} else {
|
||||||
|
return "unbekannt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (detectedOpening != null && logger.isLoggable(Level.INFO)) {
|
private String movesToUciString(List<Move> moves) {
|
||||||
logger.info("Aktuelles Opening erkannt: " + detectedOpening.getEco() + " - " + detectedOpening.getName());
|
StringBuilder sb = new StringBuilder();
|
||||||
}
|
for (Move m : moves) {
|
||||||
return true;
|
sb.append(m.toString()).append(" ");
|
||||||
}
|
}
|
||||||
if (logger.isLoggable(Level.WARNING)) {
|
return sb.toString().trim();
|
||||||
logger.warning("Ungültiger Zug: " + libMove);
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOpeningName() {
|
public List<MoveDTO> getLegalDestinations(String from) {
|
||||||
if (detectedOpening != null) {
|
logger.info("Hole legale Züge von: " + from);
|
||||||
return detectedOpening.getEco() + " - " + detectedOpening.getName();
|
List<MoveDTO> destinations = new ArrayList<>();
|
||||||
} else {
|
try {
|
||||||
return "unbekannt";
|
Square fromSq = Square.valueOf(from.toUpperCase());
|
||||||
}
|
for (Move move : board.legalMoves()) {
|
||||||
}
|
if (move.getFrom().equals(fromSq)) {
|
||||||
|
int fromRow = 8 - fromSq.getRank().ordinal() - 1;
|
||||||
|
int fromCol = fromSq.getFile().ordinal();
|
||||||
|
int toRow = 8 - move.getTo().getRank().ordinal() - 1;
|
||||||
|
int toCol = move.getTo().getFile().ordinal();
|
||||||
|
destinations.add(new MoveDTO(fromRow, fromCol, toRow, toCol));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info("Es wurden " + destinations.size() + " Ziele gefunden.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.severe("Fehler beim Holen der legalen Ziele: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return destinations;
|
||||||
|
}
|
||||||
|
|
||||||
private String movesToUciString(List<Move> moves) {
|
public List<String> getMoveListStringsGrouped() {
|
||||||
StringBuilder sb = new StringBuilder();
|
logger.info("Gruppiere Züge für Anzeige.");
|
||||||
for (Move m : moves) {
|
List<String> result = new ArrayList<>();
|
||||||
sb.append(m.toString()).append(" ");
|
StringBuilder sb = new StringBuilder();
|
||||||
}
|
for (int i = 0; i < moves.size(); i++) {
|
||||||
return sb.toString().trim();
|
if (i % 2 == 0) sb.append((i/2 + 1) + ". ");
|
||||||
}
|
sb.append(moves.get(i).toString()).append(" ");
|
||||||
|
if (i % 2 == 1 || i == moves.size() - 1) {
|
||||||
|
result.add(sb.toString().trim());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public List<MoveDTO> getLegalDestinations(String from) {
|
public PieceDTO getPieceAt(String square) {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
logger.info("Hole Figur an Feld: " + square);
|
||||||
logger.info("Hole legale Züge von: " + from);
|
Piece piece = board.getPiece(Square.valueOf(square.toUpperCase()));
|
||||||
}
|
return convertPieceToDTO(piece);
|
||||||
List<MoveDTO> destinations = new ArrayList<>();
|
}
|
||||||
try {
|
|
||||||
Square fromSq = Square.valueOf(from.toUpperCase(java.util.Locale.ROOT));
|
|
||||||
for (Move move : board.legalMoves()) {
|
|
||||||
if (move.getFrom().equals(fromSq)) {
|
|
||||||
int fromRow = 8 - fromSq.getRank().ordinal() - 1;
|
|
||||||
int fromCol = fromSq.getFile().ordinal();
|
|
||||||
int toRow = 8 - move.getTo().getRank().ordinal() - 1;
|
|
||||||
int toCol = move.getTo().getFile().ordinal();
|
|
||||||
destinations.add(new MoveDTO(fromRow, fromCol, toRow, toCol));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
|
||||||
logger.info("Es wurden " + destinations.size() + " Ziele gefunden.");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (logger.isLoggable(Level.SEVERE)) {
|
|
||||||
logger.severe("Fehler beim Holen der legalen Ziele: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return destinations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getMoveListStringsGrouped() {
|
public boolean moveWithPromotion(MoveDTO move, String promotionPiece) {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
String from = "" + (char)('A' + move.getFromCol()) + (8 - move.getFromRow());
|
||||||
logger.info("Gruppiere Züge für Anzeige.");
|
String to = "" + (char)('A' + move.getToCol()) + (8 - move.getToRow());
|
||||||
}
|
|
||||||
List<String> result = new ArrayList<>();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < moves.size(); i++) {
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
sb.append((i / 2 + 1)).append(". ");
|
|
||||||
}
|
|
||||||
sb.append(moves.get(i).toString()).append(" ");
|
|
||||||
if (i % 2 == 1 || i == moves.size() - 1) {
|
|
||||||
result.add(sb.toString().trim());
|
|
||||||
sb = new StringBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void quicksave() {
|
// Die Farbe bestimmen!
|
||||||
this.quicksaveFen = board.getFen();
|
boolean isWhite = (8 - move.getFromRow()) < (8 - move.getToRow());
|
||||||
this.quicksaveMoves = new ArrayList<>(moves);
|
Piece promotion;
|
||||||
this.quicksaveMoveIndex = currentMoveIndex;
|
switch (promotionPiece) {
|
||||||
if (whiteTimer != null) {
|
case "ROOK": promotion = isWhite ? Piece.WHITE_ROOK : Piece.BLACK_ROOK; break;
|
||||||
quicksaveWhiteTimeLeft = whiteTimer.getSecondsLeft();
|
case "KNIGHT": promotion = isWhite ? Piece.WHITE_KNIGHT : Piece.BLACK_KNIGHT; break;
|
||||||
}
|
case "BISHOP": promotion = isWhite ? Piece.WHITE_BISHOP : Piece.BLACK_BISHOP; break;
|
||||||
if (blackTimer != null) {
|
default: promotion = isWhite ? Piece.WHITE_QUEEN : Piece.BLACK_QUEEN;
|
||||||
quicksaveBlackTimeLeft = blackTimer.getSecondsLeft();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean quickload() {
|
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to), promotion);
|
||||||
if (quicksaveFen == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
board = new Board();
|
|
||||||
board.loadFromFen(quicksaveFen);
|
|
||||||
moves = new ArrayList<>(quicksaveMoves);
|
|
||||||
currentMoveIndex = quicksaveMoveIndex;
|
|
||||||
if (whiteTimer != null && quicksaveWhiteTimeLeft != -1) {
|
|
||||||
whiteTimer.setSecondsLeft(quicksaveWhiteTimeLeft);
|
|
||||||
}
|
|
||||||
if (blackTimer != null && quicksaveBlackTimeLeft != -1) {
|
|
||||||
blackTimer.setSecondsLeft(quicksaveBlackTimeLeft);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearQuicksave() {
|
if (board.legalMoves().contains(libMove)) {
|
||||||
quicksaveFen = null;
|
board.doMove(libMove);
|
||||||
quicksaveMoves = null;
|
|
||||||
quicksaveMoveIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PieceDTO getPieceAt(String square) {
|
if (currentMoveIndex < moves.size()) {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
moves = new ArrayList<>(moves.subList(0, currentMoveIndex));
|
||||||
logger.info("Hole Figur an Feld: " + square);
|
}
|
||||||
}
|
moves.add(libMove);
|
||||||
Piece piece = board.getPiece(Square.valueOf(square.toUpperCase(java.util.Locale.ROOT)));
|
currentMoveIndex++;
|
||||||
return convertPieceToDTO(piece);
|
logger.info("Promotionszug durchgeführt: " + libMove);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
logger.warning("Ungültiger Promotionszug: " + libMove);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean moveWithPromotion(MoveDTO move, String promotionPiece) {
|
public BoardDTO getBoardAsDTO() {
|
||||||
String from = "" + (char) ('A' + move.getFromCol()) + (8 - move.getFromRow());
|
logger.info("Erstelle DTO-Abbild des Boards");
|
||||||
String to = "" + (char) ('A' + move.getToCol()) + (8 - move.getToRow());
|
PieceDTO[][] dtoBoard = new PieceDTO[8][8];
|
||||||
|
for (int rank = 8; rank >= 1; rank--) {
|
||||||
|
for (int file = 0; file < 8; file++) {
|
||||||
|
Square square = Square.valueOf("" + (char)('A' + file) + rank);
|
||||||
|
Piece piece = board.getPiece(square);
|
||||||
|
dtoBoard[8-rank][file] = convertPieceToDTO(piece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BoardDTO(dtoBoard);
|
||||||
|
}
|
||||||
|
|
||||||
boolean isWhite = (8 - move.getFromRow()) < (8 - move.getToRow());
|
private String pieceToUnicode(Piece piece) {
|
||||||
Piece promotion;
|
switch (piece) {
|
||||||
switch (promotionPiece) {
|
case WHITE_KING: return "♔";
|
||||||
case "ROOK":
|
case WHITE_QUEEN: return "♕";
|
||||||
promotion = isWhite ? Piece.WHITE_ROOK : Piece.BLACK_ROOK;
|
case WHITE_ROOK: return "♖";
|
||||||
break;
|
case WHITE_BISHOP: return "♗";
|
||||||
case "KNIGHT":
|
case WHITE_KNIGHT: return "♘";
|
||||||
promotion = isWhite ? Piece.WHITE_KNIGHT : Piece.BLACK_KNIGHT;
|
case WHITE_PAWN: return "♙";
|
||||||
break;
|
case BLACK_KING: return "♚";
|
||||||
case "BISHOP":
|
case BLACK_QUEEN: return "♛";
|
||||||
promotion = isWhite ? Piece.WHITE_BISHOP : Piece.BLACK_BISHOP;
|
case BLACK_ROOK: return "♜";
|
||||||
break;
|
case BLACK_BISHOP: return "♝";
|
||||||
default:
|
case BLACK_KNIGHT: return "♞";
|
||||||
promotion = isWhite ? Piece.WHITE_QUEEN : Piece.BLACK_QUEEN;
|
case BLACK_PAWN: return "♟";
|
||||||
break;
|
default: return " ";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to), promotion);
|
public void setPositionToMoveIndex(int idx) {
|
||||||
|
// Neues Board erzeugen
|
||||||
|
logger.info("Setze Board auf Zug-Index: " + idx);
|
||||||
|
board = new Board();
|
||||||
|
for (int i = 0; i < idx; i++) {
|
||||||
|
board.doMove(moves.get(i));
|
||||||
|
}
|
||||||
|
currentMoveIndex = idx;
|
||||||
|
|
||||||
if (board.legalMoves().contains(libMove)) {
|
String playedMovesUci = movesToUciString(moves.subList(0, idx));
|
||||||
board.doMove(libMove);
|
detectedOpening = Opening.detect(playedMovesUci);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentMoveIndex < moves.size()) {
|
public int getCurrentMoveIndex() {
|
||||||
moves = new ArrayList<>(moves.subList(0, currentMoveIndex));
|
logger.info("Hole aktuellen Zug-Index: " + currentMoveIndex);
|
||||||
}
|
return currentMoveIndex;
|
||||||
moves.add(libMove);
|
}
|
||||||
currentMoveIndex++;
|
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
|
||||||
logger.info("Promotionszug durchgeführt: " + libMove);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (logger.isLoggable(Level.WARNING)) {
|
|
||||||
logger.warning("Ungültiger Promotionszug: " + libMove);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoardDTO getBoardAsDTO() {
|
public int getMoveListSize() {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
logger.info("Hole Anzahl gespielter Züge: " + moves.size());
|
||||||
logger.info("Erstelle DTO-Abbild des Boards");
|
return moves.size();
|
||||||
}
|
}
|
||||||
PieceDTO[][] dtoBoard = new PieceDTO[8][8];
|
|
||||||
for (int rank = 8; rank >= 1; rank--) {
|
|
||||||
for (int file = 0; file < 8; file++) {
|
|
||||||
Square square = Square.valueOf("" + (char) ('A' + file) + rank);
|
|
||||||
Piece piece = board.getPiece(square);
|
|
||||||
dtoBoard[8 - rank][file] = convertPieceToDTO(piece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new BoardDTO(dtoBoard);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String pieceToUnicode(Piece piece) {
|
private PieceDTO convertPieceToDTO(Piece piece) {
|
||||||
switch (piece) {
|
if (piece == null || piece.equals(Piece.NONE)) return null;
|
||||||
case WHITE_KING:
|
String color = piece.name().startsWith("WHITE") ? "WHITE" : "BLACK";
|
||||||
return "♔";
|
String type = piece.name().substring(piece.name().indexOf('_') + 1); // "PAWN", "KING"...
|
||||||
case WHITE_QUEEN:
|
String symbol = pieceToUnicode(piece);
|
||||||
return "♕";
|
return new PieceDTO(type, color, symbol);
|
||||||
case WHITE_ROOK:
|
}
|
||||||
return "♖";
|
|
||||||
case WHITE_BISHOP:
|
|
||||||
return "♗";
|
|
||||||
case WHITE_KNIGHT:
|
|
||||||
return "♘";
|
|
||||||
case WHITE_PAWN:
|
|
||||||
return "♙";
|
|
||||||
case BLACK_KING:
|
|
||||||
return "♚";
|
|
||||||
case BLACK_QUEEN:
|
|
||||||
return "♛";
|
|
||||||
case BLACK_ROOK:
|
|
||||||
return "♜";
|
|
||||||
case BLACK_BISHOP:
|
|
||||||
return "♝";
|
|
||||||
case BLACK_KNIGHT:
|
|
||||||
return "♞";
|
|
||||||
case BLACK_PAWN:
|
|
||||||
return "♟";
|
|
||||||
default:
|
|
||||||
return " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPositionToMoveIndex(int idx) {
|
public void setPositionFromFEN(String fen) {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
board.loadFromFen(fen);
|
||||||
logger.info("Setze Board auf Zug-Index: " + idx);
|
}
|
||||||
}
|
|
||||||
board = new Board();
|
|
||||||
board.loadFromFen(initialFen);
|
|
||||||
for (int i = 0; i < idx; i++) {
|
|
||||||
board.doMove(moves.get(i));
|
|
||||||
}
|
|
||||||
currentMoveIndex = idx;
|
|
||||||
|
|
||||||
String playedMovesUci = movesToUciString(moves.subList(0, idx));
|
|
||||||
detectedOpening = Opening.detect(playedMovesUci);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentMoveIndex() {
|
public boolean isMated() {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
boolean mated = board.isMated();
|
||||||
logger.info("Hole aktuellen Zug-Index: " + currentMoveIndex);
|
logger.info("isMated() = " + mated);
|
||||||
}
|
return mated;
|
||||||
return currentMoveIndex;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int getMoveListSize() {
|
public boolean isStalemate() {
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
boolean stale = board.isStaleMate();
|
||||||
logger.info("Hole Anzahl gespielter Züge: " + moves.size());
|
logger.info("isStalemate() = " + stale);
|
||||||
}
|
return stale;
|
||||||
return moves.size();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private PieceDTO convertPieceToDTO(Piece piece) {
|
public boolean isDraw() {
|
||||||
if (piece == null || piece.equals(Piece.NONE)) {
|
boolean draw = board.isDraw();
|
||||||
return null;
|
logger.info("isDraw() = " + draw);
|
||||||
}
|
return draw;
|
||||||
String color = piece.name().startsWith("WHITE") ? "WHITE" : "BLACK";
|
}
|
||||||
String type = piece.name().substring(piece.name().indexOf('_') + 1);
|
|
||||||
String symbol = pieceToUnicode(piece);
|
|
||||||
return new PieceDTO(type, color, symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPositionFromFEN(String fen) {
|
public String getCurrentPlayer() {
|
||||||
board.loadFromFen(fen);
|
String player = board.getSideToMove().toString();
|
||||||
initialFen = fen;
|
logger.info("Am Zug: " + player);
|
||||||
}
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isMated() {
|
public void logging() {
|
||||||
boolean mated = board.isMated();
|
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
|
||||||
logger.info("isMated() = " + mated);
|
|
||||||
}
|
|
||||||
return mated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStalemate() {
|
// Eigener Handler nur für diese Klasse
|
||||||
boolean stale = board.isStaleMate();
|
ConsoleHandler handler = new ConsoleHandler();
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
handler.setLevel(Level.ALL);
|
||||||
logger.info("isStalemate() = " + stale);
|
handler.setFormatter(new SimpleFormatter() {
|
||||||
}
|
@Override
|
||||||
return stale;
|
public synchronized String format(LogRecord lr) {
|
||||||
}
|
return String.format("[%s] %s%n%n", lr.getLevel().getLocalizedName(), lr.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
logger.setUseParentHandlers(false);
|
||||||
|
logger.addHandler(handler);
|
||||||
|
|
||||||
public boolean isDraw() {
|
logger.info("ChessEngine wurde initialisiert.");
|
||||||
boolean draw = board.isDraw();
|
}
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
|
||||||
logger.info("isDraw() = " + draw);
|
|
||||||
}
|
|
||||||
return draw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrentPlayer() {
|
public List<Game> loadGamesFromPgn(String path) throws IOException {
|
||||||
String player = board.getSideToMove().toString();
|
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
|
||||||
logger.info("Am Zug: " + player);
|
|
||||||
}
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void logging() {
|
PgnHolder pgnHolder = new PgnHolder(path);
|
||||||
ConsoleHandler handler = new ConsoleHandler();
|
try {
|
||||||
handler.setLevel(Level.ALL);
|
|
||||||
handler.setFormatter(new SimpleFormatter() {
|
|
||||||
@Override
|
|
||||||
public synchronized String format(LogRecord lr) {
|
|
||||||
return String.format("[%s] %s%n%n", lr.getLevel().getLocalizedName(), lr.getMessage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
logger.setUseParentHandlers(false);
|
|
||||||
logger.addHandler(handler);
|
|
||||||
|
|
||||||
if (logger.isLoggable(Level.INFO)) {
|
|
||||||
logger.info("ChessEngine wurde initialisiert.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Game> loadGamesFromPgn(String path) throws IOException {
|
|
||||||
PgnHolder pgnHolder = new PgnHolder(path);
|
|
||||||
try {
|
|
||||||
pgnHolder.loadPgn();
|
pgnHolder.loadPgn();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return pgnHolder.getGames();
|
List<Game> games = pgnHolder.getGames();
|
||||||
}
|
return games;
|
||||||
|
}
|
||||||
|
|
||||||
public void initTimers(int min, int sec) {
|
public void initTimers(int min, int sec) {
|
||||||
if (whiteTimer == null) {
|
whiteTimer = new Timer(min, sec);
|
||||||
whiteTimer = new Timer(min, sec);
|
blackTimer = new Timer(min, sec);
|
||||||
} else if (quicksaveWhiteTimeLeft != -1) {
|
}
|
||||||
whiteTimer = new Timer(min, sec);
|
|
||||||
whiteTimer.setSecondsLeft(quicksaveWhiteTimeLeft);
|
|
||||||
} else {
|
|
||||||
whiteTimer = new Timer(min, sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blackTimer == null) {
|
public void saveAsPgn(Game game, String path, String dateiname) {
|
||||||
blackTimer = new Timer(min, sec);
|
// Sicher alle Strings holen (nie null)
|
||||||
} else if (quicksaveBlackTimeLeft != -1) {
|
String event = safe(game.getRound().getEvent().getName());
|
||||||
blackTimer = new Timer(min, sec);
|
String site = safe(game.getRound().getEvent().getSite());
|
||||||
blackTimer.setSecondsLeft(quicksaveBlackTimeLeft);
|
String round = "" + game.getRound().getNumber();
|
||||||
} else {
|
// Datum für PGN-Format (YYYY.MM.DD)
|
||||||
blackTimer = new Timer(min, sec);
|
String date = safe(game.getRound().getEvent().getStartDate()).replace("-", ".");
|
||||||
}
|
String wName = safe(game.getWhitePlayer().getName());
|
||||||
}
|
String bName = safe(game.getBlackPlayer().getName());
|
||||||
|
String result = safe(game.getResult().getDescription());
|
||||||
|
|
||||||
public void saveAsPgn(Game game, String path, String dateiname) {
|
// PGN-Header zusammenbauen
|
||||||
String event = safe(game.getRound().getEvent().getName());
|
StringBuilder header = new StringBuilder();
|
||||||
String site = safe(game.getRound().getEvent().getSite());
|
header.append("[Event \"" + event + "\"]\n");
|
||||||
String round = "" + game.getRound().getNumber();
|
header.append("[Site \"" + site + "\"]\n");
|
||||||
String date = safe(game.getRound().getEvent().getStartDate()).replace("-", ".");
|
header.append("[Date \"" + date + "\"]\n");
|
||||||
String wName = safe(game.getWhitePlayer().getName());
|
header.append("[Round \"" + round + "\"]\n");
|
||||||
String bName = safe(game.getBlackPlayer().getName());
|
header.append("[White \"" + wName + "\"]\n");
|
||||||
String result = safe(game.getResult().getDescription());
|
header.append("[Black \"" + bName + "\"]\n");
|
||||||
|
header.append("[Result \"" + result + "\"]\n\n");
|
||||||
|
|
||||||
StringBuilder header = new StringBuilder();
|
// Züge als SAN holen
|
||||||
header.append("[Event \"" + event + "\"]\n");
|
StringBuilder moves = new StringBuilder();
|
||||||
header.append("[Site \"" + site + "\"]\n");
|
String[] sanArray = game.getHalfMoves().toSanArray();
|
||||||
header.append("[Date \"" + date + "\"]\n");
|
|
||||||
header.append("[Round \"" + round + "\"]\n");
|
|
||||||
header.append("[White \"" + wName + "\"]\n");
|
|
||||||
header.append("[Black \"" + bName + "\"]\n");
|
|
||||||
header.append("[Result \"" + result + "\"]\n\n");
|
|
||||||
|
|
||||||
StringBuilder movesSb = new StringBuilder();
|
for (int i = 0; i < sanArray.length; i++) {
|
||||||
String[] sanArray = game.getHalfMoves().toSanArray();
|
if (i % 2 == 0) {
|
||||||
|
moves.append((i / 2 + 1)).append(". ");
|
||||||
|
}
|
||||||
|
moves.append(sanArray[i]).append(" ");
|
||||||
|
// Optional: Zeilenumbruch für Lesbarkeit
|
||||||
|
// if (i > 0 && i % 8 == 0) moves.append("\n");
|
||||||
|
}
|
||||||
|
moves.append(result); // Ergebnis am Ende!
|
||||||
|
|
||||||
for (int i = 0; i < sanArray.length; i++) {
|
String file = header + moves.toString();
|
||||||
if (i % 2 == 0) {
|
|
||||||
movesSb.append((i / 2 + 1)).append(". ");
|
|
||||||
}
|
|
||||||
movesSb.append(sanArray[i]).append(" ");
|
|
||||||
}
|
|
||||||
movesSb.append(result);
|
|
||||||
|
|
||||||
String file = header + movesSb.toString();
|
// Datei schreiben
|
||||||
|
try {
|
||||||
|
Files.writeString(Path.of(path, dateiname), file, StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
// Hilfsfunktion für Null-Sicherheit
|
||||||
Files.writeString(Path.of(path, dateiname), file, StandardCharsets.UTF_8);
|
private String safe(String s) {
|
||||||
} catch (IOException e) {
|
return s == null ? "?" : s;
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String safe(String s) {
|
public Game getCurrentGame() {
|
||||||
return s == null ? "?" : s;
|
return getCurrentGame(this.board, this.moves, this.currentMoveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game getCurrentGame() {
|
public Game getCurrentGame(Board board, java.util.List<Move> moves, int currentMoveIndex) {
|
||||||
return getCurrentGame(this.board, this.moves, this.currentMoveIndex);
|
// Event und Turnierdaten setzen
|
||||||
}
|
Event event = new Event();
|
||||||
|
event.setName("Generated Game");
|
||||||
|
event.setSite("Local");
|
||||||
|
event.setStartDate(LocalDate.now().toString()); // Format: yyyy-MM-dd
|
||||||
|
|
||||||
public Game getCurrentGame(Board board, List<Move> moves, int currentMoveIndex) {
|
// Runde anlegen
|
||||||
Event event = new Event();
|
Round round = new Round(event);
|
||||||
event.setName("Generated Game");
|
round.setNumber(1);
|
||||||
event.setSite("Local");
|
|
||||||
event.setStartDate(LocalDate.now().toString());
|
|
||||||
|
|
||||||
Round round = new Round(event);
|
// Spiel initialisieren
|
||||||
round.setNumber(1);
|
Game game = new Game("1", round); // "1" ist die Game-ID
|
||||||
|
|
||||||
Game game = new Game("1", round);
|
// Spieler setzen (deine MyPlayer-Klasse)
|
||||||
|
game.setWhitePlayer(new MyPlayer("White"));
|
||||||
|
game.setBlackPlayer(new MyPlayer("Black"));
|
||||||
|
|
||||||
game.setWhitePlayer(new MyPlayer("White"));
|
// Ergebnis setzen
|
||||||
game.setBlackPlayer(new MyPlayer("Black"));
|
if (board.isMated()) {
|
||||||
|
game.setResult(board.getSideToMove() == Side.WHITE ? GameResult.BLACK_WON : GameResult.WHITE_WON);
|
||||||
|
} else if (board.isStaleMate() || board.isDraw()) {
|
||||||
|
game.setResult(GameResult.DRAW);
|
||||||
|
} else {
|
||||||
|
game.setResult(GameResult.ONGOING);
|
||||||
|
}
|
||||||
|
|
||||||
if (board.isMated()) {
|
// Züge übernehmen
|
||||||
game.setResult(board.getSideToMove() == Side.WHITE ? GameResult.BLACK_WON : GameResult.WHITE_WON);
|
MoveList moveList = new MoveList();
|
||||||
} else if (board.isStaleMate() || board.isDraw()) {
|
for (Move move : moves) {
|
||||||
game.setResult(GameResult.DRAW);
|
moveList.add(move);
|
||||||
} else {
|
}
|
||||||
game.setResult(GameResult.ONGOING);
|
game.setHalfMoves(moveList);
|
||||||
}
|
|
||||||
|
|
||||||
MoveList moveList = new MoveList();
|
// Position auf aktuellen Zug setzen (letzter gespielter Halbzug)
|
||||||
for (Move move : moves) {
|
if (currentMoveIndex > 0 && currentMoveIndex <= moveList.size()) {
|
||||||
moveList.add(move);
|
game.setPosition(currentMoveIndex - 1);
|
||||||
}
|
} else {
|
||||||
game.setHalfMoves(moveList);
|
game.setPosition(moveList.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentMoveIndex > 0 && currentMoveIndex <= moveList.size()) {
|
// FEN setzen: JETZT das aktuelle Board-FEN verwenden!
|
||||||
game.setPosition(currentMoveIndex - 1);
|
game.setBoard(new Board());
|
||||||
} else {
|
game.getBoard().loadFromFen(board.getFen());
|
||||||
game.setPosition(moveList.size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
game.setBoard(new Board());
|
return game;
|
||||||
game.getBoard().loadFromFen(board.getFen());
|
}
|
||||||
|
|
||||||
return game;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
if (currentMoveIndex > 0 && !moves.isEmpty()) {
|
if (currentMoveIndex > 0 && moves.size() > 0) {
|
||||||
board.undoMove();
|
board.undoMove(); // 1. Brett zurücksetzen
|
||||||
moves.remove(currentMoveIndex - 1);
|
moves.remove(currentMoveIndex - 1); // 2. Zug aus Move-Liste löschen
|
||||||
currentMoveIndex--;
|
currentMoveIndex--; // 3. Index anpassen
|
||||||
|
|
||||||
String playedMovesUci = movesToUciString(moves.subList(0, currentMoveIndex));
|
// 4. Erkennung Opening neu machen!
|
||||||
detectedOpening = Opening.detect(playedMovesUci);
|
String playedMovesUci = movesToUciString(moves.subList(0, currentMoveIndex));
|
||||||
}
|
detectedOpening = Opening.detect(playedMovesUci);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void loadMoves(List<Move> moveList) {
|
|
||||||
board = new Board();
|
|
||||||
moves.clear();
|
|
||||||
currentMoveIndex = 0;
|
|
||||||
|
|
||||||
for (Move move : moveList) {
|
public void loadMoves(List<Move> moveList) {
|
||||||
board.doMove(move);
|
board = new Board(); // Neues leeres Brett
|
||||||
moves.add(move);
|
moves.clear();
|
||||||
currentMoveIndex++;
|
currentMoveIndex = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timer getWhiteTimer() {
|
for (Move move : moveList) {
|
||||||
return whiteTimer;
|
board.doMove(move);
|
||||||
}
|
moves.add(move);
|
||||||
|
currentMoveIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
public Timer getBlackTimer() {
|
}
|
||||||
return blackTimer;
|
|
||||||
}
|
public Timer getWhiteTimer() { return whiteTimer; }
|
||||||
|
public Timer getBlackTimer() { return blackTimer; }
|
||||||
|
|
||||||
public GameMode getGameMode() {
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
package de.hs_mannheim.informatik.chess.model;
|
|
||||||
|
|
||||||
public enum GameMode {
|
|
||||||
CLASSIC(3, 0, 0),
|
|
||||||
RAPID(5, 0, 0),
|
|
||||||
BULLET(1, 0, 10); // 1 Minute + 10 Sek Inkrement
|
|
||||||
|
|
||||||
public final int minutes;
|
|
||||||
public final int seconds;
|
|
||||||
public final int incrementSeconds;
|
|
||||||
|
|
||||||
GameMode(int minutes, int seconds, int incrementSeconds) {
|
|
||||||
this.minutes = minutes;
|
|
||||||
this.seconds = seconds;
|
|
||||||
this.incrementSeconds = incrementSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return switch (this) {
|
|
||||||
case CLASSIC -> "3 Minuten (klassisch)";
|
|
||||||
case RAPID -> "5 Minuten (rapid)";
|
|
||||||
case BULLET -> "1 Minute + 10 Sek Inkrement";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -56,13 +56,6 @@ public class Timer {
|
||||||
public int getSecondsLeft() {
|
public int getSecondsLeft() {
|
||||||
return secondsLeft;
|
return secondsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSecondsLeft(int secondsLeft) {
|
|
||||||
this.secondsLeft = secondsLeft;
|
|
||||||
}
|
|
||||||
public void addSeconds(int seconds) {
|
|
||||||
this.secondsLeft += seconds;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,6 @@ import java.awt.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class CreativeGui {
|
public class CreativeGui {
|
||||||
|
|
||||||
public interface StartGameCallback {
|
|
||||||
void onStartGame(String fen);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isFlipped = false;
|
private boolean isFlipped = false;
|
||||||
|
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
|
|
@ -19,12 +14,6 @@ public class CreativeGui {
|
||||||
private JButton updateBtn;
|
private JButton updateBtn;
|
||||||
private JButton flipBoardButton;
|
private JButton flipBoardButton;
|
||||||
|
|
||||||
private boolean closedByUser = true;
|
|
||||||
|
|
||||||
private StartGameCallback startGameCallback;
|
|
||||||
|
|
||||||
private JButton startGameButton;
|
|
||||||
|
|
||||||
public static final HashMap<String, String> UNICODE_MAP = new HashMap<String, String>() {{
|
public static final HashMap<String, String> UNICODE_MAP = new HashMap<String, String>() {{
|
||||||
put("BLACK_KING", "\u265A"); put("BLACK_QUEEN", "\u265B");
|
put("BLACK_KING", "\u265A"); put("BLACK_QUEEN", "\u265B");
|
||||||
put("BLACK_ROOK", "\u265C"); put("BLACK_BISHOP", "\u265D");
|
put("BLACK_ROOK", "\u265C"); put("BLACK_BISHOP", "\u265D");
|
||||||
|
|
@ -52,7 +41,7 @@ public class CreativeGui {
|
||||||
// LINKS: chessPanel (Board+Toolbars)
|
// LINKS: chessPanel (Board+Toolbars)
|
||||||
gbc.gridx = 0;
|
gbc.gridx = 0;
|
||||||
gbc.gridy = 0;
|
gbc.gridy = 0;
|
||||||
gbc.weightx = 0.7;
|
gbc.weightx = 0.6;
|
||||||
gbc.weighty = 1.0;
|
gbc.weighty = 1.0;
|
||||||
gbc.insets = new Insets(5, 5, 5, 0);
|
gbc.insets = new Insets(5, 5, 5, 0);
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
|
|
@ -61,21 +50,12 @@ public class CreativeGui {
|
||||||
// RECHTS: FEN & Optionen
|
// RECHTS: FEN & Optionen
|
||||||
gbc.gridx = 1;
|
gbc.gridx = 1;
|
||||||
gbc.gridy = 0;
|
gbc.gridy = 0;
|
||||||
gbc.weightx = 0.3;
|
gbc.weightx = 0.4;
|
||||||
gbc.weighty = 1.0;
|
gbc.weighty = 1.0;
|
||||||
gbc.insets = new Insets(5, 0, 5, 5);
|
gbc.insets = new Insets(5, 0, 5, 5);
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
mainPanel.add(fenPanel(), gbc);
|
mainPanel.add(fenPanel(), gbc);
|
||||||
|
|
||||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
||||||
@Override
|
|
||||||
public void windowClosed(java.awt.event.WindowEvent e) {
|
|
||||||
if (closedByUser) {
|
|
||||||
new de.hs_mannheim.informatik.chess.controller.MainController();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
frame.setContentPane(mainPanel);
|
frame.setContentPane(mainPanel);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +72,7 @@ public class CreativeGui {
|
||||||
btn.setFocusPainted(false);
|
btn.setFocusPainted(false);
|
||||||
btn.setPreferredSize(new Dimension(70, 70));
|
btn.setPreferredSize(new Dimension(70, 70));
|
||||||
btn.setBackground(white ? LIGHT : DARK);
|
btn.setBackground(white ? LIGHT : DARK);
|
||||||
btn.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
btn.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||||
String key = prefix + type;
|
String key = prefix + type;
|
||||||
btn.addActionListener(e -> selectedPiece = key);
|
btn.addActionListener(e -> selectedPiece = key);
|
||||||
panel.add(btn);
|
panel.add(btn);
|
||||||
|
|
@ -125,77 +105,48 @@ public class CreativeGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel chessPanel() {
|
private JPanel chessPanel() {
|
||||||
JPanel chessPanel = new JPanel(new BorderLayout());
|
JPanel chessPanel = new JPanel(new GridBagLayout());
|
||||||
chessPanel.setBackground(new Color(0x1b263b));
|
chessPanel.setBackground(new Color(0x1b263b));
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
|
||||||
// Board UND Toolbars in EINEM Panel, damit sie linksbündig mit dem Brett starten!
|
// Toolbar oben
|
||||||
JPanel boardAndToolbars = new JPanel(new BorderLayout());
|
gbc.gridx = 0;
|
||||||
boardAndToolbars.setOpaque(false);
|
gbc.gridy = 0;
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
chessPanel.add(toolbarPanel(false), gbc);
|
||||||
|
|
||||||
// Toolbar Schwarz (oben)
|
// Board
|
||||||
JPanel blackToolbar = toolbarPanel(false);
|
gbc.gridx = 0;
|
||||||
boardAndToolbars.add(blackToolbar, BorderLayout.NORTH);
|
gbc.gridy = 1;
|
||||||
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
|
chessPanel.add(boardPanel(), gbc);
|
||||||
|
|
||||||
// Board (zentriert im Panel)
|
// Toolbar unten
|
||||||
JPanel board = boardPanel();
|
gbc.gridx = 0;
|
||||||
boardAndToolbars.add(board, BorderLayout.CENTER);
|
gbc.gridy = 2;
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
chessPanel.add(toolbarPanel(true), gbc);
|
||||||
|
|
||||||
// Toolbar Weiß (unten)
|
// Drehknopf
|
||||||
JPanel whiteToolbar = toolbarPanel(true);
|
flipBoardButton = new JButton("⇵");
|
||||||
boardAndToolbars.add(whiteToolbar, BorderLayout.SOUTH);
|
flipBoardButton.setPreferredSize(new Dimension(70, 70));
|
||||||
|
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||||
|
flipBoardButton.setBackground(new Color(0x5500ff));
|
||||||
|
flipBoardButton.setForeground(Color.WHITE);
|
||||||
|
flipBoardButton.setFocusPainted(false);
|
||||||
|
|
||||||
// Board+Toolbars mittig in einem Panel mit FlowLayout, damit sie zentriert sind
|
GridBagConstraints btn = new GridBagConstraints();
|
||||||
JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
btn.gridx = 0;
|
||||||
centerPanel.setOpaque(false);
|
btn.gridy = 2;
|
||||||
centerPanel.add(boardAndToolbars);
|
btn.weightx = 0.0;
|
||||||
|
btn.weighty = 0.0;
|
||||||
blackToolbar.setPreferredSize(new Dimension(0, 70)); // 70 px hoch
|
btn.anchor = GridBagConstraints.EAST;
|
||||||
whiteToolbar.setPreferredSize(new Dimension(0, 70));
|
btn.insets = new Insets(5, 0, 0, 0);
|
||||||
// Dynamisch skalieren wie gehabt
|
chessPanel.add(flipBoardButton, btn);
|
||||||
centerPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
|
||||||
public void componentResized(java.awt.event.ComponentEvent evt) {
|
|
||||||
int totalHeight = centerPanel.getHeight();
|
|
||||||
int totalWidth = centerPanel.getWidth();
|
|
||||||
int toolbarHeight = blackToolbar.getPreferredSize().height + whiteToolbar.getPreferredSize().height;
|
|
||||||
// Falls Toolbars keine PrefSize haben, nimm getHeight()
|
|
||||||
if (toolbarHeight == 0) toolbarHeight = blackToolbar.getHeight() + whiteToolbar.getHeight();
|
|
||||||
int boardMaxHeight = totalHeight - toolbarHeight;
|
|
||||||
int size = Math.min(totalWidth, boardMaxHeight);
|
|
||||||
board.setPreferredSize(new Dimension(size, size));
|
|
||||||
board.revalidate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
chessPanel.add(centerPanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
// Drehknopf rechts, schön mittig
|
|
||||||
JPanel eastPanel = new JPanel();
|
|
||||||
eastPanel.setOpaque(false);
|
|
||||||
eastPanel.setLayout(new BoxLayout(eastPanel, BoxLayout.Y_AXIS));
|
|
||||||
eastPanel.add(Box.createVerticalGlue());
|
|
||||||
eastPanel.add(flipBoardButton = createFlipButton());
|
|
||||||
eastPanel.add(Box.createVerticalGlue());
|
|
||||||
chessPanel.add(eastPanel, BorderLayout.EAST);
|
|
||||||
|
|
||||||
// Buffer links, wenn du willst
|
|
||||||
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.WEST);
|
|
||||||
|
|
||||||
return chessPanel;
|
return chessPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Flip-Knopf Builder, damit du’s an mehreren Stellen nutzen kannst:
|
|
||||||
private JButton createFlipButton() {
|
|
||||||
JButton btn = new JButton("⇵");
|
|
||||||
btn.setPreferredSize(new Dimension(70, 70));
|
|
||||||
btn.setFont(new Font("SansSerif", Font.BOLD, 40));
|
|
||||||
btn.setBackground(new Color(0x5500ff));
|
|
||||||
btn.setForeground(Color.WHITE);
|
|
||||||
btn.setFocusPainted(false);
|
|
||||||
return btn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private JPanel fenPanel() {
|
private JPanel fenPanel() {
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
@ -209,21 +160,7 @@ public class CreativeGui {
|
||||||
updateBtn = new JButton("Update Board");
|
updateBtn = new JButton("Update Board");
|
||||||
updateBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
updateBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
panel.add(updateBtn);
|
panel.add(updateBtn);
|
||||||
|
|
||||||
startGameButton = new JButton("🟢 Partie starten");
|
|
||||||
startGameButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
||||||
startGameButton.setBackground(new Color(0x218838));
|
|
||||||
startGameButton.setForeground(Color.WHITE);
|
|
||||||
panel.add(startGameButton);
|
|
||||||
|
|
||||||
startGameButton.addActionListener(e -> {
|
|
||||||
if (startGameCallback != null) {
|
|
||||||
setClosedByUser(false);
|
|
||||||
startGameCallback.onStartGame(getFenText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return panel;
|
return panel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Für Controller
|
// Für Controller
|
||||||
|
|
@ -234,21 +171,8 @@ public class CreativeGui {
|
||||||
public JButton getUpdateButton() { return updateBtn; }
|
public JButton getUpdateButton() { return updateBtn; }
|
||||||
public void setSelectedPiece(String piece) { selectedPiece = piece; }
|
public void setSelectedPiece(String piece) { selectedPiece = piece; }
|
||||||
public String getSelectedPiece() { return selectedPiece; }
|
public String getSelectedPiece() { return selectedPiece; }
|
||||||
public void setClosedByUser(boolean b) {
|
|
||||||
this.closedByUser = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JButton getStartGameButton() { return startGameButton; }
|
|
||||||
|
|
||||||
public void setStartGameCallback(StartGameCallback callback) {
|
|
||||||
this.startGameCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFlipped() { return isFlipped; }
|
public boolean isFlipped() { return isFlipped; }
|
||||||
public void setFlipped(boolean f) { isFlipped = f; }
|
public void setFlipped(boolean f) { isFlipped = f; }
|
||||||
public JButton getFlipBoardButton() { return flipBoardButton; }
|
public JButton getFlipBoardButton() { return flipBoardButton; }
|
||||||
|
|
||||||
public void close() {
|
|
||||||
frame.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
||||||
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
||||||
|
|
||||||
public class GameGui {
|
public class GameGui {
|
||||||
JFrame frame;
|
|
||||||
|
|
||||||
private JLabel[][] fields = new JLabel[8][8];
|
private JLabel[][] fields = new JLabel[8][8];
|
||||||
private JButton flipBoardButton;
|
private JButton flipBoardButton;
|
||||||
|
|
@ -44,6 +43,7 @@ public class GameGui {
|
||||||
|
|
||||||
private JButton resignButton;
|
private JButton resignButton;
|
||||||
private JButton drawButton;
|
private JButton drawButton;
|
||||||
|
private JButton quickSaveButton;
|
||||||
private JButton undoButton;
|
private JButton undoButton;
|
||||||
|
|
||||||
Color LIGHT = new Color(0xe0e1dd);
|
Color LIGHT = new Color(0xe0e1dd);
|
||||||
|
|
@ -59,14 +59,13 @@ public class GameGui {
|
||||||
|
|
||||||
|
|
||||||
public JFrame mainFrame() {
|
public JFrame mainFrame() {
|
||||||
frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||||
frame.setUndecorated(false);
|
frame.setUndecorated(false);
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setLocationRelativeTo(null);
|
||||||
frame.add(mainPanel());
|
frame.add(mainPanel());
|
||||||
|
|
||||||
|
frame.setDefaultCloseOperation(2);
|
||||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +238,6 @@ public class GameGui {
|
||||||
btnNext.setBackground(new Color(0x212529)); btnNext.setForeground(Color.WHITE);
|
btnNext.setBackground(new Color(0x212529)); btnNext.setForeground(Color.WHITE);
|
||||||
btnLast.setBackground(new Color(0x212529)); btnLast.setForeground(Color.WHITE);
|
btnLast.setBackground(new Color(0x212529)); btnLast.setForeground(Color.WHITE);
|
||||||
btnSave.setBackground(new Color(0x218838)); btnSave.setForeground(Color.WHITE);
|
btnSave.setBackground(new Color(0x218838)); btnSave.setForeground(Color.WHITE);
|
||||||
|
|
||||||
buttonPanel.add(btnFirst);
|
buttonPanel.add(btnFirst);
|
||||||
buttonPanel.add(btnPrev);
|
buttonPanel.add(btnPrev);
|
||||||
buttonPanel.add(btnNext);
|
buttonPanel.add(btnNext);
|
||||||
|
|
@ -255,8 +253,8 @@ public class GameGui {
|
||||||
JPanel panel = new JPanel(new GridLayout(2, 1));
|
JPanel panel = new JPanel(new GridLayout(2, 1));
|
||||||
panel.setBackground(new Color(0x0d1b2a));
|
panel.setBackground(new Color(0x0d1b2a));
|
||||||
|
|
||||||
whiteTimerLabel = new JLabel("Weiß: --:--", SwingConstants.CENTER);
|
whiteTimerLabel = new JLabel("Weiß: 03:00", SwingConstants.CENTER);
|
||||||
blackTimerLabel = new JLabel("Schwarz: --:--", SwingConstants.CENTER);
|
blackTimerLabel = new JLabel("Schwarz: 03:00", SwingConstants.CENTER);
|
||||||
|
|
||||||
whiteTimerLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
whiteTimerLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
||||||
whiteTimerLabel.setForeground(Color.WHITE);
|
whiteTimerLabel.setForeground(Color.WHITE);
|
||||||
|
|
@ -379,8 +377,4 @@ public class GameGui {
|
||||||
JOptionPane.showMessageDialog(null, msg);
|
JOptionPane.showMessageDialog(null, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JFrame getFrame() {
|
|
||||||
return frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package de.hs_mannheim.informatik.chess.view;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
|
||||||
|
|
||||||
public class GameModeSelector {
|
|
||||||
|
|
||||||
public static GameMode selectGameMode() {
|
|
||||||
GameMode[] options = GameMode.values();
|
|
||||||
GameMode selected = (GameMode) JOptionPane.showInputDialog(
|
|
||||||
null,
|
|
||||||
"Wähle den Spielmodus:",
|
|
||||||
"Spielmodus auswählen",
|
|
||||||
JOptionPane.QUESTION_MESSAGE,
|
|
||||||
null,
|
|
||||||
options,
|
|
||||||
GameMode.CLASSIC
|
|
||||||
);
|
|
||||||
|
|
||||||
return selected != null ? selected : GameMode.CLASSIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,7 +3,6 @@ package de.hs_mannheim.informatik.chess.view;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
|
|
@ -11,7 +10,6 @@ import java.awt.GridLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
@ -35,8 +33,6 @@ public class PgnGui {
|
||||||
JButton btnNext = new JButton(">");
|
JButton btnNext = new JButton(">");
|
||||||
JButton btnLast = new JButton(">|");
|
JButton btnLast = new JButton(">|");
|
||||||
|
|
||||||
private JLabel openingLabel;
|
|
||||||
|
|
||||||
Color LIGHT = new Color(0xe0e1dd);
|
Color LIGHT = new Color(0xe0e1dd);
|
||||||
Color DARK = new Color(0x778da9);
|
Color DARK = new Color(0x778da9);
|
||||||
|
|
||||||
|
|
@ -58,12 +54,6 @@ public class PgnGui {
|
||||||
|
|
||||||
frame.setDefaultCloseOperation(2);
|
frame.setDefaultCloseOperation(2);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
||||||
@Override
|
|
||||||
public void windowClosed(java.awt.event.WindowEvent e) {
|
|
||||||
new de.hs_mannheim.informatik.chess.controller.MainController();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,57 +124,37 @@ public class PgnGui {
|
||||||
return boardPanel;
|
return boardPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel chessPanel(JPanel boardPanel) {
|
public JPanel chessPanel(JPanel panel) {
|
||||||
JPanel chessPanel = new JPanel(new BorderLayout());
|
JPanel chessPanel = new JPanel(new GridBagLayout());
|
||||||
chessPanel.setBackground(new Color(0x1b263b));
|
GridBagConstraints board = new GridBagConstraints();
|
||||||
|
chessPanel.setBackground(new Color(0x1b263b));
|
||||||
|
board.gridx = 0;
|
||||||
|
board.gridy = 0;
|
||||||
|
board.weightx = 0.7;
|
||||||
|
board.weighty = 1.0;
|
||||||
|
board.insets = new Insets(0, 0, 0, 0);
|
||||||
|
//oben, links, unten, rechts
|
||||||
|
board.fill = GridBagConstraints.BOTH;
|
||||||
|
chessPanel.add(panel);
|
||||||
|
// Button unten rechts
|
||||||
|
flipBoardButton = new JButton("⇵");
|
||||||
|
flipBoardButton.setPreferredSize(new Dimension(70, 70));
|
||||||
|
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||||
|
flipBoardButton.setBackground(new Color(0x5500ff));
|
||||||
|
flipBoardButton.setForeground(Color.WHITE);
|
||||||
|
flipBoardButton.setFocusPainted(false);
|
||||||
|
|
||||||
// --- Eröffnungslabel oben ---
|
GridBagConstraints btn = new GridBagConstraints();
|
||||||
openingLabel = new JLabel("Eröffnung: unbekannt", SwingConstants.CENTER);
|
btn.gridx = 0;
|
||||||
openingLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
btn.gridy = 1;
|
||||||
openingLabel.setForeground(Color.WHITE);
|
btn.weightx = 0.0;
|
||||||
openingLabel.setOpaque(true);
|
btn.weighty = 0.0;
|
||||||
openingLabel.setBackground(new Color(0x283655));
|
btn.anchor = GridBagConstraints.SOUTHEAST;
|
||||||
openingLabel.setPreferredSize(new Dimension(800, 50));
|
btn.insets = new Insets(10, 0, 0, 0);
|
||||||
chessPanel.add(openingLabel, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
// --- Board in ein zentriertes Panel mit fixer Größe ---
|
chessPanel.add(flipBoardButton, btn);
|
||||||
JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
|
||||||
centerPanel.setOpaque(false);
|
|
||||||
centerPanel.add(boardPanel);
|
|
||||||
|
|
||||||
centerPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
return chessPanel;
|
||||||
public void componentResized(java.awt.event.ComponentEvent evt) {
|
|
||||||
int size = Math.min(centerPanel.getWidth(), centerPanel.getHeight());
|
|
||||||
boardPanel.setPreferredSize(new Dimension(size, size));
|
|
||||||
boardPanel.revalidate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
chessPanel.add(centerPanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
// --- Dummy-Buffer für WEST und EAST ---
|
|
||||||
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.WEST);
|
|
||||||
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.EAST);
|
|
||||||
|
|
||||||
// --- Buttonleiste unten bauen ---
|
|
||||||
JPanel buttonRow = new JPanel();
|
|
||||||
buttonRow.setOpaque(false);
|
|
||||||
buttonRow.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 0));
|
|
||||||
|
|
||||||
|
|
||||||
flipBoardButton = new JButton("⇵");
|
|
||||||
flipBoardButton.setPreferredSize(new Dimension(70, 70));
|
|
||||||
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
|
||||||
flipBoardButton.setBackground(new Color(0x5500ff));
|
|
||||||
flipBoardButton.setForeground(Color.WHITE);
|
|
||||||
flipBoardButton.setFocusPainted(false);
|
|
||||||
|
|
||||||
buttonRow.add(flipBoardButton);
|
|
||||||
|
|
||||||
chessPanel.add(buttonRow, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
return chessPanel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel statsPanel() {
|
public JPanel statsPanel() {
|
||||||
|
|
@ -270,11 +240,6 @@ public class PgnGui {
|
||||||
this.isFlipped = flipped;
|
this.isFlipped = flipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOpeningLabel(String text) {
|
|
||||||
openingLabel.setText("Eröffnung: " + text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public JButton getBtnFirst() { return btnFirst; }
|
public JButton getBtnFirst() { return btnFirst; }
|
||||||
public JButton getBtnPrev() { return btnPrev; }
|
public JButton getBtnPrev() { return btnPrev; }
|
||||||
public JButton getBtnNext() { return btnNext; }
|
public JButton getBtnNext() { return btnNext; }
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>de.hs-mannheim.informatik.schach</groupId>
|
||||||
|
<artifactId>schach</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>schach</name>
|
||||||
|
<description>A simple schach.</description>
|
||||||
|
<url>http://www.example.com</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Schachlib (bhlangonijr) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.bhlangonijr</groupId>
|
||||||
|
<artifactId>chesslib</artifactId>
|
||||||
|
<version>1.3.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>5.10.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mockito damit man Controller und Gui besser testen kann-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.12.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
||||||
Loading…
Reference in New Issue