@@ -8,12 +8,26 @@ public class BWClientConfiguration {
88 /**
99 * Set to `true` for more explicit error messages (which might spam the terminal).
1010 */
11- public boolean debugConnection ;
11+ public BWClientConfiguration withDebugConnection (boolean value ) {
12+ debugConnection = value ;
13+ return this ;
14+ }
15+ boolean getDebugConnection () {
16+ return debugConnection ;
17+ }
18+ private boolean debugConnection ;
1219
1320 /**
1421 * When true, restarts the client loop when a game ends, allowing the client to play multiple games without restarting.
1522 */
16- public boolean autoContinue = false ;
23+ public BWClientConfiguration withAutoContinue (boolean value ) {
24+ autoContinue = value ;
25+ return this ;
26+ }
27+ boolean getAutoContinue () {
28+ return autoContinue ;
29+ }
30+ private boolean autoContinue = false ;
1731
1832 /**
1933 * Most bot tournaments allow bots to take an indefinite amount of time on frame #0 (the first frame of the game) to analyze the map and load data,
@@ -23,15 +37,29 @@ public class BWClientConfiguration {
2337 * Performance metrics omit the frame as an outlier.
2438 * Asynchronous operation will block until the bot's event handlers are complete.
2539 */
26- public boolean unlimitedFrameZero = true ;
40+ public BWClientConfiguration withUnlimitedFrameZero (boolean value ) {
41+ unlimitedFrameZero = value ;
42+ return this ;
43+ }
44+ boolean getUnlimitedFrameZero () {
45+ return unlimitedFrameZero ;
46+ }
47+ private boolean unlimitedFrameZero = true ;
2748
2849 /**
2950 * The maximum amount of time the bot is supposed to spend on a single frame.
3051 * In asynchronous mode, JBWAPI will attempt to let the bot use up to this much time to process all frames before returning control to BWAPI.
3152 * In synchronous mode, JBWAPI is not empowered to prevent the bot to exceed this amount, but will record overruns in performance metrics.
3253 * Real-time human play typically uses the "fastest" game speed, which has 42.86ms (42,860ns) between frames.
3354 */
34- public int maxFrameDurationMs = 40 ;
55+ public BWClientConfiguration withMaxFrameDurationMs (int value ) {
56+ maxFrameDurationMs = value ;
57+ return this ;
58+ }
59+ int getMaxFrameDurationMs () {
60+ return maxFrameDurationMs ;
61+ }
62+ private int maxFrameDurationMs = 40 ;
3563
3664 /**
3765 * Runs the bot in asynchronous mode. Asynchronous mode helps attempt to ensure that the bot adheres to real-time performance constraints.
@@ -44,13 +72,27 @@ public class BWClientConfiguration {
4472 * real-time performance requirements, while not fully guaranteeing it (subject to the whims of the JVM thread scheduler), at a cost of the bot possibly
4573 * issuing commands later than intended, and a marginally larger memory footprint.
4674 */
47- public boolean async = false ;
75+ public BWClientConfiguration withAsync (boolean value ) {
76+ async = value ;
77+ return this ;
78+ }
79+ boolean getAsync () {
80+ return async ;
81+ }
82+ private boolean async = false ;
4883
4984 /**
5085 * The maximum number of frames to buffer while waiting on a bot.
5186 * Each frame buffered adds about 33 megabytes to JBWAPI's memory footprint.
5287 */
53- public int asyncFrameBufferCapacity = 10 ;
88+ public BWClientConfiguration withAsyncFrameBufferCapacity (int size ) {
89+ asyncFrameBufferCapacity = size ;
90+ return this ;
91+ }
92+ int getAsyncFrameBufferCapacity () {
93+ return asyncFrameBufferCapacity ;
94+ }
95+ private int asyncFrameBufferCapacity = 10 ;
5496
5597 /**
5698 * Enables thread-unsafe async mode.
@@ -59,17 +101,34 @@ public class BWClientConfiguration {
59101 * This should enhance performance by allowing the bot to act while the frame is copied, but poses unidentified risk due to
60102 * the non-thread-safe switc from shared memory reads to frame buffer reads.
61103 */
62- public boolean asyncUnsafe = false ;
104+ public BWClientConfiguration withAsyncUnsafe (boolean value ) {
105+ asyncUnsafe = value ;
106+ return this ;
107+ }
108+ boolean getAsyncUnsafe () {
109+ return asyncUnsafe ;
110+ }
111+ private boolean asyncUnsafe = false ;
63112
64113 /**
65114 * Toggles verbose logging, particularly of synchronization steps.
66115 */
67- public boolean logVerbosely = false ;
116+ public BWClientConfiguration withLogVerbosely (boolean value ) {
117+ logVerbosely = value ;
118+ return this ;
119+ }
120+ boolean getLogVerbosely () {
121+ return logVerbosely ;
122+ }
123+ private boolean logVerbosely = false ;
68124
69125 /**
70126 * Checks that the configuration is in a valid state. Throws an IllegalArgumentException if it isn't.
71127 */
72128 void validate () {
129+ if (asyncUnsafe && ! async ) {
130+ throw new IllegalArgumentException ("asyncUnsafe mode needs async mode." );
131+ }
73132 if (async && maxFrameDurationMs < 0 ) {
74133 throw new IllegalArgumentException ("maxFrameDurationMs needs to be a non-negative number (it's how long JBWAPI waits for a bot response before returning control to BWAPI)." );
75134 }
0 commit comments