start to reversi logic

This commit is contained in:
Ticho Hidding
2025-10-08 17:27:50 +02:00
parent a302f0d24d
commit 5a3490af2e
10 changed files with 265 additions and 33 deletions

View File

@@ -9,6 +9,8 @@ public abstract class Game {
public record Move(int position, char value) {}
public record Score(int player1Score, int player2Score) {}
public static final char EMPTY = (char)0;
public final int rowSize;

View File

@@ -1,19 +0,0 @@
package org.toop.game.othello;
import org.toop.game.TurnBasedGame;
public final class Othello extends TurnBasedGame {
Othello() {
super(8, 8, 2);
}
@Override
public Move[] getLegalMoves() {
return new Move[0];
}
@Override
public State play(Move move) {
return null;
}
}

View File

@@ -1,11 +0,0 @@
package org.toop.game.othello;
import org.toop.game.AI;
import org.toop.game.Game;
public final class OthelloAI extends AI<Othello> {
@Override
public Game.Move findBestMove(Othello game, int depth) {
return null;
}
}

View File

@@ -0,0 +1,74 @@
package org.toop.game.reversi;
import org.toop.game.Game;
import org.toop.game.TurnBasedGame;
import org.toop.game.tictactoe.TicTacToe;
public final class Reversi extends TurnBasedGame {
private int movesTaken;
public static final char FIRST_MOVE = 'B';
public Reversi() {
super(8, 8, 2);
addStartPieces();
}
public Reversi(Reversi other) {
super(other);
this.movesTaken = other.movesTaken;
}
private void addStartPieces() {
board[27] = 'W';
board[28] = 'B';
board[35] = 'B';
board[36] = 'W';
}
@Override
public Move[] getLegalMoves() {
char[][] boardGrid = makeBoardAGrid();
if(currentTurn == 1){
}
return new Move[0];
}
public char[][] makeBoardAGrid() {
char[][] boardGrid = new char[8][8];
for (int i = 0; i < 64; i++) {
boardGrid[i / 8][i % 8] = board[i];
}
return boardGrid;
}
@Override
public State play(Move move) {
return null;
}
public char getCurrentPlayer() {
if (currentTurn == 0){
return 'B';
}
else {
return 'W';
}
}
public Game.Score getScore(){
int player1Score = 0, player2Score = 0;
for (int count = 0; count < 63; count++) {
if (board[count] == 'W') {
player1Score += 1;
}
if (board[count] == 'B') {
player2Score += 1;
}
}
return new Game.Score(player1Score, player2Score);
}
}

View File

@@ -0,0 +1,11 @@
package org.toop.game.reversi;
import org.toop.game.AI;
import org.toop.game.Game;
public final class ReversiAI extends AI<Reversi> {
@Override
public Game.Move findBestMove(Reversi game, int depth) {
return null;
}
}