404 IQ-Move added move logic

This commit is contained in:
Benjamin Feyer
2024-12-09 16:10:56 +01:00
18 changed files with 321 additions and 44 deletions

View File

@@ -0,0 +1,21 @@
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000070ba272e8104, pid=54211, tid=54346
#
# JRE version: OpenJDK Runtime Environment Temurin-20.0.2+9 (20.0.2+9) (build 20.0.2+9)
# Java VM: OpenJDK 64-Bit Server VM Temurin-20.0.2+9 (20.0.2+9, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V [libjvm.so+0xee8104] SystemDictionary::find_or_define_helper(Symbol*, Handle, InstanceKlass*, JavaThread*)+0x304
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/cedric/ProgProjekt/Gruppe-01/Projekte/mdga/client/core.54211)
#
# If you would like to submit a bug report, please visit:
# https://github.com/adoptium/adoptium-support/issues
#
--------------- S U M M A R Y ------------
Command Line: -Ddebugger.agent.enable.coroutines=true -Djava.util.logging.config.file=logging.properties -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:40559 -javaagent:/usr/share/idea/plugins/java/lib/rt/debugger-agent.jar -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea pp.mdga.client.MdgaApp
Host: AMD Ryzen 5 8640HS w/ Radeon 760M Graphics, 12 cores, 14G,

View File

@@ -0,0 +1,171 @@
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fc14e0eef41, pid=60653, tid=60689
#
# JRE version: OpenJDK Runtime Environment (21.0.5+11) (build 21.0.5+11)
# Java VM: OpenJDK 64-Bit Server VM (21.0.5+11, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C [libgallium-24.2.8-arch1.1.so+0x8eef41]
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/cedric/ProgProjekt/Gruppe-01/Projekte/mdga/client/core.60653)
#
# If you would like to submit a bug report, please visit:
# https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
--------------- S U M M A R Y ------------
Command Line: -Ddebugger.agent.enable.coroutines=true -Djava.util.logging.config.file=logging.properties -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:39131 -javaagent:/usr/share/idea/plugins/java/lib/rt/debugger-agent.jar -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea pp.mdga.client.MdgaApp
Host: AMD Ryzen 5 8640HS w/ Radeon 760M Graphics, 12 cores, 14G, Manjaro Linux
Time: Sun Dec 8 18:11:23 2024 CET elapsed time: 295.650309 seconds (0d 0h 4m 55s)
--------------- T H R E A D ---------------
Current thread (0x00007fc17ca803b0): JavaThread "jME3 Main" [_thread_in_native, id=60689, stack(0x00007fc159425000,0x00007fc159525000) (1024K)]
Stack: [0x00007fc159425000,0x00007fc159525000], sp=0x00007fc159522300, free space=1012k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libgallium-24.2.8-arch1.1.so+0x8eef41]
C [libgallium-24.2.8-arch1.1.so+0xf4a849]
C [libgallium-24.2.8-arch1.1.so+0x6ccb71]
C [libgallium-24.2.8-arch1.1.so+0x6c58ae]
C [libgallium-24.2.8-arch1.1.so+0x6c6013]
C [libgallium-24.2.8-arch1.1.so+0x6cddf8]
C [libgallium-24.2.8-arch1.1.so+0x141327]
C [libgallium-24.2.8-arch1.1.so+0x5fc8b]
C [libGLX_mesa.so.0+0x4f2e0]
C [libGLX_mesa.so.0+0x40496]
C [libGLX_mesa.so.0+0x2efa5]
J 2042 org.lwjgl.system.JNI.invokePV(JJ)V (0 bytes) @ 0x00007fc16c1abb6f [0x00007fc16c1abaa0+0x00000000000000cf]
J 4039 c1 org.lwjgl.glfw.GLFW.glfwSwapBuffers(J)V (21 bytes) @ 0x00007fc164d8684c [0x00007fc164d86760+0x00000000000000ec]
J 3912 c1 com.jme3.system.lwjgl.LwjglWindow.runLoop()V (177 bytes) @ 0x00007fc164d44b34 [0x00007fc164d442c0+0x0000000000000874]
j com.jme3.system.lwjgl.LwjglWindow.run()V+54
j java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V+5 java.base@21.0.5
j java.lang.Thread.run()V+19 java.base@21.0.5
v ~StubRoutines::call_stub 0x00007fc16bb37cc6
V [libjvm.so+0x6d0894]
V [libjvm.so+0x6d14fd]
V [libjvm.so+0x79a7be]
V [libjvm.so+0x6cac55]
V [libjvm.so+0x9d62c1]
C [libc.so.6+0x9439d]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 2042 org.lwjgl.system.JNI.invokePV(JJ)V (0 bytes) @ 0x00007fc16c1abafc [0x00007fc16c1abaa0+0x000000000000005c]
J 4039 c1 org.lwjgl.glfw.GLFW.glfwSwapBuffers(J)V (21 bytes) @ 0x00007fc164d8684c [0x00007fc164d86760+0x00000000000000ec]
J 3912 c1 com.jme3.system.lwjgl.LwjglWindow.runLoop()V (177 bytes) @ 0x00007fc164d44b34 [0x00007fc164d442c0+0x0000000000000874]
j com.jme3.system.lwjgl.LwjglWindow.run()V+54
j java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V+5 java.base@21.0.5
j java.lang.Thread.run()V+19 java.base@21.0.5
v ~StubRoutines::call_stub 0x00007fc16bb37cc6
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x00000000000000c9
Registers:
RAX=0x0000000000000000, RBX=0x00007fc09825b2a0, RCX=0x0000000000000006, RDX=0x0000000028200000
RSP=0x00007fc159522300, RBP=0x00007fc159522310, RSI=0x00007fc0998d3604, RDI=0x00007fc09825b7a0
R8 =0x0000000000000006, R9 =0x00000000aa959a6a, R10=0x0000000000000263, R11=0x00007fc099bc36c0
R12=0x00007fc0998d35e0, R13=0x000000058bc5f100, R14=0x000000058bc5f140, R15=0x0000000000000040
RIP=0x00007fc14e0eef41, EFLAGS=0x0000000000010202, CSGSFS=0x002b000000000033, ERR=0x0000000000000004
TRAPNO=0x000000000000000e
Register to memory mapping:
RAX=0x0 is null
RBX=0x00007fc09825b2a0 points into unknown readable memory: 0x00007fc098239c40 | 40 9c 23 98 c0 7f 00 00
RCX=0x0000000000000006 is an unknown value
RDX=0x0000000028200000 is an unknown value
RSP=0x00007fc159522300 is pointing into the stack for thread: 0x00007fc17ca803b0
RBP=0x00007fc159522310 is pointing into the stack for thread: 0x00007fc17ca803b0
RSI=0x00007fc0998d3604 points into unknown readable memory: 00 00 00 00
RDI=0x00007fc09825b7a0 points into unknown readable memory: 0x00001c7c00000265 | 65 02 00 00 7c 1c 00 00
R8 =0x0000000000000006 is an unknown value
R9 =0x00000000aa959a6a is an unknown value
R10=0x0000000000000263 is an unknown value
R11=0x00007fc099bc36c0 points into unknown readable memory: 0x00007fc14e121570 | 70 15 12 4e c1 7f 00 00
R12=0x00007fc0998d35e0 points into unknown readable memory: 0x0000000000000000 | 00 00 00 00 00 00 00 00
R13=0x000000058bc5f100 is an unknown value
R14=0x000000058bc5f140 is an unknown value
R15=0x0000000000000040 is an unknown value
Top of Stack: (sp=0x00007fc159522300)
0x00007fc159522300: 00007fc09825b2a0 ffffffffffffffff
0x00007fc159522310: 00007fc1595223d0 00007fc14e74a849
0x00007fc159522320: 0000000000000000 00000000cc0016c8
0x00007fc159522330: 00007fc09920b000 00007fc100000004
0x00007fc159522340: 00007fc100000001 00007fc100000000
0x00007fc159522350: ffff800100000002 00007fc09825b7a0
0x00007fc159522360: 00007fc1595223e0 0000000100000b02
0x00007fc159522370: 0000000000000000 00007fc0983eca88
0x00007fc159522380: 00007fc100000000 00007fc099e33780
0x00007fc159522390: 00007fc159523170 b36c5690f9bb0900
0x00007fc1595223a0: 00007fc15951fd20 00007fc0983eca80
0x00007fc1595223b0: 00007fc09825b2a0 00007fc0983edb60
0x00007fc1595223c0: 00007fc098415b10 00007fc0983ec850
0x00007fc1595223d0: 00007fc159523280 00007fc14deccb71
0x00007fc1595223e0: 00000bdc00000000 00007fc100000000
0x00007fc1595223f0: 00007fc159523290 00007fc159523294
0x00007fc159522400: 00007fc159523320 00007fc159523324
0x00007fc159522410: 00007fc1595231b0 00007fc1595231b4
0x00007fc159522420: 00007fc159522860 00007fc164c8401c
0x00007fc159522430: 00007fc159523310 00007fc159523314
0x00007fc159522440: 00007fc1595232a0 00007fc1595232a4
0x00007fc159522450: 00007fc159522860 00007fc159523334
0x00007fc159522460: 00007fc159523400 00007fc159523404
0x00007fc159522470: 00007fc1595232d0 00007fc1595232d4
0x00007fc159522480: 00007fc16bc61f10 00007fc0c80123d0
0x00007fc159522490: 00007fc1595231f0 00007fc1595231f4
0x00007fc1595224a0: 00007fc1595223e0 00000000e31c914f
0x00007fc1595224b0: 00007fc159523350 00007fc159523354
0x00007fc1595224c0: 00007fc1595232e0 00007fc1595232e4
0x00007fc1595224d0: 00007f0000000000 00000000e3193478
0x00007fc1595224e0: 00007fc159523440 00007fc159523444
0x00007fc1595224f0: 00007fc159523310 00007fc159523314
Instructions: (pc=0x00007fc14e0eef41)
0x00007fc14e0eee41: 0f 1e fa 55 48 83 c6 24 48 89 e5 41 55 41 54 53
0x00007fc14e0eee51: 48 89 fb 48 83 ec 08 8b 97 00 05 00 00 44 0f b7
0x00007fc14e0eee61: 6e f0 48 8b 87 08 05 00 00 49 89 d4 45 01 ec 48
0x00007fc14e0eee71: 8d 3c 90 42 8d 14 ad 00 00 00 00 ff 15 ee 7e c3
0x00007fc14e0eee81: 01 44 89 a3 00 05 00 00 48 83 c4 08 5b 41 5c 41
0x00007fc14e0eee91: 5d 5d c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 f3
0x00007fc14e0eeea1: 0f 1e fa 55 48 89 e5 41 57 41 56 41 55 41 54 41
0x00007fc14e0eeeb1: 89 f4 53 48 89 fb 48 83 ec 08 4e 8b b4 e7 88 09
0x00007fc14e0eeec1: 00 00 8b 97 00 05 00 00 48 8b 87 08 05 00 00 45
0x00007fc14e0eeed1: 0f b7 7e 14 49 89 d5 49 8d 76 24 48 8d 3c 90 45
0x00007fc14e0eeee1: 01 fd 42 8d 14 bd 00 00 00 00 ff 15 7f 7e c3 01
0x00007fc14e0eeef1: 44 89 ab 00 05 00 00 4e 89 b4 e3 d8 09 00 00 48
0x00007fc14e0eef01: 83 c4 08 5b 41 5c 41 5d 41 5e 41 5f 5d c3 90 f3
0x00007fc14e0eef11: 0f 1e fa 55 89 f0 48 89 e5 41 54 53 4c 8b a4 c7
0x00007fc14e0eef21: 88 09 00 00 48 89 fb e8 73 ff ff ff 49 8b 84 24
0x00007fc14e0eef31: 80 01 00 00 ba 00 00 20 28 48 8d bb 00 05 00 00
0x00007fc14e0eef41: 0f b6 88 c9 00 00 00 48 8b b0 b0 00 00 00 48 8b
0x00007fc14e0eef51: 83 f0 04 00 00 ff 90 00 01 00 00 49 8b 04 24 48
0x00007fc14e0eef61: 85 c0 74 13 48 89 df be ff ff ff ff 5b 41 5c 5d
0x00007fc14e0eef71: ff e0 0f 1f 44 00 00 5b 41 5c 5d c3 0f 1f 00 f3
0x00007fc14e0eef81: 0f 1e fa 66 0f ef c0 31 c9 ba 01 00 00 00 0f 11
0x00007fc14e0eef91: 87 d8 09 00 00 0f 11 87 e8 09 00 00 0f 11 87 f8
0x00007fc14e0eefa1: 09 00 00 0f 11 87 08 0a 00 00 0f 11 87 18 0a 00
0x00007fc14e0eefb1: 00 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 48
0x00007fc14e0eefc1: 83 bc cf 88 09 00 00 00 74 0d 48 89 d0 48 d3 e0
0x00007fc14e0eefd1: 48 09 87 80 09 00 00 48 83 c1 01 48 83 f9 0a 75
0x00007fc14e0eefe1: de c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3
0x00007fc14e0eeff1: 0f 1e fa 55 48 89 e5 41 56 41 89 d6 41 55 41 89
0x00007fc14e0ef001: f5 8d 34 b5 28 00 00 00 41 54 49 89 fc bf 01 00
0x00007fc14e0ef011: 00 00 53 ff 15 7e 89 c3 01 48 89 c3 48 85 c0 74
0x00007fc14e0ef021: 2a 66 44 89 68 1a 41 0f b6 ce 48 8d 78 08 41 0f
0x00007fc14e0ef031: b6 94 24 97 08 00 00 49 8d b4 24 90 02 00 00 c0
Stack slot to memory mapping:
stack at sp + 0 slots: 0x00007fc09825b2a0 points into unknown readable memory: 0x00007fc098239c40 | 40 9c 23 98 c0 7f 00 00
stack at sp + 1 slots: 0xffffffffffffffff is an unknown value
stack at sp + 2 slots: 0x00007fc1595223d0 is pointing into the stack for thread: 0x00007fc17ca803b0
stack at sp + 3 slots: 0x00007fc14e74a849: <offset 0x0000000000f4a849> in /usr/lib/libgallium-24.2.8-arch1.1.so at 0x00007fc14d800000
stack at sp + 4 slots: 0x0 is null
stack at sp + 5 slots:

