mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-14 15:25:08 +01:00
JAVA
This commit is contained in:
parent
b083ef958d
commit
125990e659
2 changed files with 26 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ public class Connect4ArenaMain {
|
||||||
static final int NOMOVE = -1;
|
static final int NOMOVE = -1;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new Connect4ArenaMain().play(new HumanPlayer(), new GreedyPlayer());
|
new Connect4ArenaMain().play(new RustPlayer(), new GreedyPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
static String toDebugString(Stone[] board) {
|
static String toDebugString(Stone[] board) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package ch.bbw.m411.connect4;
|
||||||
public class RustPlayer extends Connect4ArenaMain.DefaultPlayer {
|
public class RustPlayer extends Connect4ArenaMain.DefaultPlayer {
|
||||||
private static native int rustPlay(byte player, byte[] board);
|
private static native int rustPlay(byte player, byte[] board);
|
||||||
|
|
||||||
|
private static native boolean isWinning(byte player, byte[] forColor);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// This actually loads the shared object that we'll be creating.
|
// This actually loads the shared object that we'll be creating.
|
||||||
// The actual location of the .so or .dll may differ based on your
|
// The actual location of the .so or .dll may differ based on your
|
||||||
|
|
@ -10,15 +12,10 @@ public class RustPlayer extends Connect4ArenaMain.DefaultPlayer {
|
||||||
System.loadLibrary("rs_wrapper");
|
System.loadLibrary("rs_wrapper");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
static byte[] encodeBoard(Connect4ArenaMain.Stone[] board) {
|
||||||
protected int play() {
|
byte[] boardBuf = new byte[board.length];
|
||||||
byte player = switch (this.myColor) {
|
for (int i = 0; i < board.length; i++) {
|
||||||
case BLUE -> 0;
|
var stone = board[i];
|
||||||
case RED -> 1;
|
|
||||||
};
|
|
||||||
byte[] boardBuf = new byte[this.board.length];
|
|
||||||
for (int i = 0; i < this.board.length; i++) {
|
|
||||||
var stone = this.board[i];
|
|
||||||
byte value;
|
byte value;
|
||||||
if (stone == null) {
|
if (stone == null) {
|
||||||
value = 2;
|
value = 2;
|
||||||
|
|
@ -29,6 +26,25 @@ public class RustPlayer extends Connect4ArenaMain.DefaultPlayer {
|
||||||
}
|
}
|
||||||
boardBuf[i] = value;
|
boardBuf[i] = value;
|
||||||
}
|
}
|
||||||
|
return boardBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWinning(Connect4ArenaMain.Stone[] board, Connect4ArenaMain.Stone forColor) {
|
||||||
|
byte player = switch (forColor) {
|
||||||
|
case BLUE -> 0;
|
||||||
|
case RED -> 1;
|
||||||
|
};
|
||||||
|
byte[] boardBuf = RustPlayer.encodeBoard(board);
|
||||||
|
return RustPlayer.isWinning(player, boardBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int play() {
|
||||||
|
byte player = switch (this.myColor) {
|
||||||
|
case BLUE -> 0;
|
||||||
|
case RED -> 1;
|
||||||
|
};
|
||||||
|
byte[] boardBuf = RustPlayer.encodeBoard(this.board);
|
||||||
return RustPlayer.rustPlay(player, boardBuf);
|
return RustPlayer.rustPlay(player, boardBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue