commit c08a2220ccfea3fc1b0fcd8991c8c9d78c2ad530
parent 85940005630c4ab95769fb3b688e23e28cb88f2e
Author: Friedel Schon <[email protected]>
Date: Sun, 5 Feb 2023 21:20:13 +0100
add netwerk
Diffstat:
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/src/main/java/nl/isygameclient/Tournament.java b/src/main/java/nl/isygameclient/Tournament.java
@@ -28,18 +28,22 @@ public class Tournament {
};
public static void main(String[] args) throws IOException {
+ // GameClient client = new GameClient("145.33.225.170", 7789);
GameClient client = new GameClient("localhost", 7789);
- client.login("deeznuts" + new Random().nextInt(0, 9));
+ client.login("ITV2D1" + new Random().nextInt(0, 9));
Player dummyPlayer = new Player("network", "black") {
public Vector2D<Integer, Integer> onPlayerTurn() { return null; }
};
- Player ai = new Ai("yannick", "white", HEURISTIC);
+ Player randomPlayer = new Player("network", "black") {
+ public Vector2D<Integer, Integer> onPlayerTurn() { return null; }
+ };
- PlayerManager playerManager = new PlayerManager(0, List.of(ai, dummyPlayer));
+ PlayerManager playerManager = new PlayerManager(0, List.of(randomPlayer, dummyPlayer));
Othello othello = new Othello(playerManager);
+ Random random = new Random();
String firstPlayer = null;
@@ -64,7 +68,10 @@ public class Tournament {
firstPlayer = "self";
othello.initializeBoard();
}
- var turn = ai.onPlayerTurn();
+ var turns = othello.getValidMoves(randomPlayer);
+ System.out.println(turns);
+ var turn = turns.get(random.nextInt(0, turns.size()));
+
System.out.println(turn);
client.send("move " + (turn.getY() * 8 + turn.getX()));
// othello.move(ai, turn);
@@ -80,20 +87,21 @@ public class Tournament {
var moveMap = (Map<String, String>) event.data;
int move = Integer.parseInt(moveMap.get("move"));
- System.out.printf("%s did move %dx%d\n", moveMap.get("player"), move / 8, move % 8);
- othello.move(moveMap.get("player").equals(client.getName()) ? ai : dummyPlayer, new Vector2D<>(move % 8, move / 8));
+ System.out.printf("%s did move %dx%d\n", moveMap.get("player"), move % 8, move / 8);
+ othello.move(moveMap.get("player").equals(client.getName()) ? randomPlayer : dummyPlayer, new Vector2D<>(move % 8, move / 8));
break;
case WIN:
case LOSS:
default:
+ System.out.printf("%s -> %s\n", client.getName(), event.type);
for (int y = 0; y < 8; y++) {
System.out.print("|");
for (int x = 0; x < 8; x++) {
Player p = othello.getBoard().get(new Vector2D<Integer, Integer>(x, y));
if (p == dummyPlayer) {
System.out.print("N|");
- } else if (p == ai) {
+ } else if (p == randomPlayer) {
System.out.print("A|");
} else {
System.out.print(" |");
@@ -101,7 +109,7 @@ public class Tournament {
}
System.out.println();
} // outcome = event;
- // return false;
+ // return false;
}
}
// client.close();
diff --git a/src/main/java/nl/isygameclient/models/games/othello/Othello.java b/src/main/java/nl/isygameclient/models/games/othello/Othello.java
@@ -88,13 +88,15 @@ public class Othello extends Game {
private List<Vector2D<Integer, Integer>> rangeContains(Player player, Vector2D<Integer, Integer> pos, Vector2D<Integer, Integer> dir) {
List<Vector2D<Integer, Integer>> flippable = new ArrayList<>();
- int x = pos.getX();
- int y = pos.getY();
+ int x = pos.getX() + dir.getX();
+ int y = pos.getY() + dir.getY();
while (x >= 0 && x < board.getWidth() && y >= 0 && y < board.getHeight()) {
var newPos = new Vector2D<>(x, y);
flippable.add(newPos);
if (Objects.equals(board.get(newPos), player)) {
return flippable;
+ } else if (board.get(newPos) == null) {
+ return null;
}
x += dir.getX();
y += dir.getY();
@@ -124,6 +126,9 @@ public class Othello extends Game {
}
}
}
+ if (!flippable.isEmpty()) {
+ flippable.add(pos);
+ }
return flippable;
}