mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-14 15:25:08 +01:00
java
This commit is contained in:
parent
84750781f2
commit
193c89c25c
3 changed files with 20 additions and 3 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
minmax-java/build
|
||||
minmax-java/.gradle
|
||||
.idea
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue