mirror of
https://github.com/Vale54321/schafkopf-bot.git
synced 2025-12-16 19:59:33 +01:00
Compare commits
2 Commits
v0.0.1-alp
...
v0.0.1-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e5a42b6d3 | ||
|
|
b8b89ee696 |
6
.github/workflows/relaseNewVersion.yml
vendored
6
.github/workflows/relaseNewVersion.yml
vendored
@@ -52,12 +52,14 @@ jobs:
|
|||||||
|
|
||||||
- name: Archive dist folder
|
- name: Archive dist folder
|
||||||
# run: mv Backend/target/schafkopf-backend-build-jar-with-dependencies.jar schafkopf-bot.jar && zip -r dist.zip schafkopf-bot.jar
|
# run: mv Backend/target/schafkopf-backend-build-jar-with-dependencies.jar schafkopf-bot.jar && zip -r dist.zip schafkopf-bot.jar
|
||||||
run: mv Backend/schafkopf-client/target/schafkopf-client-build-jar-with-dependencies.jar schafkopf-bot-client_${{ github.ref_name }}.jar
|
run: mv Backend/schafkopf-client/target/schafkopf-client-build-jar-with-dependencies.jar schafkopf-bot-client_${{ github.ref_name }}.jar && mv Backend/schafkopf-server/target/schafkopf-server-build-jar-with-dependencies.jar schafkopf-bot-server_${{ github.ref_name }}.jar
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
with:
|
with:
|
||||||
files: schafkopf-bot-client_${{ github.ref_name }}.jar
|
files: |
|
||||||
|
schafkopf-bot-client_${{ github.ref_name }}.jar
|
||||||
|
schafkopf-bot-server_${{ github.ref_name }}.jar
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.PAT }}
|
||||||
|
|
||||||
|
|||||||
@@ -48,13 +48,15 @@ public class BackendServer implements MessageSender {
|
|||||||
// Configure CORS settings
|
// Configure CORS settings
|
||||||
configureCors(context);
|
configureCors(context);
|
||||||
|
|
||||||
URL webContentUrl = getClass().getClassLoader().getResource("web-content");
|
if (openFrontend) {
|
||||||
if (webContentUrl == null) {
|
URL webContentUrl = getClass().getClassLoader().getResource("web-content");
|
||||||
throw new RuntimeException("Unable to find 'web-content' directory");
|
if (webContentUrl == null) {
|
||||||
|
throw new RuntimeException("Unable to find 'web-content' directory");
|
||||||
|
}
|
||||||
|
String webContentPath = webContentUrl.toExternalForm();
|
||||||
|
context.setResourceBase(webContentPath);
|
||||||
|
context.addServlet(new ServletHolder("frontend", DefaultServlet.class), "/");
|
||||||
}
|
}
|
||||||
String webContentPath = webContentUrl.toExternalForm();
|
|
||||||
context.setResourceBase(webContentPath);
|
|
||||||
context.addServlet(new ServletHolder("frontend", DefaultServlet.class), "/");
|
|
||||||
|
|
||||||
// Configure specific websocket behavior
|
// Configure specific websocket behavior
|
||||||
JettyWebSocketServletContainerInitializer.configure(
|
JettyWebSocketServletContainerInitializer.configure(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.schafkopf;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import org.eclipse.jetty.websocket.api.Session;
|
import org.eclipse.jetty.websocket.api.Session;
|
||||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||||
@@ -31,20 +30,11 @@ public class DedicatedServerConnection implements MessageSender {
|
|||||||
* Class that represents one Frontend Connection.
|
* Class that represents one Frontend Connection.
|
||||||
*/
|
*/
|
||||||
public DedicatedServerConnection(String address, MessageListener messageListener) {
|
public DedicatedServerConnection(String address, MessageListener messageListener) {
|
||||||
URI uri = null;
|
|
||||||
try {
|
|
||||||
uri = new URI(address);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.messageListener = messageListener;
|
this.messageListener = messageListener;
|
||||||
this.closeLatch = new CountDownLatch(1);
|
this.closeLatch = new CountDownLatch(1);
|
||||||
this.connectionLatch = new CountDownLatch(1);
|
this.connectionLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
String host = uri.getHost();
|
connect("ws://" + address);
|
||||||
int port = uri.getPort();
|
|
||||||
connect("ws://" + host + ":" + port);
|
|
||||||
try {
|
try {
|
||||||
connectionLatch.await(); // Wait until the connection is established
|
connectionLatch.await(); // Wait until the connection is established
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package org.schafkopf;
|
package org.schafkopf;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import org.schafkopf.GameState.GamePhase;
|
import org.schafkopf.GameState.GamePhase;
|
||||||
import org.schafkopf.SchafkopfException.NotEnoughPlayersException;
|
import org.schafkopf.SchafkopfException.NotEnoughPlayersException;
|
||||||
import org.schafkopf.SchafkopfMessage.SchafkopfBaseMessage;
|
import org.schafkopf.SchafkopfMessage.SchafkopfBaseMessage;
|
||||||
import org.schafkopf.SchafkopfMessage.SchafkopfMessageType;
|
import org.schafkopf.SchafkopfMessage.SchafkopfMessageType;
|
||||||
import org.schafkopf.karte.Karte;
|
|
||||||
import org.schafkopf.karte.KartenFarbe;
|
import org.schafkopf.karte.KartenFarbe;
|
||||||
import org.schafkopf.karte.KartenListe;
|
import org.schafkopf.karte.KartenListe;
|
||||||
import org.schafkopf.karte.KartenUtil;
|
import org.schafkopf.karte.KartenUtil;
|
||||||
@@ -79,23 +76,15 @@ public class Schafkopf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Player currentPlayer : player) {
|
for (Player currentPlayer : player) {
|
||||||
if (currentPlayer instanceof OnlinePlayer) {
|
if (currentPlayer instanceof OnlinePlayer onlinePlayer) {
|
||||||
Karte[] karten = new Karte[8];
|
KartenListe karten = new KartenListe();
|
||||||
for (int i = 7; i >= 0; i--) {
|
for (int i = 7; i >= 0; i--) {
|
||||||
karten[i] = austeilen.removeKarten(austeilen.getByIndex(i));
|
karten.addKarten(austeilen.removeKarten(austeilen.getByIndex(i)));
|
||||||
}
|
}
|
||||||
Gson gson = new Gson();
|
onlinePlayer.setAndSendPlayerCards(karten);
|
||||||
JsonObject messageObject = new JsonObject();
|
|
||||||
messageObject.add("cards", gson.toJsonTree(karten));
|
|
||||||
|
|
||||||
messageSender.sendMessage(
|
|
||||||
new SchafkopfBaseMessage(SchafkopfMessageType.ONLINE_PLAYER_HAND, messageObject));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// spielThread = new Thread(() -> new Spielablauf(this, spiel));
|
|
||||||
//
|
|
||||||
// spielThread.start();
|
|
||||||
new Spielablauf(this, spiel);
|
new Spielablauf(this, spiel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.schafkopf.karte;
|
package org.schafkopf.karte;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonElement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -25,6 +25,19 @@ public class KartenListe {
|
|||||||
return this.kartenListe;
|
return this.kartenListe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Class that represents a list of Cards.
|
||||||
|
*/
|
||||||
|
public void sort() {
|
||||||
|
KartenListe completeDeck = KartenUtil.initializeSchafKopfCardDeck();
|
||||||
|
completeDeck.removeKarten(this);
|
||||||
|
|
||||||
|
KartenListe completeDeck2 = KartenUtil.initializeSchafKopfCardDeck();
|
||||||
|
completeDeck2.removeKarten(completeDeck);
|
||||||
|
|
||||||
|
this.kartenListe = completeDeck2.getKartenListe();
|
||||||
|
}
|
||||||
|
|
||||||
public void shuffle() {
|
public void shuffle() {
|
||||||
Collections.shuffle(this.kartenListe);
|
Collections.shuffle(this.kartenListe);
|
||||||
}
|
}
|
||||||
@@ -185,12 +198,10 @@ public class KartenListe {
|
|||||||
/**
|
/**
|
||||||
* A Class that represents a list of Cards.
|
* A Class that represents a list of Cards.
|
||||||
*/
|
*/
|
||||||
public JsonObject getJson() {
|
public JsonElement getJson() {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
JsonObject jsonObject = new JsonObject();
|
|
||||||
jsonObject.add("cards", gson.toJsonTree(this.kartenListe));
|
|
||||||
|
|
||||||
return jsonObject;
|
return gson.toJsonTree(this.kartenListe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import org.schafkopf.karte.KartenListe;
|
|||||||
import org.schafkopf.karte.KartenUtil;
|
import org.schafkopf.karte.KartenUtil;
|
||||||
import org.schafkopf.spielcontroller.SpielController;
|
import org.schafkopf.spielcontroller.SpielController;
|
||||||
|
|
||||||
/** Player that represents the Bot. */
|
/**
|
||||||
|
* Player that represents the Bot.
|
||||||
|
*/
|
||||||
public class BotPlayer extends Player {
|
public class BotPlayer extends Player {
|
||||||
|
|
||||||
private KartenListe eigeneKarten;
|
private KartenListe eigeneKarten;
|
||||||
@@ -32,9 +34,12 @@ public class BotPlayer extends Player {
|
|||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the Cards of the Player. */
|
/**
|
||||||
|
* Set the Cards of the Player.
|
||||||
|
*/
|
||||||
public void setCards(KartenListe cards) {
|
public void setCards(KartenListe cards) {
|
||||||
System.out.println("Eigene Karte setzen");
|
System.out.println("Eigene Karte setzen");
|
||||||
|
cards.sort();
|
||||||
this.eigeneKarten = cards;
|
this.eigeneKarten = cards;
|
||||||
this.unbekannteKarten = KartenUtil.initializeSchafKopfCardDeck();
|
this.unbekannteKarten = KartenUtil.initializeSchafKopfCardDeck();
|
||||||
this.unbekannteKarten.removeKarten(eigeneKarten);
|
this.unbekannteKarten.removeKarten(eigeneKarten);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.schafkopf.player;
|
package org.schafkopf.player;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import org.schafkopf.MessageSender;
|
import org.schafkopf.MessageSender;
|
||||||
@@ -17,13 +18,26 @@ public class OnlinePlayer extends Player {
|
|||||||
private final MessageSender messageSender;
|
private final MessageSender messageSender;
|
||||||
private final BlockingQueue<Karte> receivedCardQueue = new LinkedBlockingQueue<>();
|
private final BlockingQueue<Karte> receivedCardQueue = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
|
private KartenListe karten = new KartenListe();
|
||||||
|
|
||||||
public OnlinePlayer(MessageSender messageSender) {
|
public OnlinePlayer(MessageSender messageSender) {
|
||||||
this.messageSender = messageSender;
|
this.messageSender = messageSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Class that represents a list of Cards.
|
||||||
|
*/
|
||||||
|
public void setAndSendPlayerCards(KartenListe karten) {
|
||||||
|
karten.sort();
|
||||||
|
this.karten = karten;
|
||||||
|
|
||||||
|
sendPlayerCards();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Karte play(SpielController spiel, KartenListe tischKarten, KartenListe gespielteKarten)
|
public Karte play(SpielController spiel, KartenListe tischKarten, KartenListe gespielteKarten)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
|
sendPlayerCards();
|
||||||
Karte spielKarte = null;
|
Karte spielKarte = null;
|
||||||
|
|
||||||
// Send the message to request the card from the frontend
|
// Send the message to request the card from the frontend
|
||||||
@@ -32,10 +46,20 @@ public class OnlinePlayer extends Player {
|
|||||||
|
|
||||||
spielKarte = receivedCardQueue.take();
|
spielKarte = receivedCardQueue.take();
|
||||||
|
|
||||||
|
this.karten.removeKarten(spielKarte);
|
||||||
|
sendPlayerCards();
|
||||||
System.out.println("Karte gespielt: " + spielKarte);
|
System.out.println("Karte gespielt: " + spielKarte);
|
||||||
return spielKarte;
|
return spielKarte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPlayerCards() {
|
||||||
|
JsonObject messageObject = new JsonObject();
|
||||||
|
messageObject.add("cards", this.karten.getJson());
|
||||||
|
|
||||||
|
messageSender.sendMessage(
|
||||||
|
new SchafkopfBaseMessage(SchafkopfMessageType.ONLINE_PLAYER_HAND, messageObject));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents one Frontend Connection.
|
* Class that represents one Frontend Connection.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ function joinGame(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendCard(cardInput: Card): void {
|
function sendCard(cardInput: Card): void {
|
||||||
const index = botCards.value!.findIndex(card => card === cardInput);
|
|
||||||
|
|
||||||
// If card exists in the array, remove it
|
|
||||||
if (index !== -1) {
|
|
||||||
botCards.value!.splice(index, 1);
|
|
||||||
}
|
|
||||||
backendConnection.sendMessage(MessageType.PLAYER_CARD, {card: cardInput});
|
backendConnection.sendMessage(MessageType.PLAYER_CARD, {card: cardInput});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {BackendMessage, MessageType} from "../BackendMessage.ts";
|
|||||||
|
|
||||||
const backendConnection = scg("BackendConnection");
|
const backendConnection = scg("BackendConnection");
|
||||||
|
|
||||||
const serverAddress = ref("http://10.6.9.57:8085/")
|
const serverAddress = ref("10.6.9.57:8085")
|
||||||
const isConnected = ref<boolean>(false);
|
const isConnected = ref<boolean>(false);
|
||||||
const isPingInProgress = ref<boolean>(false);
|
const isPingInProgress = ref<boolean>(false);
|
||||||
const secondsRemaining = ref<number>(10);
|
const secondsRemaining = ref<number>(10);
|
||||||
@@ -30,7 +30,7 @@ async function checkConnection(): Promise<void> {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Try to fetch a resource from the internet
|
// Try to fetch a resource from the internet
|
||||||
await fetch(serverAddress.value + "health", {mode: "no-cors"})
|
await fetch("http://" + serverAddress.value + "/health", {mode: "no-cors"})
|
||||||
// If successful, set isConnected to true
|
// If successful, set isConnected to true
|
||||||
isConnected.value = true;
|
isConnected.value = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user