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;
|
package org.toop.game;
|
||||||
|
|
||||||
import org.toop.framework.gameFramework.GameState;
|
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.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class BitboardGame {
|
public abstract class BitboardGame implements TurnBasedGame<BitboardGame> {
|
||||||
private final int columnSize;
|
private final int columnSize;
|
||||||
private final int rowSize;
|
private final int rowSize;
|
||||||
|
|
||||||
@@ -22,6 +25,34 @@ public abstract class BitboardGame {
|
|||||||
Arrays.fill(playerBitboard, 0L);
|
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) {
|
public BitboardGame(BitboardGame other) {
|
||||||
this.columnSize = other.columnSize;
|
this.columnSize = other.columnSize;
|
||||||
this.rowSize = other.rowSize;
|
this.rowSize = other.rowSize;
|
||||||
@@ -65,7 +96,4 @@ public abstract class BitboardGame {
|
|||||||
public void nextTurn() {
|
public void nextTurn() {
|
||||||
currentTurn++;
|
currentTurn++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract long getLegalMoves();
|
|
||||||
public abstract GameState play(long move);
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
package org.toop.game.reversi;
|
package org.toop.game.reversi;
|
||||||
|
|
||||||
import org.toop.framework.gameFramework.GameState;
|
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;
|
import org.toop.game.BitboardGame;
|
||||||
|
|
||||||
public class BitboardReversi extends BitboardGame {
|
public class BitboardReversi extends BitboardGame {
|
||||||
public record Score(int black, int white) {}
|
@Override
|
||||||
|
public Player<BitboardGame> getPlayer(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Score(int black, int white) {}
|
||||||
|
|
||||||
private final long notAFile = 0xfefefefefefefefeL;
|
private final long notAFile = 0xfefefefefefefefeL;
|
||||||
private final long notHFile = 0x7f7f7f7f7f7f7f7fL;
|
private final long notHFile = 0x7f7f7f7f7f7f7f7fL;
|
||||||
@@ -18,8 +25,7 @@ public class BitboardReversi extends BitboardGame {
|
|||||||
// White (player 1)
|
// White (player 1)
|
||||||
setPlayerBitboard(1, (1L << (3 + 3 * 8)) | (1L << (4 + 4 * 8))); }
|
setPlayerBitboard(1, (1L << (3 + 3 * 8)) | (1L << (4 + 4 * 8))); }
|
||||||
|
|
||||||
@Override
|
public long getLegalMoves2() {
|
||||||
public long getLegalMoves() {
|
|
||||||
final long player = getPlayerBitboard(getCurrentPlayer());
|
final long player = getPlayerBitboard(getCurrentPlayer());
|
||||||
final long opponent = getPlayerBitboard(getNextPlayer());
|
final long opponent = getPlayerBitboard(getNextPlayer());
|
||||||
|
|
||||||
@@ -53,8 +59,21 @@ public class BitboardReversi extends BitboardGame {
|
|||||||
return flips;
|
return flips;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
final long flips = getFlips(move);
|
||||||
|
|
||||||
long player = getPlayerBitboard(getCurrentPlayer());
|
long player = getPlayerBitboard(getCurrentPlayer());
|
||||||
@@ -68,12 +87,12 @@ public class BitboardReversi extends BitboardGame {
|
|||||||
|
|
||||||
nextTurn();
|
nextTurn();
|
||||||
|
|
||||||
final long nextLegalMoves = getLegalMoves();
|
final long nextLegalMoves = getLegalMoves2();
|
||||||
|
|
||||||
if (nextLegalMoves <= 0) {
|
if (nextLegalMoves <= 0) {
|
||||||
nextTurn();
|
nextTurn();
|
||||||
|
|
||||||
final long skippedLegalMoves = getLegalMoves();
|
final long skippedLegalMoves = getLegalMoves2();
|
||||||
|
|
||||||
if (skippedLegalMoves <= 0) {
|
if (skippedLegalMoves <= 0) {
|
||||||
final long black = getPlayerBitboard(0);
|
final long black = getPlayerBitboard(0);
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ public class BitboardTicTacToe extends BitboardGame {
|
|||||||
super(3, 3, 2);
|
super(3, 3, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLegalMoves() {
|
public int[] getLegalMoves(){
|
||||||
|
return translateLegalMoves(getLegalMoves2());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLegalMoves2() {
|
||||||
final long xBitboard = getPlayerBitboard(0);
|
final long xBitboard = getPlayerBitboard(0);
|
||||||
final long oBitboard = getPlayerBitboard(1);
|
final long oBitboard = getPlayerBitboard(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user