From 97276c7e80c794ef3149245b19e7d82985428ad1 Mon Sep 17 00:00:00 2001 From: ramollia <> Date: Fri, 23 Jan 2026 19:14:46 +0100 Subject: [PATCH] readded threads argument --- .../org/toop/game/players/ai/mcts/MCTSAI3.java | 17 +++++++++++------ .../org/toop/game/players/ai/mcts/MCTSAI4.java | 17 +++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI3.java b/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI3.java index 4e582b3..a39594a 100644 --- a/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI3.java +++ b/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI3.java @@ -9,16 +9,21 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class MCTSAI3 extends MCTSAI { - private static final int THREADS = 8; + private final int threads; + private final ExecutorService threadPool; - private static final ExecutorService threadPool = Executors.newFixedThreadPool(THREADS); - - public MCTSAI3(int milliseconds) { + public MCTSAI3(int milliseconds, int threads) { super(milliseconds); + + this.threads = threads; + this.threadPool = Executors.newFixedThreadPool(threads); } public MCTSAI3(MCTSAI3 other) { super(other); + + this.threads = other.threads; + this.threadPool = other.threadPool; } @Override @@ -32,9 +37,9 @@ public class MCTSAI3 extends MCTSAI { final long endTime = System.nanoTime() + milliseconds * 1_000_000L; - final CountDownLatch latch = new CountDownLatch(THREADS); + final CountDownLatch latch = new CountDownLatch(threads); - for (int i = 0; i < THREADS; i++) { + for (int i = 0; i < threads; i++) { threadPool.submit(() -> { try { iterate(root, endTime); diff --git a/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI4.java b/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI4.java index 399dc5b..630df44 100644 --- a/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI4.java +++ b/game/src/main/java/org/toop/game/players/ai/mcts/MCTSAI4.java @@ -9,22 +9,23 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class MCTSAI4 extends MCTSAI { - private static final int THREADS = 8; - - private static final ExecutorService threadPool = Executors.newFixedThreadPool(THREADS); + private final int threads; + private final ExecutorService threadPool; private Node root; - public MCTSAI4(int milliseconds) { + public MCTSAI4(int milliseconds, int threads) { super(milliseconds); - this.root = null; + this.threads = threads; + this.threadPool = Executors.newFixedThreadPool(threads); } public MCTSAI4(MCTSAI4 other) { super(other); - this.root = other.root; + this.threads = other.threads; + this.threadPool = other.threadPool; } @Override @@ -38,9 +39,9 @@ public class MCTSAI4 extends MCTSAI { final long endTime = System.nanoTime() + milliseconds * 1_000_000L; - final CountDownLatch latch = new CountDownLatch(THREADS); + final CountDownLatch latch = new CountDownLatch(threads); - for (int i = 0; i < THREADS; i++) { + for (int i = 0; i < threads; i++) { threadPool.submit(() -> { try { iterate(root, endTime);