mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
(DOES NOT COMPILE) In-between commit
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package org.toop.game;
|
||||
|
||||
import org.toop.framework.gameFramework.GameState;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BitboardGame {
|
||||
public abstract class BitboardGame implements TurnBasedGame<BitboardGame> {
|
||||
private final int columnSize;
|
||||
private final int rowSize;
|
||||
|
||||
@@ -22,6 +25,34 @@ public abstract class BitboardGame {
|
||||
Arrays.fill(playerBitboard, 0L);
|
||||
}
|
||||
|
||||
protected int[] translateLegalMoves(long legalMoves){
|
||||
int[] output = new int[Long.bitCount(legalMoves)];
|
||||
int j = 0;
|
||||
for(int i = 0; i < 64; i++){
|
||||
if ((legalMoves & (1L << i)) != 0){
|
||||
output[j] = i;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
protected long translateMove(int move){
|
||||
return 1L << move;
|
||||
}
|
||||
|
||||
protected int[] translateBoard(){
|
||||
int[] output = new int[64];
|
||||
for(int i = 0; i < this.playerBitboard.length; i++){
|
||||
for (int j = 0; j < 64; j++){
|
||||
if ((this.playerBitboard[i] & (1L << j)) != 0){
|
||||
output[j] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public BitboardGame(BitboardGame other) {
|
||||
this.columnSize = other.columnSize;
|
||||
this.rowSize = other.rowSize;
|
||||
@@ -65,7 +96,4 @@ public abstract class BitboardGame {
|
||||
public void nextTurn() {
|
||||
currentTurn++;
|
||||
}
|
||||
|
||||
public abstract long getLegalMoves();
|
||||
public abstract GameState play(long move);
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package org.toop.game.reversi;
|
||||
|
||||
import org.toop.framework.gameFramework.GameState;
|
||||
import org.toop.framework.gameFramework.model.game.PlayResult;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.game.BitboardGame;
|
||||
|
||||
public class BitboardReversi extends BitboardGame {
|
||||
@Override
|
||||
public Player<BitboardGame> getPlayer(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public record Score(int black, int white) {}
|
||||
|
||||
private final long notAFile = 0xfefefefefefefefeL;
|
||||
@@ -18,8 +25,7 @@ public class BitboardReversi extends BitboardGame {
|
||||
// White (player 1)
|
||||
setPlayerBitboard(1, (1L << (3 + 3 * 8)) | (1L << (4 + 4 * 8))); }
|
||||
|
||||
@Override
|
||||
public long getLegalMoves() {
|
||||
public long getLegalMoves2() {
|
||||
final long player = getPlayerBitboard(getCurrentPlayer());
|
||||
final long opponent = getPlayerBitboard(getNextPlayer());
|
||||
|
||||
@@ -54,7 +60,20 @@ public class BitboardReversi extends BitboardGame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameState play(long move) {
|
||||
public int[] getLegalMoves(){
|
||||
return translateLegalMoves(getLegalMoves2());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayResult play(int move) {
|
||||
return new PlayResult(playBit(translateMove(move)), getCurrentPlayer());
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
@Override
|
||||
public BitboardReversi deepCopy() {return this;};
|
||||
|
||||
public GameState playBit(long move) {
|
||||
final long flips = getFlips(move);
|
||||
|
||||
long player = getPlayerBitboard(getCurrentPlayer());
|
||||
@@ -68,12 +87,12 @@ public class BitboardReversi extends BitboardGame {
|
||||
|
||||
nextTurn();
|
||||
|
||||
final long nextLegalMoves = getLegalMoves();
|
||||
final long nextLegalMoves = getLegalMoves2();
|
||||
|
||||
if (nextLegalMoves <= 0) {
|
||||
nextTurn();
|
||||
|
||||
final long skippedLegalMoves = getLegalMoves();
|
||||
final long skippedLegalMoves = getLegalMoves2();
|
||||
|
||||
if (skippedLegalMoves <= 0) {
|
||||
final long black = getPlayerBitboard(0);
|
||||
|
||||
@@ -20,7 +20,11 @@ public class BitboardTicTacToe extends BitboardGame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLegalMoves() {
|
||||
public int[] getLegalMoves(){
|
||||
return translateLegalMoves(getLegalMoves2());
|
||||
}
|
||||
|
||||
public long getLegalMoves2() {
|
||||
final long xBitboard = getPlayerBitboard(0);
|
||||
final long oBitboard = getPlayerBitboard(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user