From eb90e00709487b98a94caa474fa2a508c2fd065f Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Tue, 6 Aug 2019 22:24:56 +0300 Subject: [PATCH 01/13] Refactoring: anti-static --- .../java/com/leokom/chess/MainRunner.java | 5 ++-- .../java/com/leokom/chess/PlayerFactory.java | 4 +-- .../com/leokom/chess/PlayerFactoryTest.java | 26 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/leokom/chess/MainRunner.java b/src/main/java/com/leokom/chess/MainRunner.java index 85bace134..87c460d61 100644 --- a/src/main/java/com/leokom/chess/MainRunner.java +++ b/src/main/java/com/leokom/chess/MainRunner.java @@ -87,8 +87,9 @@ public static void main( String[] args ) { } private static void runGame() { - final Player whitePlayer = PlayerFactory.createPlayer( Side.WHITE ); - final Player blackPlayer = PlayerFactory.createPlayer( Side.BLACK ); + PlayerFactory factory = new PlayerFactory(); + final Player whitePlayer = factory.createPlayer( Side.WHITE ); + final Player blackPlayer = factory.createPlayer( Side.BLACK ); new Game( whitePlayer, blackPlayer ).run(); } diff --git a/src/main/java/com/leokom/chess/PlayerFactory.java b/src/main/java/com/leokom/chess/PlayerFactory.java index 744547de3..75e92a91a 100644 --- a/src/main/java/com/leokom/chess/PlayerFactory.java +++ b/src/main/java/com/leokom/chess/PlayerFactory.java @@ -17,8 +17,6 @@ * Date-time: 06.05.14 22:45 */ final class PlayerFactory { - private PlayerFactory() {} - private static Logger logger = LogManager.getLogger( PlayerFactory.class ); /** @@ -61,7 +59,7 @@ Optional getFor( Side side ) { * @param side side to create * @return new instance of a player */ - static Player createPlayer( Side side ) { + Player createPlayer( Side side ) { return new ChessSystemProperty("engine").getFor(side).map(engineName -> { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { diff --git a/src/test/java/com/leokom/chess/PlayerFactoryTest.java b/src/test/java/com/leokom/chess/PlayerFactoryTest.java index a26a5b92a..3f325a3f7 100644 --- a/src/test/java/com/leokom/chess/PlayerFactoryTest.java +++ b/src/test/java/com/leokom/chess/PlayerFactoryTest.java @@ -16,7 +16,7 @@ public class PlayerFactoryTest { @Test public void noSystemPropertiesDefaultPlayerBlack() { - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertIsLegal( player ); } @@ -24,7 +24,7 @@ public void noSystemPropertiesDefaultPlayerBlack() { public void canSelectSimpleEngineForWhite() { System.setProperty( "white.engine", "Simple" ); - final Player player = PlayerFactory.createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().createPlayer( Side.WHITE ); assertIsSimple( player ); } @@ -32,7 +32,7 @@ public void canSelectSimpleEngineForWhite() { public void failFastOnUnsupportedEngine() { System.setProperty( "white.engine", "Unsupported" ); - PlayerFactory.createPlayer( Side.WHITE ); + new PlayerFactory().createPlayer( Side.WHITE ); } private void assertIsSimple(Player player) { @@ -43,13 +43,13 @@ private void assertIsSimple(Player player) { public void canSelectWinboardForBlack() { System.setProperty( "black.engine", "Winboard" ); - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertTrue( player instanceof WinboardPlayer ); } @Test public void noSystemPropertiesDefaultPlayerWhite() { - final Player player = PlayerFactory.createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().createPlayer( Side.WHITE ); assertTrue( player instanceof WinboardPlayer ); } @@ -57,7 +57,7 @@ public void noSystemPropertiesDefaultPlayerWhite() { public void legalSelected() { System.setProperty( "black", "Legal" ); - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertIsLegal( player ); } @@ -69,7 +69,7 @@ private void assertIsLegal( Player player ) { public void legalSelectedWhite() { System.setProperty( "white.engine", "Legal" ); - final Player player = PlayerFactory.createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().createPlayer( Side.WHITE ); assertIsLegal( player ); } @@ -78,7 +78,7 @@ public void depth2FromCommandLineRespectedForWhite() { System.setProperty( "white.engine", "Legal" ); System.setProperty( "white.depth", "2" ); - final Player player = PlayerFactory.createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().createPlayer( Side.WHITE ); assertDepth( player, 2 ); } @@ -87,7 +87,7 @@ public void depth1FromCommandLineRespectedForWhite() { System.setProperty( "white.engine", "Legal" ); System.setProperty( "white.depth", "1" ); - final Player player = PlayerFactory.createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().createPlayer( Side.WHITE ); assertDepth( player, 1 ); } @@ -96,7 +96,7 @@ public void depth1FromCommandLineRespectedForBlack() { System.setProperty( "black.engine", "Legal" ); System.setProperty( "black.depth", "1" ); - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertDepth( player, 1 ); } @@ -105,7 +105,7 @@ public void depth2FromCommandLineRespectedForBlack() { System.setProperty( "black.engine", "Legal" ); System.setProperty( "black.depth", "2" ); - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertDepth( player, 2 ); } @@ -114,7 +114,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { //because legal is default one System.setProperty( "black.depth", "2" ); - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertDepth( player, 2 ); } @@ -122,7 +122,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { public void defaultDepthIs1() { System.setProperty( "black.engine", "Legal" ); - final Player player = PlayerFactory.createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().createPlayer( Side.BLACK ); assertDepth( player, 1 ); } From 2d2aa32f473e822a57f06a7e1041a00a220a963c Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Tue, 6 Aug 2019 22:27:27 +0300 Subject: [PATCH 02/13] Refactoring: use interface --- .../java/com/leokom/chess/MainRunner.java | 8 +++--- .../java/com/leokom/chess/PlayerFactory.java | 6 +++-- .../com/leokom/chess/PlayerFactoryTest.java | 26 +++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/leokom/chess/MainRunner.java b/src/main/java/com/leokom/chess/MainRunner.java index 87c460d61..ad39b018f 100644 --- a/src/main/java/com/leokom/chess/MainRunner.java +++ b/src/main/java/com/leokom/chess/MainRunner.java @@ -6,6 +6,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.function.Function; + /** * Entry point to the Chess application. */ @@ -87,9 +89,9 @@ public static void main( String[] args ) { } private static void runGame() { - PlayerFactory factory = new PlayerFactory(); - final Player whitePlayer = factory.createPlayer( Side.WHITE ); - final Player blackPlayer = factory.createPlayer( Side.BLACK ); + Function< Side, Player > factory = new PlayerFactory(); + final Player whitePlayer = factory.apply( Side.WHITE ); + final Player blackPlayer = factory.apply( Side.BLACK ); new Game( whitePlayer, blackPlayer ).run(); } diff --git a/src/main/java/com/leokom/chess/PlayerFactory.java b/src/main/java/com/leokom/chess/PlayerFactory.java index 75e92a91a..9347a3be6 100644 --- a/src/main/java/com/leokom/chess/PlayerFactory.java +++ b/src/main/java/com/leokom/chess/PlayerFactory.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger; import java.util.Optional; +import java.util.function.Function; /** * Create players for the chess game @@ -16,7 +17,7 @@ * Author: Leonid * Date-time: 06.05.14 22:45 */ -final class PlayerFactory { +final class PlayerFactory implements Function< Side, Player > { private static Logger logger = LogManager.getLogger( PlayerFactory.class ); /** @@ -59,7 +60,8 @@ Optional getFor( Side side ) { * @param side side to create * @return new instance of a player */ - Player createPlayer( Side side ) { + @Override + public Player apply( Side side ) { return new ChessSystemProperty("engine").getFor(side).map(engineName -> { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { diff --git a/src/test/java/com/leokom/chess/PlayerFactoryTest.java b/src/test/java/com/leokom/chess/PlayerFactoryTest.java index 3f325a3f7..f6eea68eb 100644 --- a/src/test/java/com/leokom/chess/PlayerFactoryTest.java +++ b/src/test/java/com/leokom/chess/PlayerFactoryTest.java @@ -16,7 +16,7 @@ public class PlayerFactoryTest { @Test public void noSystemPropertiesDefaultPlayerBlack() { - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertIsLegal( player ); } @@ -24,7 +24,7 @@ public void noSystemPropertiesDefaultPlayerBlack() { public void canSelectSimpleEngineForWhite() { System.setProperty( "white.engine", "Simple" ); - final Player player = new PlayerFactory().createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().apply( Side.WHITE ); assertIsSimple( player ); } @@ -32,7 +32,7 @@ public void canSelectSimpleEngineForWhite() { public void failFastOnUnsupportedEngine() { System.setProperty( "white.engine", "Unsupported" ); - new PlayerFactory().createPlayer( Side.WHITE ); + new PlayerFactory().apply( Side.WHITE ); } private void assertIsSimple(Player player) { @@ -43,13 +43,13 @@ private void assertIsSimple(Player player) { public void canSelectWinboardForBlack() { System.setProperty( "black.engine", "Winboard" ); - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertTrue( player instanceof WinboardPlayer ); } @Test public void noSystemPropertiesDefaultPlayerWhite() { - final Player player = new PlayerFactory().createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().apply( Side.WHITE ); assertTrue( player instanceof WinboardPlayer ); } @@ -57,7 +57,7 @@ public void noSystemPropertiesDefaultPlayerWhite() { public void legalSelected() { System.setProperty( "black", "Legal" ); - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertIsLegal( player ); } @@ -69,7 +69,7 @@ private void assertIsLegal( Player player ) { public void legalSelectedWhite() { System.setProperty( "white.engine", "Legal" ); - final Player player = new PlayerFactory().createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().apply( Side.WHITE ); assertIsLegal( player ); } @@ -78,7 +78,7 @@ public void depth2FromCommandLineRespectedForWhite() { System.setProperty( "white.engine", "Legal" ); System.setProperty( "white.depth", "2" ); - final Player player = new PlayerFactory().createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().apply( Side.WHITE ); assertDepth( player, 2 ); } @@ -87,7 +87,7 @@ public void depth1FromCommandLineRespectedForWhite() { System.setProperty( "white.engine", "Legal" ); System.setProperty( "white.depth", "1" ); - final Player player = new PlayerFactory().createPlayer( Side.WHITE ); + final Player player = new PlayerFactory().apply( Side.WHITE ); assertDepth( player, 1 ); } @@ -96,7 +96,7 @@ public void depth1FromCommandLineRespectedForBlack() { System.setProperty( "black.engine", "Legal" ); System.setProperty( "black.depth", "1" ); - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertDepth( player, 1 ); } @@ -105,7 +105,7 @@ public void depth2FromCommandLineRespectedForBlack() { System.setProperty( "black.engine", "Legal" ); System.setProperty( "black.depth", "2" ); - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertDepth( player, 2 ); } @@ -114,7 +114,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { //because legal is default one System.setProperty( "black.depth", "2" ); - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertDepth( player, 2 ); } @@ -122,7 +122,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { public void defaultDepthIs1() { System.setProperty( "black.engine", "Legal" ); - final Player player = new PlayerFactory().createPlayer( Side.BLACK ); + final Player player = new PlayerFactory().apply( Side.BLACK ); assertDepth( player, 1 ); } From 76a59c6825cfd41aee75b3799fd96b57b73ea88f Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Tue, 6 Aug 2019 22:39:26 +0300 Subject: [PATCH 03/13] Refactoring: renaming, package moving, encapsulation --- src/main/java/com/leokom/chess/Game.java | 9 ++++++ .../java/com/leokom/chess/MainRunner.java | 19 ++++-------- .../CommandLinePlayers.java} | 10 +++---- .../leokom/chess/players/package-info.java | 5 ++++ .../CommandLinePlayersTest.java} | 30 +++++++++---------- 5 files changed, 39 insertions(+), 34 deletions(-) rename src/main/java/com/leokom/chess/{PlayerFactory.java => players/CommandLinePlayers.java} (89%) create mode 100644 src/main/java/com/leokom/chess/players/package-info.java rename src/test/java/com/leokom/chess/{PlayerFactoryTest.java => players/CommandLinePlayersTest.java} (74%) diff --git a/src/main/java/com/leokom/chess/Game.java b/src/main/java/com/leokom/chess/Game.java index dbb6ef21e..56ca0e68c 100644 --- a/src/main/java/com/leokom/chess/Game.java +++ b/src/main/java/com/leokom/chess/Game.java @@ -5,6 +5,8 @@ import com.leokom.chess.player.Player; import org.apache.logging.log4j.LogManager; +import java.util.function.Function; + /** * Create & Run Game of Chess. * Author: Leonid @@ -14,6 +16,13 @@ public final class Game { private final Player whitePlayer; private final Player blackPlayer; + Game( Function< Side, Player > players ) { + this( + players.apply( Side.WHITE ), + players.apply( Side.BLACK ) + ); + } + /** * Initiate game between two players * @param whitePlayer white player diff --git a/src/main/java/com/leokom/chess/MainRunner.java b/src/main/java/com/leokom/chess/MainRunner.java index ad39b018f..5db90c865 100644 --- a/src/main/java/com/leokom/chess/MainRunner.java +++ b/src/main/java/com/leokom/chess/MainRunner.java @@ -1,13 +1,10 @@ package com.leokom.chess; -import com.leokom.chess.engine.Side; -import com.leokom.chess.player.Player; +import com.leokom.chess.players.CommandLinePlayers; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.function.Function; - /** * Entry point to the Chess application. */ @@ -72,8 +69,10 @@ private MainRunner() { public static void main( String[] args ) { try { logger.info( "Starting the chess..." ); - runGame(); - logger.info( "Chess are stopped. Bye-bye" ); + new Game( + new CommandLinePlayers() + ).run(); + logger.info( "Chess are stopped. Bye-bye" ); } catch ( RuntimeException re ) { //important to investigate issues @@ -88,13 +87,5 @@ public static void main( String[] args ) { } - private static void runGame() { - Function< Side, Player > factory = new PlayerFactory(); - final Player whitePlayer = factory.apply( Side.WHITE ); - final Player blackPlayer = factory.apply( Side.BLACK ); - - new Game( whitePlayer, blackPlayer ).run(); - } - } diff --git a/src/main/java/com/leokom/chess/PlayerFactory.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java similarity index 89% rename from src/main/java/com/leokom/chess/PlayerFactory.java rename to src/main/java/com/leokom/chess/players/CommandLinePlayers.java index 9347a3be6..ff8352d50 100644 --- a/src/main/java/com/leokom/chess/PlayerFactory.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -1,4 +1,4 @@ -package com.leokom.chess; +package com.leokom.chess.players; import com.leokom.chess.engine.Side; import com.leokom.chess.player.Player; @@ -12,19 +12,19 @@ import java.util.function.Function; /** - * Create players for the chess game + * Create players for the chess game based on command-line parameters * * Author: Leonid * Date-time: 06.05.14 22:45 */ -final class PlayerFactory implements Function< Side, Player > { - private static Logger logger = LogManager.getLogger( PlayerFactory.class ); +public final class CommandLinePlayers implements Function< Side, Player > { + private static Logger logger = LogManager.getLogger( CommandLinePlayers.class ); /** * Chess system properties. * Represent properties in format 'side.property' (like 'white.depth' or 'black.engine') */ - static class ChessSystemProperty { + private static class ChessSystemProperty { private final String propertyName; ChessSystemProperty( String propertyName ) { diff --git a/src/main/java/com/leokom/chess/players/package-info.java b/src/main/java/com/leokom/chess/players/package-info.java new file mode 100644 index 000000000..e2a8e0f3b --- /dev/null +++ b/src/main/java/com/leokom/chess/players/package-info.java @@ -0,0 +1,5 @@ +/** + * Provide players for the Chess game. + * The goal of this package is to decide who will play chess in the current game + */ +package com.leokom.chess.players; \ No newline at end of file diff --git a/src/test/java/com/leokom/chess/PlayerFactoryTest.java b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java similarity index 74% rename from src/test/java/com/leokom/chess/PlayerFactoryTest.java rename to src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java index f6eea68eb..75511e87a 100644 --- a/src/test/java/com/leokom/chess/PlayerFactoryTest.java +++ b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java @@ -1,4 +1,4 @@ -package com.leokom.chess; +package com.leokom.chess.players; import com.leokom.chess.engine.Side; import com.leokom.chess.player.Player; @@ -9,14 +9,14 @@ import static org.junit.Assert.*; -public class PlayerFactoryTest { +public class CommandLinePlayersTest { //snapshots all system properties before a test, restores after it @Rule public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); @Test public void noSystemPropertiesDefaultPlayerBlack() { - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertIsLegal( player ); } @@ -24,7 +24,7 @@ public void noSystemPropertiesDefaultPlayerBlack() { public void canSelectSimpleEngineForWhite() { System.setProperty( "white.engine", "Simple" ); - final Player player = new PlayerFactory().apply( Side.WHITE ); + final Player player = new CommandLinePlayers().apply( Side.WHITE ); assertIsSimple( player ); } @@ -32,7 +32,7 @@ public void canSelectSimpleEngineForWhite() { public void failFastOnUnsupportedEngine() { System.setProperty( "white.engine", "Unsupported" ); - new PlayerFactory().apply( Side.WHITE ); + new CommandLinePlayers().apply( Side.WHITE ); } private void assertIsSimple(Player player) { @@ -43,13 +43,13 @@ private void assertIsSimple(Player player) { public void canSelectWinboardForBlack() { System.setProperty( "black.engine", "Winboard" ); - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertTrue( player instanceof WinboardPlayer ); } @Test public void noSystemPropertiesDefaultPlayerWhite() { - final Player player = new PlayerFactory().apply( Side.WHITE ); + final Player player = new CommandLinePlayers().apply( Side.WHITE ); assertTrue( player instanceof WinboardPlayer ); } @@ -57,7 +57,7 @@ public void noSystemPropertiesDefaultPlayerWhite() { public void legalSelected() { System.setProperty( "black", "Legal" ); - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertIsLegal( player ); } @@ -69,7 +69,7 @@ private void assertIsLegal( Player player ) { public void legalSelectedWhite() { System.setProperty( "white.engine", "Legal" ); - final Player player = new PlayerFactory().apply( Side.WHITE ); + final Player player = new CommandLinePlayers().apply( Side.WHITE ); assertIsLegal( player ); } @@ -78,7 +78,7 @@ public void depth2FromCommandLineRespectedForWhite() { System.setProperty( "white.engine", "Legal" ); System.setProperty( "white.depth", "2" ); - final Player player = new PlayerFactory().apply( Side.WHITE ); + final Player player = new CommandLinePlayers().apply( Side.WHITE ); assertDepth( player, 2 ); } @@ -87,7 +87,7 @@ public void depth1FromCommandLineRespectedForWhite() { System.setProperty( "white.engine", "Legal" ); System.setProperty( "white.depth", "1" ); - final Player player = new PlayerFactory().apply( Side.WHITE ); + final Player player = new CommandLinePlayers().apply( Side.WHITE ); assertDepth( player, 1 ); } @@ -96,7 +96,7 @@ public void depth1FromCommandLineRespectedForBlack() { System.setProperty( "black.engine", "Legal" ); System.setProperty( "black.depth", "1" ); - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertDepth( player, 1 ); } @@ -105,7 +105,7 @@ public void depth2FromCommandLineRespectedForBlack() { System.setProperty( "black.engine", "Legal" ); System.setProperty( "black.depth", "2" ); - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertDepth( player, 2 ); } @@ -114,7 +114,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { //because legal is default one System.setProperty( "black.depth", "2" ); - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertDepth( player, 2 ); } @@ -122,7 +122,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { public void defaultDepthIs1() { System.setProperty( "black.engine", "Legal" ); - final Player player = new PlayerFactory().apply( Side.BLACK ); + final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertDepth( player, 1 ); } From 4bca68ae5c85f23441c0405d1796c0dffc703dda Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Tue, 6 Aug 2019 22:42:44 +0300 Subject: [PATCH 04/13] Refactoring: create properties in constructor --- .../leokom/chess/players/CommandLinePlayers.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index ff8352d50..302f4a321 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -20,6 +20,14 @@ public final class CommandLinePlayers implements Function< Side, Player > { private static Logger logger = LogManager.getLogger( CommandLinePlayers.class ); + private final ChessSystemProperty engineProperty; + private final ChessSystemProperty depthProperty; + + CommandLinePlayers() { + this.engineProperty = new ChessSystemProperty( "engine" ); + this.depthProperty = new ChessSystemProperty( "depth" ); + } + /** * Chess system properties. * Represent properties in format 'side.property' (like 'white.depth' or 'black.engine') @@ -62,7 +70,7 @@ Optional getFor( Side side ) { */ @Override public Player apply( Side side ) { - return new ChessSystemProperty("engine").getFor(side).map(engineName -> { + return engineProperty.getFor(side).map(engineName -> { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { case "Legal": @@ -80,8 +88,8 @@ public Player apply( Side side ) { }).get(); } - private static LegalPlayerSupplier getLegalPlayerSupplier( Side side ) { - return new ChessSystemProperty("depth").getFor(side) + private LegalPlayerSupplier getLegalPlayerSupplier( Side side ) { + return depthProperty.getFor(side) .map(Integer::valueOf) .map(LegalPlayerSupplier::new) //takes depth parameter .orElseGet(LegalPlayerSupplier::new); //without parameters, default constructor From 451120be8c7f811292fb0f2767b4d701a7affde6 Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Tue, 6 Aug 2019 22:43:50 +0300 Subject: [PATCH 05/13] Fixed visibility --- src/main/java/com/leokom/chess/players/CommandLinePlayers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index 302f4a321..df9c74b48 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -23,7 +23,7 @@ public final class CommandLinePlayers implements Function< Side, Player > { private final ChessSystemProperty engineProperty; private final ChessSystemProperty depthProperty; - CommandLinePlayers() { + public CommandLinePlayers() { this.engineProperty = new ChessSystemProperty( "engine" ); this.depthProperty = new ChessSystemProperty( "depth" ); } From 04bcb3a6295c67922aa749087279315218b55ebd Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 21:15:31 +0300 Subject: [PATCH 06/13] Support brain.denormalized command line parameter. It will create Legal Player with Denormalized brain --- .../denormalized/DenormalizedPlayerSupplier.java | 13 +++++++++++++ .../leokom/chess/players/CommandLinePlayers.java | 3 +++ .../chess/players/CommandLinePlayersTest.java | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java diff --git a/src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java b/src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java new file mode 100644 index 000000000..ebfba54d5 --- /dev/null +++ b/src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java @@ -0,0 +1,13 @@ +package com.leokom.chess.player.legal.brain.denormalized; + +import com.leokom.chess.player.Player; +import com.leokom.chess.player.legal.LegalPlayer; + +import java.util.function.Supplier; + +public class DenormalizedPlayerSupplier implements Supplier { + @Override + public Player get() { + return new LegalPlayer( new DenormalizedBrain() ); + } +} diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index df9c74b48..ddd97f89c 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -3,6 +3,7 @@ import com.leokom.chess.engine.Side; import com.leokom.chess.player.Player; import com.leokom.chess.player.legal.LegalPlayerSupplier; +import com.leokom.chess.player.legal.brain.denormalized.DenormalizedPlayerSupplier; import com.leokom.chess.player.legal.brain.simple.SimplePlayerSupplier; import com.leokom.chess.player.winboard.WinboardPlayerSupplier; import org.apache.logging.log4j.LogManager; @@ -75,6 +76,8 @@ public Player apply( Side side ) { switch (engineName) { case "Legal": return getLegalPlayerSupplier( side ); + case "brain.denormalized": + return new DenormalizedPlayerSupplier(); case "Simple": return new SimplePlayerSupplier(); case "Winboard": diff --git a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java index 75511e87a..d518582ac 100644 --- a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java +++ b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java @@ -28,6 +28,14 @@ public void canSelectSimpleEngineForWhite() { assertIsSimple( player ); } + @Test + public void canSelectDenormalizedBrainForWhite() { + System.setProperty( "white.engine", "brain.denormalized" ); + + final Player player = new CommandLinePlayers().apply( Side.WHITE ); + assertThat( player.name(), CoreMatchers.containsString( "Denormalized" ) ); + } + @Test( expected = IllegalArgumentException.class ) public void failFastOnUnsupportedEngine() { System.setProperty( "white.engine", "Unsupported" ); From 8cda7076b7a8dd2c8191daf23071b7aa5f59d818 Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 21:50:12 +0300 Subject: [PATCH 07/13] Updated comments for new possibilities --- src/main/bat/runTwoEngines.bat | 70 ++++++++++--------- src/main/bat/variables.bat | 42 +++++------ .../java/com/leokom/chess/MainRunner.java | 3 +- .../chess/players/CommandLinePlayers.java | 2 +- .../chess/players/CommandLinePlayersTest.java | 4 +- 5 files changed, 62 insertions(+), 59 deletions(-) diff --git a/src/main/bat/runTwoEngines.bat b/src/main/bat/runTwoEngines.bat index 42e6793c6..9d6ee4371 100644 --- a/src/main/bat/runTwoEngines.bat +++ b/src/main/bat/runTwoEngines.bat @@ -1,34 +1,36 @@ -@rem ======================================================= -@rem Runs 2-engine match between Chess deployed to /LeokomChess and /LeokomChessTest -@rem Pre-requisites: -@rem variables.bat contains correct configuration -@rem ======================================================= - -%~d0 -cd %~p0 - -call variables.bat -SET RUNNABLE_JAR_DIRECTORY_2=%WINBOARD_INSTALLATION_PATH%\LeokomChessTest -SET RUN_JAR_PATH_2=%RUNNABLE_JAR_DIRECTORY_2%\Chess.jar - -@rem you may specify -Dblack.engine=Simple (or -Dblack=Simple if the second instance is Chess <= 0.3) -@rem for LegalPlayer you may specify -Dblack.depth=2 (if the second instance is Chess >= 0.4) -SET RUN_OPTIONS_2= -SET ENGINE_2=%JAVA_PATH% %RUN_OPTIONS_2% -jar %RUN_JAR_PATH_2% - -SET MATCHES_COUNT=1 - -@rem to turn on debug mode add -debug -@rem it will create winboard debug log - -@rem -mg means match game -@rem -testClaims disabled claims test in order to allow draw claim manually from the engine without adjudication -%WINBOARD_PATH% ^ --debug ^ --reuseFirst false ^ --mg %MATCHES_COUNT% ^ --fcp "%ENGINE%" ^ --fd "%RUNNABLE_JAR_DIRECTORY%" ^ --scp "%ENGINE_2%" ^ --sd "%RUNNABLE_JAR_DIRECTORY_2%" ^ --testClaims false +@rem ======================================================= +@rem Runs 2-engine match between Chess deployed to /LeokomChess and /LeokomChessTest +@rem Pre-requisites: +@rem variables.bat contains correct configuration +@rem ======================================================= + +%~d0 +cd %~p0 + +call variables.bat +SET RUNNABLE_JAR_DIRECTORY_2=%WINBOARD_INSTALLATION_PATH%\LeokomChessTest +SET RUN_JAR_PATH_2=%RUNNABLE_JAR_DIRECTORY_2%\Chess.jar + +@rem you may specify -Dblack.engine=brain.simple or brain.denormalized for Chess 0.5+ +@rem you may specify -Dblack.engine=Simple for Chess 0.4 +@rem you may specify -Dblack=Simple for Chess <= 0.3 +@rem for LegalPlayer you may specify -Dblack.depth=2 (if the second instance is Chess >= 0.4) +SET RUN_OPTIONS_2= +SET ENGINE_2=%JAVA_PATH% %RUN_OPTIONS_2% -jar %RUN_JAR_PATH_2% + +SET MATCHES_COUNT=1 + +@rem to turn on debug mode add -debug +@rem it will create winboard debug log + +@rem -mg means match game +@rem -testClaims disabled claims test in order to allow draw claim manually from the engine without adjudication +%WINBOARD_PATH% ^ +-debug ^ +-reuseFirst false ^ +-mg %MATCHES_COUNT% ^ +-fcp "%ENGINE%" ^ +-fd "%RUNNABLE_JAR_DIRECTORY%" ^ +-scp "%ENGINE_2%" ^ +-sd "%RUNNABLE_JAR_DIRECTORY_2%" ^ +-testClaims false diff --git a/src/main/bat/variables.bat b/src/main/bat/variables.bat index 2d64e3872..b21f58596 100644 --- a/src/main/bat/variables.bat +++ b/src/main/bat/variables.bat @@ -1,22 +1,22 @@ -@rem ======================================================= -@rem Tunes common settings: -@rem * Winboard location -@rem * Java executable location -@rem * All derivatives and default engine settings -@rem ======================================================= - -@rem the variables should be tuned per target environment -SET WINBOARD_INSTALLATION_PATH=E:\Games\WinBoard-4.8.0 -SET JAVA_PATH=Q:\Program Files\Java\jdk1.8.0_162\bin\java.exe - -@rem UI that we use to run our Chess with -SET WINBOARD_PATH=%WINBOARD_INSTALLATION_PATH%\WinBoard\winboard.exe -@rem I use the Winboard installation as a Chess deployment target -@rem it should be equal to 'project.deployDirectory' property in pom.xml -SET RUNNABLE_JAR_DIRECTORY=%WINBOARD_INSTALLATION_PATH%\LeokomChess -SET RUN_JAR_PATH=%RUNNABLE_JAR_DIRECTORY%\Chess.jar -@rem you may pass -Dblack.engine=Simple to choose a different engine for blacks -@rem for LegalPlayer you may specify -Dblack.depth (1 or 2) -SET RUN_OPTIONS=-Dblack.depth=2 - +@rem ======================================================= +@rem Tunes common settings: +@rem * Winboard location +@rem * Java executable location +@rem * All derivatives and default engine settings +@rem ======================================================= + +@rem the variables should be tuned per target environment +SET WINBOARD_INSTALLATION_PATH=E:\Games\WinBoard-4.8.0 +SET JAVA_PATH=Q:\Program Files\Java\jdk1.8.0_162\bin\java.exe + +@rem UI that we use to run our Chess with +SET WINBOARD_PATH=%WINBOARD_INSTALLATION_PATH%\WinBoard\winboard.exe +@rem I use the Winboard installation as a Chess deployment target +@rem it should be equal to 'project.deployDirectory' property in pom.xml +SET RUNNABLE_JAR_DIRECTORY=%WINBOARD_INSTALLATION_PATH%\LeokomChess +SET RUN_JAR_PATH=%RUNNABLE_JAR_DIRECTORY%\Chess.jar +@rem you may pass -Dblack.engine=brain.simple or brain.denormalized to choose a different engine for blacks +@rem for LegalPlayer you may specify -Dblack.depth (1 or 2) +SET RUN_OPTIONS=-Dblack.depth=2 + SET ENGINE=%JAVA_PATH% %RUN_OPTIONS% -jar %RUN_JAR_PATH% \ No newline at end of file diff --git a/src/main/java/com/leokom/chess/MainRunner.java b/src/main/java/com/leokom/chess/MainRunner.java index 5db90c865..40938909b 100644 --- a/src/main/java/com/leokom/chess/MainRunner.java +++ b/src/main/java/com/leokom/chess/MainRunner.java @@ -30,7 +30,8 @@ private MainRunner() { * engineName could be any of: *
    *
  • Winboard
  • - *
  • Simple
  • + *
  • brain.simple
  • + *
  • brain.denormalized
  • *
  • Legal
  • *
* diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index ddd97f89c..a0c65e11a 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -78,7 +78,7 @@ public Player apply( Side side ) { return getLegalPlayerSupplier( side ); case "brain.denormalized": return new DenormalizedPlayerSupplier(); - case "Simple": + case "brain.simple": return new SimplePlayerSupplier(); case "Winboard": return new WinboardPlayerSupplier(); diff --git a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java index d518582ac..02c50ddb9 100644 --- a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java +++ b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java @@ -21,8 +21,8 @@ public void noSystemPropertiesDefaultPlayerBlack() { } @Test - public void canSelectSimpleEngineForWhite() { - System.setProperty( "white.engine", "Simple" ); + public void canSelectSimpleBrainForWhite() { + System.setProperty( "white.engine", "brain.simple" ); final Player player = new CommandLinePlayers().apply( Side.WHITE ); assertIsSimple( player ); From 4e89aa0962cea2cdd28c7c6ce346ca8ad939096a Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 21:54:41 +0300 Subject: [PATCH 08/13] Normalized brain: common convention of usage. --- .../chess/players/CommandLinePlayers.java | 2 +- .../chess/players/CommandLinePlayersTest.java | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index a0c65e11a..b3047e121 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -74,7 +74,7 @@ public Player apply( Side side ) { return engineProperty.getFor(side).map(engineName -> { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { - case "Legal": + case "brain.normalized": return getLegalPlayerSupplier( side ); case "brain.denormalized": return new DenormalizedPlayerSupplier(); diff --git a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java index 02c50ddb9..7556e154e 100644 --- a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java +++ b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java @@ -17,7 +17,7 @@ public class CommandLinePlayersTest { @Test public void noSystemPropertiesDefaultPlayerBlack() { final Player player = new CommandLinePlayers().apply( Side.BLACK ); - assertIsLegal( player ); + assertHasNormalizedBrain( player ); } @Test @@ -62,28 +62,28 @@ public void noSystemPropertiesDefaultPlayerWhite() { } @Test - public void legalSelected() { - System.setProperty( "black", "Legal" ); + public void normalizedSelectedBlack() { + System.setProperty( "black.engine", "brain.normalized" ); final Player player = new CommandLinePlayers().apply( Side.BLACK ); - assertIsLegal( player ); + assertHasNormalizedBrain( player ); } - private void assertIsLegal( Player player ) { - assertThat( player.name(), CoreMatchers.startsWith( "LegalPlayer" ) ); + private void assertHasNormalizedBrain(Player player ) { + assertThat( player.name(), CoreMatchers.startsWith( "LegalPlayer : NormalizedBrain" ) ); } @Test - public void legalSelectedWhite() { - System.setProperty( "white.engine", "Legal" ); + public void normalizedSelectedWhite() { + System.setProperty( "white.engine", "brain.normalized" ); final Player player = new CommandLinePlayers().apply( Side.WHITE ); - assertIsLegal( player ); + assertHasNormalizedBrain( player ); } @Test public void depth2FromCommandLineRespectedForWhite() { - System.setProperty( "white.engine", "Legal" ); + System.setProperty( "white.engine", "brain.normalized" ); System.setProperty( "white.depth", "2" ); final Player player = new CommandLinePlayers().apply( Side.WHITE ); @@ -92,7 +92,7 @@ public void depth2FromCommandLineRespectedForWhite() { @Test public void depth1FromCommandLineRespectedForWhite() { - System.setProperty( "white.engine", "Legal" ); + System.setProperty( "white.engine", "brain.normalized" ); System.setProperty( "white.depth", "1" ); final Player player = new CommandLinePlayers().apply( Side.WHITE ); @@ -101,7 +101,7 @@ public void depth1FromCommandLineRespectedForWhite() { @Test public void depth1FromCommandLineRespectedForBlack() { - System.setProperty( "black.engine", "Legal" ); + System.setProperty( "black.engine", "brain.normalized" ); System.setProperty( "black.depth", "1" ); final Player player = new CommandLinePlayers().apply( Side.BLACK ); @@ -110,7 +110,7 @@ public void depth1FromCommandLineRespectedForBlack() { @Test public void depth2FromCommandLineRespectedForBlack() { - System.setProperty( "black.engine", "Legal" ); + System.setProperty( "black.engine", "brain.normalized" ); System.setProperty( "black.depth", "2" ); final Player player = new CommandLinePlayers().apply( Side.BLACK ); @@ -118,8 +118,8 @@ public void depth2FromCommandLineRespectedForBlack() { } @Test - public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { - //because legal is default one + public void normalizedBrainDepthCanBeProvidedEvenIfEngineIsNotProvided() { + //because normalized is default one System.setProperty( "black.depth", "2" ); final Player player = new CommandLinePlayers().apply( Side.BLACK ); @@ -128,7 +128,7 @@ public void legalPlayerDepthCanBeProvidedEvenIfEngineIsNotProvided() { @Test public void defaultDepthIs1() { - System.setProperty( "black.engine", "Legal" ); + System.setProperty( "black.engine", "brain.normalized" ); final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertDepth( player, 1 ); From ad2fa28c98ac58cb114759af3ea96825b76d4cac Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 21:58:12 +0300 Subject: [PATCH 09/13] Refactoring: updated references to 'brain.normalized' --- src/main/bat/runTwoEngines.bat | 2 +- src/main/bat/variables.bat | 2 +- src/main/java/com/leokom/chess/MainRunner.java | 6 +++--- .../com/leokom/chess/players/CommandLinePlayers.java | 9 +++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/bat/runTwoEngines.bat b/src/main/bat/runTwoEngines.bat index 9d6ee4371..ee11f58e0 100644 --- a/src/main/bat/runTwoEngines.bat +++ b/src/main/bat/runTwoEngines.bat @@ -14,7 +14,7 @@ SET RUN_JAR_PATH_2=%RUNNABLE_JAR_DIRECTORY_2%\Chess.jar @rem you may specify -Dblack.engine=brain.simple or brain.denormalized for Chess 0.5+ @rem you may specify -Dblack.engine=Simple for Chess 0.4 @rem you may specify -Dblack=Simple for Chess <= 0.3 -@rem for LegalPlayer you may specify -Dblack.depth=2 (if the second instance is Chess >= 0.4) +@rem for brain.normalized you may specify -Dblack.depth=2 (if the second instance is Chess >= 0.4) SET RUN_OPTIONS_2= SET ENGINE_2=%JAVA_PATH% %RUN_OPTIONS_2% -jar %RUN_JAR_PATH_2% diff --git a/src/main/bat/variables.bat b/src/main/bat/variables.bat index b21f58596..a9434e9f5 100644 --- a/src/main/bat/variables.bat +++ b/src/main/bat/variables.bat @@ -16,7 +16,7 @@ SET WINBOARD_PATH=%WINBOARD_INSTALLATION_PATH%\WinBoard\winboard.exe SET RUNNABLE_JAR_DIRECTORY=%WINBOARD_INSTALLATION_PATH%\LeokomChess SET RUN_JAR_PATH=%RUNNABLE_JAR_DIRECTORY%\Chess.jar @rem you may pass -Dblack.engine=brain.simple or brain.denormalized to choose a different engine for blacks -@rem for LegalPlayer you may specify -Dblack.depth (1 or 2) +@rem for brain.normalized you may specify -Dblack.depth (1 or 2) SET RUN_OPTIONS=-Dblack.depth=2 SET ENGINE=%JAVA_PATH% %RUN_OPTIONS% -jar %RUN_JAR_PATH% \ No newline at end of file diff --git a/src/main/java/com/leokom/chess/MainRunner.java b/src/main/java/com/leokom/chess/MainRunner.java index 40938909b..cca277f3c 100644 --- a/src/main/java/com/leokom/chess/MainRunner.java +++ b/src/main/java/com/leokom/chess/MainRunner.java @@ -32,18 +32,18 @@ private MainRunner() { *
  • Winboard
  • *
  • brain.simple
  • *
  • brain.denormalized
  • - *
  • Legal
  • + *
  • brain.normalized
  • * * * Default players: *
      *
    • -Dwhite.engine=Winboard
    • - *
    • -Dblack.engine=Legal
    • + *
    • -Dblack.engine=brain.normalized
    • *
    * *

    * - * Optional parameters for LegalPlayer + * Optional parameters for brain.normalized *

      *
    • -Dwhite.depth=depth in plies
    • *
    • -Dblack.depth=depth in plies
    • diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index b3047e121..93964deca 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -54,17 +54,18 @@ Optional getFor( Side side ) { * Basing on defaults or system properties. * Defaults : * WHITE: Winboard - * BLACK: Legal + * BLACK: brain.normalized * * There are practical important limitations (not yet validated): * * Winboard vs Winboard game has no practical use (both will work with System.out) * Winboard vs any other engine that uses System.out has no practical use (UCI?) * - * LegalPlayer vs LegalPlayer is possible but can lead to StackOverflow due to - * no limits on move amount and single-threaded model of execution. + * brain.* vs brain.* is possible but can lead to StackOverflow due to + * no limits on move amount and single-threaded model of execution + * (although some brains like brain.simple have internal limit on count of moves). * - * LegalPlayer supports optional depth parameter. + * brain.normalized supports optional depth parameter. * * @param side side to create * @return new instance of a player From 607df16dcd6cca8e3816107bc3297aca916c5e3d Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 22:09:02 +0300 Subject: [PATCH 10/13] Refactoring: reduced duplication over player creation. --- .../chess/players/CommandLinePlayers.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index 93964deca..cec993466 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -11,6 +11,7 @@ import java.util.Optional; import java.util.function.Function; +import java.util.function.Supplier; /** * Create players for the chess game based on command-line parameters @@ -72,24 +73,28 @@ Optional getFor( Side side ) { */ @Override public Player apply( Side side ) { - return engineProperty.getFor(side).map(engineName -> { - logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); - switch (engineName) { - case "brain.normalized": - return getLegalPlayerSupplier( side ); - case "brain.denormalized": - return new DenormalizedPlayerSupplier(); - case "brain.simple": - return new SimplePlayerSupplier(); - case "Winboard": - return new WinboardPlayerSupplier(); - default: - throw new IllegalArgumentException( "The engine is not supported: " + engineName); - } - }).orElseGet(() -> { + String engineName = engineProperty.getFor( side ).orElseGet( () -> { logger.info( "Selecting a default engine for Side = " + side ); - return side == Side.WHITE ? new WinboardPlayerSupplier() : getLegalPlayerSupplier( side ); - }).get(); + return side == Side.WHITE ? "Winboard" : "brain.normalized"; + } ); + + return getPlayerSupplier( side, engineName ).get(); + } + + private Supplier getPlayerSupplier( Side side, String engineName ) { + logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); + switch (engineName) { + case "brain.normalized": + return getLegalPlayerSupplier( side ); + case "brain.denormalized": + return new DenormalizedPlayerSupplier(); + case "brain.simple": + return new SimplePlayerSupplier(); + case "Winboard": + return new WinboardPlayerSupplier(); + default: + throw new IllegalArgumentException( "The engine is not supported: " + engineName); + } } private LegalPlayerSupplier getLegalPlayerSupplier( Side side ) { From 962fdd2a30d54ea1e49a6ad98a363a40b04e1324 Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 22:20:22 +0300 Subject: [PATCH 11/13] Refactoring: remove brain suppliers (except the normalized one) --- .../player/legal/LegalPlayerSupplier.java | 25 ---------------- .../DenormalizedPlayerSupplier.java | 13 -------- .../normalized/NormalizedBrainSupplier.java | 30 +++++++++++++++++++ .../brain/simple/SimplePlayerSupplier.java | 14 --------- .../chess/players/CommandLinePlayers.java | 19 ++++++------ .../java/com/leokom/chess/SimulatorIT.java | 9 +++--- .../player/legal/LegalPlayerNameTest.java | 4 +-- .../legal/brain/simple/SimpleBrainTest.java | 3 +- 8 files changed, 48 insertions(+), 69 deletions(-) delete mode 100644 src/main/java/com/leokom/chess/player/legal/LegalPlayerSupplier.java delete mode 100644 src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java create mode 100644 src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java delete mode 100644 src/main/java/com/leokom/chess/player/legal/brain/simple/SimplePlayerSupplier.java diff --git a/src/main/java/com/leokom/chess/player/legal/LegalPlayerSupplier.java b/src/main/java/com/leokom/chess/player/legal/LegalPlayerSupplier.java deleted file mode 100644 index 5e44dcce3..000000000 --- a/src/main/java/com/leokom/chess/player/legal/LegalPlayerSupplier.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.leokom.chess.player.legal; - -import com.leokom.chess.player.Player; -import com.leokom.chess.player.legal.brain.normalized.MasterEvaluator; -import com.leokom.chess.player.legal.brain.normalized.NormalizedBrain; - -import java.util.function.Supplier; - -public class LegalPlayerSupplier implements Supplier { - //this depth has been used for years - private static final int DEFAULT_DEPTH = 1; - private final int depth; - - public LegalPlayerSupplier() { - this(DEFAULT_DEPTH); - } - - public LegalPlayerSupplier( int depth ) { - this.depth = depth; - } - - public Player get() { - return new LegalPlayer( new NormalizedBrain<>( new MasterEvaluator(), depth ) ); - } -} diff --git a/src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java b/src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java deleted file mode 100644 index ebfba54d5..000000000 --- a/src/main/java/com/leokom/chess/player/legal/brain/denormalized/DenormalizedPlayerSupplier.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.leokom.chess.player.legal.brain.denormalized; - -import com.leokom.chess.player.Player; -import com.leokom.chess.player.legal.LegalPlayer; - -import java.util.function.Supplier; - -public class DenormalizedPlayerSupplier implements Supplier { - @Override - public Player get() { - return new LegalPlayer( new DenormalizedBrain() ); - } -} diff --git a/src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java b/src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java new file mode 100644 index 000000000..b346d01d8 --- /dev/null +++ b/src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java @@ -0,0 +1,30 @@ +package com.leokom.chess.player.legal.brain.normalized; + +import com.leokom.chess.engine.Move; +import com.leokom.chess.engine.Position; +import com.leokom.chess.player.Player; +import com.leokom.chess.player.legal.brain.common.Brain; +import com.leokom.chess.player.legal.brain.common.Evaluator; +import com.leokom.chess.player.legal.brain.common.GenericBrain; +import com.leokom.chess.player.legal.brain.normalized.MasterEvaluator; +import com.leokom.chess.player.legal.brain.normalized.NormalizedBrain; + +import java.util.function.Supplier; + +public class NormalizedBrainSupplier implements Supplier> { + //this depth has been used for years + private static final int DEFAULT_DEPTH = 1; + private final int depth; + + public NormalizedBrainSupplier() { + this(DEFAULT_DEPTH); + } + + public NormalizedBrainSupplier(int depth ) { + this.depth = depth; + } + + public GenericBrain get() { + return new NormalizedBrain<>( new MasterEvaluator(), depth ); + } +} diff --git a/src/main/java/com/leokom/chess/player/legal/brain/simple/SimplePlayerSupplier.java b/src/main/java/com/leokom/chess/player/legal/brain/simple/SimplePlayerSupplier.java deleted file mode 100644 index c537c93f0..000000000 --- a/src/main/java/com/leokom/chess/player/legal/brain/simple/SimplePlayerSupplier.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.leokom.chess.player.legal.brain.simple; - -import com.leokom.chess.player.Player; -import com.leokom.chess.player.legal.LegalPlayer; - -import java.util.function.Supplier; - -public class SimplePlayerSupplier implements Supplier { - - @Override - public Player get() { - return new LegalPlayer( new SimpleBrain() ); - } -} diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index cec993466..cf2409870 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -2,9 +2,10 @@ import com.leokom.chess.engine.Side; import com.leokom.chess.player.Player; -import com.leokom.chess.player.legal.LegalPlayerSupplier; -import com.leokom.chess.player.legal.brain.denormalized.DenormalizedPlayerSupplier; -import com.leokom.chess.player.legal.brain.simple.SimplePlayerSupplier; +import com.leokom.chess.player.legal.LegalPlayer; +import com.leokom.chess.player.legal.brain.denormalized.DenormalizedBrain; +import com.leokom.chess.player.legal.brain.normalized.NormalizedBrainSupplier; +import com.leokom.chess.player.legal.brain.simple.SimpleBrain; import com.leokom.chess.player.winboard.WinboardPlayerSupplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -85,11 +86,11 @@ private Supplier getPlayerSupplier( Side side, String engineName ) { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { case "brain.normalized": - return getLegalPlayerSupplier( side ); + return () -> new LegalPlayer( getNormalizedBrainSupplier( side ).get() ); case "brain.denormalized": - return new DenormalizedPlayerSupplier(); + return () -> new LegalPlayer( new DenormalizedBrain() ); case "brain.simple": - return new SimplePlayerSupplier(); + return () -> new LegalPlayer( new SimpleBrain() ); case "Winboard": return new WinboardPlayerSupplier(); default: @@ -97,10 +98,10 @@ private Supplier getPlayerSupplier( Side side, String engineName ) { } } - private LegalPlayerSupplier getLegalPlayerSupplier( Side side ) { + private NormalizedBrainSupplier getNormalizedBrainSupplier(Side side ) { return depthProperty.getFor(side) .map(Integer::valueOf) - .map(LegalPlayerSupplier::new) //takes depth parameter - .orElseGet(LegalPlayerSupplier::new); //without parameters, default constructor + .map(NormalizedBrainSupplier::new) //takes depth parameter + .orElseGet(NormalizedBrainSupplier::new); //without parameters, default constructor } } diff --git a/src/test/java/com/leokom/chess/SimulatorIT.java b/src/test/java/com/leokom/chess/SimulatorIT.java index 5dec029b8..6590ce155 100644 --- a/src/test/java/com/leokom/chess/SimulatorIT.java +++ b/src/test/java/com/leokom/chess/SimulatorIT.java @@ -5,14 +5,13 @@ import com.leokom.chess.engine.Side; import com.leokom.chess.player.Player; import com.leokom.chess.player.legal.LegalPlayer; -import com.leokom.chess.player.legal.LegalPlayerSupplier; import com.leokom.chess.player.legal.brain.common.Evaluator; import com.leokom.chess.player.legal.brain.common.EvaluatorType; import com.leokom.chess.player.legal.brain.denormalized.DenormalizedBrain; import com.leokom.chess.player.legal.brain.normalized.MasterEvaluator; import com.leokom.chess.player.legal.brain.normalized.MasterEvaluatorBuilder; import com.leokom.chess.player.legal.brain.normalized.NormalizedBrain; -import com.leokom.chess.player.legal.brain.simple.SimplePlayerSupplier; +import com.leokom.chess.player.legal.brain.simple.SimpleBrain; import org.junit.Ignore; import org.junit.Test; @@ -131,17 +130,17 @@ private void programPlayers( Position position, Position ... positions ) { when( second.getPosition() ).thenReturn( position, positions ); } - //we expect the default brain of the legal player is much smarter than the simple one + //we expect the normalized brain of the legal player is much smarter than the simple one @Test public void legalVsSimpleStatistics() { - final SimulatorStatistics statistics = new Simulator( new LegalPlayerSupplier(), new SimplePlayerSupplier() ).run(); + final SimulatorStatistics statistics = new Simulator( new LegalPlayer( new NormalizedBrain<>( new MasterEvaluator() ) ), new LegalPlayer( new SimpleBrain() ) ).run(); assertEquals( new SimulatorStatistics( 2, 2, 0 ), statistics ); } @Test public void simpleVsSimpleStatistics() { - final SimulatorStatistics statistics = new Simulator( new SimplePlayerSupplier(), new SimplePlayerSupplier() ).run(); + final SimulatorStatistics statistics = new Simulator( new LegalPlayer( new SimpleBrain() ), new LegalPlayer( new SimpleBrain() ) ).run(); //now simple vs simple correctly draws at the second move assertEquals( new SimulatorStatistics( 2, 0, 0 ), statistics ); diff --git a/src/test/java/com/leokom/chess/player/legal/LegalPlayerNameTest.java b/src/test/java/com/leokom/chess/player/legal/LegalPlayerNameTest.java index 749b2c987..3eed9a707 100644 --- a/src/test/java/com/leokom/chess/player/legal/LegalPlayerNameTest.java +++ b/src/test/java/com/leokom/chess/player/legal/LegalPlayerNameTest.java @@ -1,6 +1,6 @@ package com.leokom.chess.player.legal; -import com.leokom.chess.player.legal.brain.simple.SimplePlayerSupplier; +import com.leokom.chess.player.legal.brain.simple.SimpleBrain; import com.leokom.chess.player.legal.brain.denormalized.DenormalizedBrain; import com.leokom.chess.player.legal.brain.normalized.MasterEvaluator; import com.leokom.chess.player.legal.brain.normalized.NormalizedBrain; @@ -21,6 +21,6 @@ public void normalizedBrain() { @Test public void simpleBrain() { - assertEquals( "LegalPlayer : SimpleBrain", new SimplePlayerSupplier().get().name() ); + assertEquals( "LegalPlayer : SimpleBrain", new LegalPlayer( new SimpleBrain() ).name() ); } } diff --git a/src/test/java/com/leokom/chess/player/legal/brain/simple/SimpleBrainTest.java b/src/test/java/com/leokom/chess/player/legal/brain/simple/SimpleBrainTest.java index ea44ee660..3396065c6 100644 --- a/src/test/java/com/leokom/chess/player/legal/brain/simple/SimpleBrainTest.java +++ b/src/test/java/com/leokom/chess/player/legal/brain/simple/SimpleBrainTest.java @@ -4,6 +4,7 @@ import com.leokom.chess.engine.Move; import com.leokom.chess.player.Player; import com.leokom.chess.player.PlayerBuilder; +import com.leokom.chess.player.legal.LegalPlayer; import org.junit.Before; import org.junit.Test; @@ -17,7 +18,7 @@ public class SimpleBrainTest { @Before public void prepare() { - simplePlayer = new SimplePlayerSupplier().get(); + simplePlayer = new LegalPlayer( new SimpleBrain() ); } @Test From 648844d2443a1f535693f1c1a8a426f3469ba902 Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 7 Aug 2019 23:01:37 +0300 Subject: [PATCH 12/13] Refactoring: simplified players creation --- .../normalized/NormalizedBrainSupplier.java | 30 ------------------- .../chess/player/winboard/WinboardPlayer.java | 2 +- .../winboard/WinboardPlayerSupplier.java | 13 -------- .../chess/players/CommandLinePlayers.java | 28 ++++++++--------- 4 files changed, 13 insertions(+), 60 deletions(-) delete mode 100644 src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java delete mode 100644 src/main/java/com/leokom/chess/player/winboard/WinboardPlayerSupplier.java diff --git a/src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java b/src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java deleted file mode 100644 index b346d01d8..000000000 --- a/src/main/java/com/leokom/chess/player/legal/brain/normalized/NormalizedBrainSupplier.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.leokom.chess.player.legal.brain.normalized; - -import com.leokom.chess.engine.Move; -import com.leokom.chess.engine.Position; -import com.leokom.chess.player.Player; -import com.leokom.chess.player.legal.brain.common.Brain; -import com.leokom.chess.player.legal.brain.common.Evaluator; -import com.leokom.chess.player.legal.brain.common.GenericBrain; -import com.leokom.chess.player.legal.brain.normalized.MasterEvaluator; -import com.leokom.chess.player.legal.brain.normalized.NormalizedBrain; - -import java.util.function.Supplier; - -public class NormalizedBrainSupplier implements Supplier> { - //this depth has been used for years - private static final int DEFAULT_DEPTH = 1; - private final int depth; - - public NormalizedBrainSupplier() { - this(DEFAULT_DEPTH); - } - - public NormalizedBrainSupplier(int depth ) { - this.depth = depth; - } - - public GenericBrain get() { - return new NormalizedBrain<>( new MasterEvaluator(), depth ); - } -} diff --git a/src/main/java/com/leokom/chess/player/winboard/WinboardPlayer.java b/src/main/java/com/leokom/chess/player/winboard/WinboardPlayer.java index 4ed8a4278..e99ae6138 100644 --- a/src/main/java/com/leokom/chess/player/winboard/WinboardPlayer.java +++ b/src/main/java/com/leokom/chess/player/winboard/WinboardPlayer.java @@ -162,7 +162,7 @@ private boolean canClaimDrawBeExecutedNow() { * @return instance of properly initialized Player against WinBoard-powered player * */ - static Player create() { + public static Player create() { //TODO: implement some singleton policy? final WinboardCommunicator communicator = new WinboardCommunicator(); return new WinboardPlayer( new WinboardCommanderImpl( communicator ) ); diff --git a/src/main/java/com/leokom/chess/player/winboard/WinboardPlayerSupplier.java b/src/main/java/com/leokom/chess/player/winboard/WinboardPlayerSupplier.java deleted file mode 100644 index 49d42c2f9..000000000 --- a/src/main/java/com/leokom/chess/player/winboard/WinboardPlayerSupplier.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.leokom.chess.player.winboard; - -import com.leokom.chess.player.Player; - -import java.util.function.Supplier; - -public class WinboardPlayerSupplier implements Supplier { - - @Override - public Player get() { - return WinboardPlayer.create(); - } -} diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index cf2409870..1039dfd81 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -4,15 +4,15 @@ import com.leokom.chess.player.Player; import com.leokom.chess.player.legal.LegalPlayer; import com.leokom.chess.player.legal.brain.denormalized.DenormalizedBrain; -import com.leokom.chess.player.legal.brain.normalized.NormalizedBrainSupplier; +import com.leokom.chess.player.legal.brain.normalized.MasterEvaluator; +import com.leokom.chess.player.legal.brain.normalized.NormalizedBrain; import com.leokom.chess.player.legal.brain.simple.SimpleBrain; -import com.leokom.chess.player.winboard.WinboardPlayerSupplier; +import com.leokom.chess.player.winboard.WinboardPlayer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.Optional; import java.util.function.Function; -import java.util.function.Supplier; /** * Create players for the chess game based on command-line parameters @@ -79,29 +79,25 @@ public Player apply( Side side ) { return side == Side.WHITE ? "Winboard" : "brain.normalized"; } ); - return getPlayerSupplier( side, engineName ).get(); + return getPlayer( side, engineName ); } - private Supplier getPlayerSupplier( Side side, String engineName ) { + private Player getPlayer(Side side, String engineName ) { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { case "brain.normalized": - return () -> new LegalPlayer( getNormalizedBrainSupplier( side ).get() ); + int depth = depthProperty.getFor(side) + .map(Integer::valueOf) + .orElse( 1 ); //this depth has been used for years + return new LegalPlayer( new NormalizedBrain<>( new MasterEvaluator(), depth ) ); case "brain.denormalized": - return () -> new LegalPlayer( new DenormalizedBrain() ); + return new LegalPlayer( new DenormalizedBrain() ); case "brain.simple": - return () -> new LegalPlayer( new SimpleBrain() ); + return new LegalPlayer( new SimpleBrain() ); case "Winboard": - return new WinboardPlayerSupplier(); + return WinboardPlayer.create(); default: throw new IllegalArgumentException( "The engine is not supported: " + engineName); } } - - private NormalizedBrainSupplier getNormalizedBrainSupplier(Side side ) { - return depthProperty.getFor(side) - .map(Integer::valueOf) - .map(NormalizedBrainSupplier::new) //takes depth parameter - .orElseGet(NormalizedBrainSupplier::new); //without parameters, default constructor - } } From 0596fc5cfe86fdad7cf2016ac7093f1ae45d794e Mon Sep 17 00:00:00 2001 From: Leonid Rozenblyum Date: Wed, 14 Aug 2019 22:43:45 +0300 Subject: [PATCH 13/13] Winboard creation looks well --- src/main/java/com/leokom/chess/MainRunner.java | 4 ++-- .../java/com/leokom/chess/players/CommandLinePlayers.java | 6 +++--- .../com/leokom/chess/players/CommandLinePlayersTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/leokom/chess/MainRunner.java b/src/main/java/com/leokom/chess/MainRunner.java index cca277f3c..9b40b4259 100644 --- a/src/main/java/com/leokom/chess/MainRunner.java +++ b/src/main/java/com/leokom/chess/MainRunner.java @@ -29,7 +29,7 @@ private MainRunner() { * * engineName could be any of: *
        - *
      • Winboard
      • + *
      • ui.winboard
      • *
      • brain.simple
      • *
      • brain.denormalized
      • *
      • brain.normalized
      • @@ -37,7 +37,7 @@ private MainRunner() { * * Default players: *
          - *
        • -Dwhite.engine=Winboard
        • + *
        • -Dwhite.engine=ui.winboard
        • *
        • -Dblack.engine=brain.normalized
        • *
        * diff --git a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java index 1039dfd81..85645df59 100644 --- a/src/main/java/com/leokom/chess/players/CommandLinePlayers.java +++ b/src/main/java/com/leokom/chess/players/CommandLinePlayers.java @@ -76,13 +76,13 @@ Optional getFor( Side side ) { public Player apply( Side side ) { String engineName = engineProperty.getFor( side ).orElseGet( () -> { logger.info( "Selecting a default engine for Side = " + side ); - return side == Side.WHITE ? "Winboard" : "brain.normalized"; + return side == Side.WHITE ? "ui.winboard" : "brain.normalized"; } ); return getPlayer( side, engineName ); } - private Player getPlayer(Side side, String engineName ) { + private Player getPlayer( Side side, String engineName ) { logger.info("Selecting an engine for Side = " + side + " by engine name = " + engineName); switch (engineName) { case "brain.normalized": @@ -94,7 +94,7 @@ private Player getPlayer(Side side, String engineName ) { return new LegalPlayer( new DenormalizedBrain() ); case "brain.simple": return new LegalPlayer( new SimpleBrain() ); - case "Winboard": + case "ui.winboard": return WinboardPlayer.create(); default: throw new IllegalArgumentException( "The engine is not supported: " + engineName); diff --git a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java index 7556e154e..085210c40 100644 --- a/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java +++ b/src/test/java/com/leokom/chess/players/CommandLinePlayersTest.java @@ -49,7 +49,7 @@ private void assertIsSimple(Player player) { @Test public void canSelectWinboardForBlack() { - System.setProperty( "black.engine", "Winboard" ); + System.setProperty( "black.engine", "ui.winboard" ); final Player player = new CommandLinePlayers().apply( Side.BLACK ); assertTrue( player instanceof WinboardPlayer );