View File

@@ -66,7 +66,7 @@ public class MdgaApp extends SimpleApplication {
private ServerConnection networkConnection;
public static final int DEBUG_MULTIPLIER = 0;
public static final int DEBUG_MULTIPLIER = 1;
public MdgaApp() {
networkConnection = new NetworkSupport(this);

View File

@@ -21,7 +21,7 @@
public class DiceControl extends AbstractControl {
private Quaternion targetRotation;
private final Vector3f angularVelocity = new Vector3f();
private float deceleration = 0.5f;
private float deceleration = 1.7f;
private float timeElapsed = 0.0f;
private float rollDuration = 1f;
private static final int ANGULAR_MIN = 5;

View File

@@ -128,7 +128,7 @@ private BitmapText createName(String name, boolean first, boolean own){
//renderedSize = 45
hudText.setSize(TEXT_SIZE);
hudText.setColor(first ? ACTIVE_COLOR : own ? OWN_COLOR : NORMAL_COLOR);
hudText.setText(name);
hudText.setText(own ? name + " (Du)" : name);
hudText.setLocalTranslation(PADDING_LEFT,hudText.getHeight()/2, 0);
return hudText;
}

View File

@@ -47,8 +47,12 @@ protected void throwPiece(Piece piece) {
}
private void handleShield(UUID uuid) {
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughUUID(uuid)) % 10 != 0) {
Board board = logic.getGame().getBoard();
Piece piece = logic.getGame().getPieceThroughUUID(uuid);
Node node = board.getInfield()[board.getInfieldIndexOfPiece(piece)];
if (node.isStart()) {
logic.getGame().getPieceThroughUUID(uuid).setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldActiveNotification(uuid));
logic.addNotification(new ShieldSuppressedNotification(uuid));
} else {
logic.getGame().getPieceThroughUUID(uuid).setShield(ShieldState.ACTIVE);

View File

@@ -3,6 +3,7 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.TurnState;
import pp.mdga.game.BonusCard;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.notification.PlayCardNotification;
@@ -12,6 +13,7 @@ public class PlayPowerCardState extends TurnStates {
private final TurnState parent;
private PlayCardMessage playCardMessage;
private int animationCounter = 0;
public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -20,7 +22,11 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
@Override
public void enter() {
animationCounter++;
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard().getCard()));
if(!playCardMessage.getCard().getCard().equals(BonusCard.TURBO)){
animationCounter++;
}
handlePowerCard(playCardMessage);
}
@@ -35,7 +41,10 @@ public void setPlayCard(PlayCardMessage playCardMessage) {
@Override
public void selectAnimationEnd(){
logic.send(new AnimationEndMessage());
parent.setState(parent.getRollDice());
animationCounter--;
if(animationCounter == 0){
logic.send(new AnimationEndMessage());
parent.setState(parent.getRollDice());
}
}
}

View File

@@ -57,16 +57,32 @@ public void received(MoveMessage msg) {
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
int infieldIndex=logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
System.out.println("Client: SelectState: activePiece in Home: infieldIndex"+infieldIndex);
if(msg.getTargetIndex()==logic.getGame().getActivePlayer().getHighestHomeIdx()){
piece.setState(PieceState.HOMEFINISHED);
}
else{
piece.setState(PieceState.HOME);
}
logic.getGame().getBoard().getInfield()[infieldIndex].clearOccupant();
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
}
else{
System.out.println("Client: SelectPieceState: receivedMoveMessage:reached else");
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
System.out.println("Client: electPieceState: homeindex"+logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece));
int pieceHomeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
if(msg.getTargetIndex()==logic.getGame().getActivePlayer().getHighestHomeIdx()){
piece.setState(PieceState.HOMEFINISHED);
}
else{
piece.setState(PieceState.HOME);
}
logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex].clearOccupant();
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
}
/*
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));

View File

@@ -87,7 +87,7 @@ public Game() {
gameStatistics = new Statistic();
initializeDrawPile();
board = new Board();
die = new Die(5,5,5,5,5,5,5,5,1,2,1,2,2,6,3,6);
die = new Die(5, 5,5,5,5,5,5,5,5,3, 6 ,5,5,5,5,5,5,5,5,3 );
}
/**
@@ -95,8 +95,8 @@ public Game() {
*/
private void initializeDrawPile() {
// this.addBonusCards(new TurboCard(), AMOUNT_OF_TURBO_CARDS);
this.addBonusCards(new SwapCard(), AMOUNT_OF_SWAP_CARDS);
// this.addBonusCards(new ShieldCard(), AMOUNT_OF_SHIELD_CARDS);
// this.addBonusCards(new SwapCard(), AMOUNT_OF_SWAP_CARDS);
this.addBonusCards(new ShieldCard(), AMOUNT_OF_SHIELD_CARDS);
Collections.shuffle(this.drawPile);
}

View File

@@ -99,4 +99,8 @@ public boolean isOccupied() {
public boolean isOccupied(Color color) {
return isOccupied() && this.occupant.getColor() == color;
}
public boolean isStart() {
return false;
}
}

View File

@@ -205,6 +205,22 @@ public boolean isHomeFinished(Piece piece) {
return true;
}
/**
* this method will be used to determine the highest index in the home
*
* @return the index
*/
public int getHighestHomeIdx(){
for (int i =3; i>=0;i--){
if(!homeNodes[i].isOccupied()) {
System.out.println("Player: highestHomeIndex:"+i);
return i;
}
}
return -1;
}
/**
* This method returns the give name of the Player
*

View File

@@ -47,4 +47,9 @@ public Color getColor() {
public void setColor(Color color) {
this.color = color;
}
@Override
public boolean isStart() {
return true;
}
}

View File

@@ -37,7 +37,6 @@ public GameState(ServerGameLogic logic) {
this.determineStartPlayerState = new DetermineStartPlayerState(this, logic);
this.animationState = new AnimationState(this, logic);
this.turnState = new TurnState(this, logic);
this.setCurrentState(this.determineStartPlayerState);
}
/**
@@ -46,6 +45,7 @@ public GameState(ServerGameLogic logic) {
@Override
public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered GameState state.");
this.setCurrentState(this.determineStartPlayerState);
}
/**

View File

@@ -30,8 +30,10 @@ public class DetermineStartPlayerState extends GameAutomatonState {
* Create DetermineStartPlayerState attributes.
*/
private final Map<Integer, Integer> diceResults = new HashMap<>();
private final Map<Integer, Integer> finalDiceResults = new HashMap<>();
private final List<Integer> playersHaveToRoll = new ArrayList<>();
private final Set<Integer> messageReceived = new HashSet<>();;
private int playerToStart;
/**
* Constructs a server state of the specified game logic.
@@ -45,12 +47,13 @@ public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic)
@Override
public void enter() {
LOGGER.log(System.Logger.Level.DEBUG, "Entered DetermineStartPlayerState state.");
LOGGER.log(System.Logger.Level.INFO, "Entered DetermineStartPlayerState state.");
playerToStart = this.logic.getGame().getPlayers().size();
}
@Override
public void exit() {
LOGGER.log(System.Logger.Level.DEBUG, "Exited DetermineStartPlayerState state.");
LOGGER.log(Level.INFO, "Exited DetermineStartPlayerState state.");
this.diceResults.clear();
this.messageReceived.clear();
}
@@ -67,23 +70,21 @@ public void received(RequestDieMessage msg, int from) {
int roll = this.logic.getGame().getDie().shuffle();
this.logic.getServerSender().send(from, new DieMessage(roll));
this.diceResults.put(from, roll);
if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) {
if (this.diceResults.size() == playerToStart) {
int maximumRoll = 0;
for (Map.Entry<Integer, Integer> entry : this.diceResults.entrySet()) {
if (maximumRoll == entry.getValue()) {
this.playersHaveToRoll.add(entry.getKey());
LOGGER.log(Level.INFO, "Players have to roll(RD same as maximum): {0}", this.playersHaveToRoll.size());
}
else if (maximumRoll < entry.getValue()) {
maximumRoll = entry.getValue();
this.playersHaveToRoll.clear();
this.playersHaveToRoll.add(entry.getKey());
LOGGER.log(Level.INFO, "Players have to roll(RD higher as maximum): {0}", this.playersHaveToRoll.size());
}
}
for (int id: this.playersHaveToRoll) {
this.diceResults.remove(id);
}
}
}
@@ -97,18 +98,24 @@ else if (maximumRoll < entry.getValue()) {
@Override
public void received(AnimationEndMessage msg, int from) {
this.messageReceived.add(from);
if (this.messageReceived.size() == this.logic.getGame().getPlayers().size()) {
if (this.messageReceived.size() == playerToStart) {
this.messageReceived.clear();
LOGGER.log(Level.INFO, "Players have to roll(Animation End): {0}", this.playersHaveToRoll.size());
if (this.playersHaveToRoll.size() > 1) {
playerToStart = this.playersHaveToRoll.size();
for (Integer id : this.playersHaveToRoll) {
diceResults.remove(id);
this.logic.getServerSender().send(id, new DiceNowMessage());
}
finalDiceResults.putAll(this.diceResults);
diceResults.clear();
}
else {
finalDiceResults.putAll(this.diceResults);
LOGGER.log(Level.INFO, "Players have to roll: %s".formatted(this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0))));
Color color = this.logic.getGame().getPlayerById(this.playersHaveToRoll.get(0)).getColor();
this.logic.getGame().setActiveColor(color);
this.logic.getServerSender().broadcast(new RankingResponseMessage(this.diceResults));
this.logic.getServerSender().broadcast(new RankingResponseMessage(this.finalDiceResults));
this.logic.getServerSender().broadcast(new ActivePlayerMessage(color));
this.gameAutomaton.setCurrentState(this.gameAutomaton.getAnimationState());
}

View File

@@ -121,21 +121,22 @@ protected int calculateTargetIndex(Piece piece) {
* @return true, if the piece can move
*/
protected boolean canMove(Piece piece) {
System.out.println("Server: ChoosePieceStateMachine: canMove: piece.getState()" + piece.getState());
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
int pieceIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
System.out.println("ChoosePieceAutomaton: pieceIndex:" + pieceIdx);
int startIdx = logic.getGame().getActivePlayer().getStartNodeIndex();
int normPieceIdx = (-startIdx + pieceIdx + 40) % 40;
int targetIdx = normPieceIdx + steps;
System.out.println("Server: ChoosePieceStateMachine: canMove: piece.getState()" + piece.getState());
System.out.println("Server: ChoosePieceStateAutomaton: canMove:" + canPieceMoveInHome(piece, steps));
//checks if the piece can move in the home
if (canPieceMoveInHome(piece, steps)) {
System.out.println("Server: ChoosePieceStateMachine:canMove: entered canMove/canPieceMoveInHome");
return true;
}
int pieceIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
System.out.println("ChoosePieceAutomaton: pieceIndex:" + pieceIdx);
int startIdx = logic.getGame().getActivePlayer().getStartNodeIndex();
int normPieceIdx = (-startIdx + pieceIdx + 40) % 40;
int targetIdx = normPieceIdx + steps;
//checks if the piece will not go over its home-field
if (40 > targetIdx) {
else if(40 > targetIdx && (!piece.getState().equals(PieceState.HOME)||!piece.getState().equals(PieceState.HOMEFINISHED))) {
Color activeColor = logic.getGame().getActiveColor();
System.out.println("ChoosePieceAutomaton: targetindex:" + (pieceIdx + steps) % 40);
Node tartgetNode = logic.getGame().getBoard().getInfield()[(pieceIdx + steps) % 40];
@@ -162,18 +163,18 @@ protected boolean canPieceMoveInHome(Piece piece, int steps) {
//tests if the piece can move inside the home
System.out.println("Server: ChoosePieceStateMachine: canPieceMoveInHome: pieceState:" + piece.getState());
steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
if (piece.getState() == PieceState.HOME) {
if (piece.getState().equals(PieceState.HOME)) {
System.out.println("Server: ChoosePieceStateMachine: canPieceMoveInHome: pieceState:reached if(piece.getState()==PieceState.HOME)");
int homeIdx = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
//tests if the steps are less than the possible movement
System.out.println("Server: ChoosePieceAutomaton: canPieceMoveInHome: reached second if: (4 - homeIdx) > steps:"+ ((4 - homeIdx) > steps)+ "steps:"+steps+"homeIdx:"+homeIdx);
System.out.println("Server: ChoosePieceAutomaton: canPieceMoveInHome: reached second if: (4 - homeIdx) > steps:" + ((4 - homeIdx) > steps) + "steps:" + steps + "homeIdx:" + homeIdx);
if ((4 - homeIdx) > steps) {
System.out.println("Server: canPieceMoveInHome: !jumpOver" + !jumpOver(steps, homeIdx, false));
return !jumpOver(steps, homeIdx, false);
}
}
//tests if the piece can move in the home
if (piece.getState() == PieceState.ACTIVE) {
else if (piece.getState() == PieceState.ACTIVE) {
int pieceIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
int startIdx = logic.getGame().getActivePlayer().getStartNodeIndex();
int normPieceIdx = (-startIdx + pieceIdx + 40) % 40;
@@ -185,12 +186,16 @@ protected boolean canPieceMoveInHome(Piece piece, int steps) {
System.out.println("Server: ChoosePieceStateMachine: canPieceMoveInHome: stepsToHome:" + stepsToHome + "restMovement:" + restMovement + "jumpOver:" + jumpOver(restMovement, 0, true) + "canPieceMoveInHome: return:" + true);
return !jumpOver(restMovement, 0, true);
}
} else {
System.out.println("Server: ChoosePieceStateMachine: canPieceMoveInHome: return:" + false);
return false;
}
System.out.println("Server: ChoosePieceStateMachine: canPieceMoveInHome: return:" + false);
return false;
}
/**
* tests if the piece, when moved in or inside a home, must jump over another piece
*
@@ -200,8 +205,10 @@ protected boolean canPieceMoveInHome(Piece piece, int steps) {
* @return false, if there is no piece to jump over
*/
private boolean jumpOver(int stepsInHome, int homeIdx, boolean outside) {
//tests if the piece comes from the outside in the home
if (outside) {
if (logic.getGame().getActivePlayer().getHomeNodes()[stepsInHome].isOccupied()) return true;
System.out.println("Server: ChoosePieceState: jumpOver: from outside");
for (int i = 0; i < stepsInHome; i++) {
if (logic.getGame().getActivePlayer().getHomeNodes()[i].isOccupied()) return true;
@@ -209,6 +216,7 @@ private boolean jumpOver(int stepsInHome, int homeIdx, boolean outside) {
}
//tests if the piece jumps over a piece from inside the home
else {
if (logic.getGame().getActivePlayer().getHomeNodes()[stepsInHome + homeIdx].isOccupied()) return true;
for (int i = 1 + homeIdx; i < homeIdx + stepsInHome; i++) {
if (logic.getGame().getActivePlayer().getHomeNodes()[i].isOccupied()) return true;
}

View File

@@ -91,7 +91,7 @@ public void received(RequestMoveMessage msg, int from){
Piece piece = moveablePieces.get(indexOfPiece);
if(canPieceMoveInHome(piece,steps)){
System.out.println("Server: SelectPieceState: canPieceMoveInHome(piece,steps)");
if(piece.getState()==PieceState.HOME) {
if(piece.getState().equals(PieceState.HOME)) {
System.out.println("Server: SelectPieceState: piece.getState()==PieceState.HOME");
//gets the oldNode
int homeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
@@ -99,15 +99,17 @@ public void received(RequestMoveMessage msg, int from){
//gets the targetNode
int targetHomeIdx = getHomeTargetIdx(piece,steps);
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[targetHomeIdx];
oldNode.clearOccupant();
targetNode.setOccupant(piece);
if (targetHomeIdx == 3) {
if (targetHomeIdx ==logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
else{
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
System.out.println("sets homefinsihed here:"+ (targetHomeIdx ==logic.getGame().getActivePlayer().getHighestHomeIdx())+"targetIdx:"+targetHomeIdx+"HighestHomeIdx:"+logic.getGame().getActivePlayer().getHighestHomeIdx());
}
else{
System.out.println("Server: SelectPieceState: entered else");
@@ -118,13 +120,17 @@ public void received(RequestMoveMessage msg, int from){
int targetHomeIdx = getHomeTargetIdx(piece,steps);
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[targetHomeIdx];
oldNode.clearOccupant();
targetNode.setOccupant(piece);
if (targetHomeIdx == 3) {
if (targetHomeIdx ==logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
}
piece.setState(PieceState.HOME);
else{
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
System.out.println("sets homefinsihed:"+ (targetHomeIdx ==logic.getGame().getActivePlayer().getHighestHomeIdx())+"targetIdx:"+targetHomeIdx+"HighestHomeIdx:"+logic.getGame().getActivePlayer().getHighestHomeIdx());
System.out.println("Server: SelectPieceMessage: received(RequestMoveMessage): setPiece(Home)"+piece.getState());
}
LOGGER.log(System.Logger.Level.INFO,"Server : SelectPieceState: PieceState:"+piece.getState());

View File

@@ -22,6 +22,7 @@ public class FirstRollState extends RollDiceAutomatonState {
private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
private List<Piece> moveablePieces;
private int roll;
private boolean isDied = false;
/**
* Constructs a server state of the specified game logic.
@@ -37,6 +38,7 @@ public FirstRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
public void enter() {
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
roll = 0;
isDied = false;
moveablePieces = new ArrayList<>();
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
@@ -62,14 +64,16 @@ public void received(RequestDieMessage msg, int from) {
roll = this.logic.getGame().getDie().shuffle();
this.logic.getGame().setDiceEyes(roll);
this.logic.getServerSender().broadcast(new DieMessage(roll));
isDied = true;
}
@Override
public void received(AnimationEndMessage msg, int from) {
if (from != this.logic.getGame().getActivePlayerId()) {
return;
}
if (!moveablePieces.isEmpty()) {
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage from wrong player.");
} else if (!isDied){
LOGGER.log(System.Logger.Level.INFO, "Received AnimationEndMessage without the active player rolling a die.");
} else if (!moveablePieces.isEmpty()) {
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new ChoosePieceStateMessage());
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
} else {

View File

@@ -41,7 +41,13 @@ public ServerCardVisitor(ServerGameLogic logic) {
*/
@Override
public void visit(TurboCard card) {
this.cards.add(card);
for (Piece piece : this.logic.getGame().getPlayerByColor(this.logic.getGame().getActiveColor()).getPieces()) {
if (piece.getState() == PieceState.ACTIVE) {
if (!this.cards.contains(card)) {
this.cards.add(card);
}
}
}
}
/**