This commit is contained in:
nora 2023-01-09 09:56:02 +01:00
parent 84750781f2
commit 193c89c25c
3 changed files with 20 additions and 3 deletions

View file

@ -136,7 +136,7 @@ public class Connect4ArenaMain {
* Givent the current {@link #board}, find a suitable position-index to play to.
* @return the position to play to as defined by {@link Connect4Player#play(int)}.
*/
abstract int play();
protected abstract int play();
}
@ -167,7 +167,7 @@ public class Connect4ArenaMain {
return sb.toString();
}
@Override
int play() {
protected int play() {
System.out.println("where to to put the next " + myColor + "?");
var scanner = new Scanner(System.in, StandardCharsets.UTF_8);
return Integer.parseInt(scanner.nextLine());
@ -178,7 +178,7 @@ public class Connect4ArenaMain {
public static class GreedyPlayer extends DefaultPlayer {
@Override
int play() {
protected int play() {
for (int c = 0; c < WIDTH; c++) {
for (int r = 0; r < HEIGHT; r++) {
var index = r * WIDTH + c;

View file

@ -0,0 +1,14 @@
package ch.bbw.m411.connect4;
public class RustPlayer extends Connect4ArenaMain.DefaultPlayer {
private native int rustPlay(byte player, Connect4ArenaMain.Stone[] board);
@Override
protected int play() {
byte player = switch (this.myColor) {
case BLUE -> 0;
case RED -> 1;
};
return this.rustPlay(player, this.board);
}
}