Event bus now testable, improved UI (#284)

* turn updates

* smalle fixes aan turn updates

* better human/ai selector with bot selection and depth on TicTacToeAIR

* depth + thinktime back to AIs, along with a a specific TicTacToeAIRSleep

* fixed overlapping back and disconnect buttons

* Changed to debug instead of info

* changed the transitionNextCustom to be easier to use

* added getAllWidgets to WidgetContainer

* Correct back view

* added replacePrevious in ViewWidget

* added removeIndexFromPreviousChain

* fixed incorrect index counting

* Fixt wrong view order

* Removed todo

* Challenge popups "Fixed"

* Popups now remove themselves

* localize the ChallengePopup text

* made the game text a header instead

* fixed getAllWidgets

* Escape popup

* fixed redundant container

* Escape remove popup

* Working escape menu

* Added find functionality

* Tutorials moved to escape menu

* Escape can't be opened in mainview now

* Can now test the event bus, created testable interfaces

* Logging errors

* Made events and handlers more generic

* Suppress

* Managers now have changeable eventbus

* Tutorials fixed

* Removed import

* Single threaded eventbus

* Fixed wrong eventbus

* Removed get

* Removed old code

* Renaming

* Optimization

* Removed useless comment

* Removed unnecessary imports

* Rename

* Renaming, refactor and type safety

* Rename

* Removed import

---------

Co-authored-by: michiel301b <m.brands.3@st.hanze.nl>
Co-authored-by: ramollia <>
This commit is contained in:
Bas Antonius de Jong
2025-12-07 17:38:34 +01:00
committed by GitHub
parent f60df73b66
commit 38f50cc16d
68 changed files with 1100 additions and 538 deletions

View File

@@ -25,10 +25,10 @@ public final class ReversiR extends AbstractGame<ReversiR> {
// TODO: Don't hardcore for two players :)
public record Score(int player1Score, int player2Score) {}
public ReversiR(Player<ReversiR>[] players) {
super(8, 8, 2, players);
public ReversiR(Player<ReversiR>[] players) {
super(8, 8, 2, players);
addStartPieces();
}
}
public ReversiR(ReversiR other) {
super(other);
@@ -53,8 +53,8 @@ public final class ReversiR extends AbstractGame<ReversiR> {
}
}
@Override
public int[] getLegalMoves() {
@Override
public int[] getLegalMoves() {
final ArrayList<Integer> legalMoves = new ArrayList<>();
int[][] boardGrid = makeBoardAGrid();
int currentPlayer = this.getCurrentTurn();
@@ -67,7 +67,7 @@ public final class ReversiR extends AbstractGame<ReversiR> {
}
}
return legalMoves.stream().mapToInt(Integer::intValue).toArray();
}
}
private Set<Point> getAdjacentCells(int[][] boardGrid) {
Set<Point> possibleCells = new HashSet<>();
@@ -76,7 +76,7 @@ public final class ReversiR extends AbstractGame<ReversiR> {
for (int deltaRow = -1; deltaRow <= 1; deltaRow++){ //orthogonally and diagonally
int newX = point.x + deltaColumn, newY = point.y + deltaRow;
if (deltaColumn == 0 && deltaRow == 0 //continue if out of bounds
|| !isOnBoard(newX, newY)) {
|| !isOnBoard(newX, newY)) {
continue;
}
if (boardGrid[newY][newX] == EMPTY) { //check if the cell is empty

View File

@@ -13,7 +13,7 @@ import org.toop.framework.gameFramework.GameState;
* opening or when no clear best move is found.
* </p>
*/
public final class TicTacToeAIR extends AbstractAI<TicTacToeR> {
public class TicTacToeAIR extends AbstractAI<TicTacToeR> {
/**
* Determines the best move for the given Tic-Tac-Toe game state.
@@ -27,8 +27,14 @@ public final class TicTacToeAIR extends AbstractAI<TicTacToeR> {
* @param depth the depth of lookahead for evaluating moves (non-negative)
* @return the index of the best move, or -1 if no moves are available
*/
private int depth;
public TicTacToeAIR(int depth) {
this.depth = depth;
}
public int getMove(TicTacToeR game) {
int depth = 9;
assert game != null;
final int[] legalMoves = game.getLegalMoves();

View File

@@ -0,0 +1,25 @@
package org.toop.game.games.tictactoe;
import java.util.Random;
public class TicTacToeAIRSleep extends TicTacToeAIR {
private int thinkTime;
public TicTacToeAIRSleep(int depth, int thinkTime) {
super(depth);
this.thinkTime = thinkTime;
}
@Override
public int getMove(TicTacToeR game) {
int score = super.getMove(game);
try {
Random random = new Random();
Thread.sleep(this.thinkTime * 1000L + random.nextInt(1000));
} catch (Exception e) {
e.printStackTrace();
}
return score;
}
}

View File

@@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.*;
final class TicTacToeAIRTest {
private final TicTacToeAIR ai = new TicTacToeAIR();
private final TicTacToeAIR ai = new TicTacToeAIR(9);
// Helper: play multiple moves in sequence on a fresh board
private TicTacToeR playSequence(int... moves) {