Skip to content

Commit

Permalink
Merge pull request #333 from lrozenblyum/DifferentBrainSelectableCLI#278
Browse files Browse the repository at this point in the history
Different brain are selectable from cli. #278
  • Loading branch information
lrozenblyum authored Aug 15, 2019
2 parents a145612 + 0596fc5 commit 6aa1591
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 355 deletions.
70 changes: 36 additions & 34 deletions src/main/bat/runTwoEngines.bat
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
@rem =======================================================
@rem Runs 2-engine match between Chess deployed to <WinboardRoot>/LeokomChess and <WinboardRoot>/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 <WinboardRoot>/LeokomChess and <WinboardRoot>/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 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%

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
42 changes: 21 additions & 21 deletions src/main/bat/variables.bat
Original file line number Diff line number Diff line change
@@ -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 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%
9 changes: 9 additions & 0 deletions src/main/java/com/leokom/chess/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.leokom.chess.player.Player;
import org.apache.logging.log4j.LogManager;

import java.util.function.Function;

/**
* Create &amp; Run Game of Chess.
* Author: Leonid
Expand All @@ -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
Expand Down
29 changes: 12 additions & 17 deletions src/main/java/com/leokom/chess/MainRunner.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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;

Expand Down Expand Up @@ -30,20 +29,21 @@ private MainRunner() {
*
* <code>engineName</code> could be any of:
* <ul>
* <li>Winboard</li>
* <li>Simple</li>
* <li>Legal</li>
* <li>ui.winboard</li>
* <li>brain.simple</li>
* <li>brain.denormalized</li>
* <li>brain.normalized</li>
* </ul>
*
* Default players:
* <ul>
* <li>-Dwhite.engine=Winboard</li>
* <li>-Dblack.engine=Legal</li>
* <li>-Dwhite.engine=ui.winboard</li>
* <li>-Dblack.engine=brain.normalized</li>
* </ul>
*
* <p>
*
* Optional parameters for LegalPlayer
* Optional parameters for brain.normalized
* <ul>
* <li>-Dwhite.depth=<code>depth in plies</code></li>
* <li>-Dblack.depth=<code>depth in plies</code></li>
Expand All @@ -70,8 +70,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
Expand All @@ -86,12 +88,5 @@ public static void main( String[] args ) {

}

private static void runGame() {
final Player whitePlayer = PlayerFactory.createPlayer( Side.WHITE );
final Player blackPlayer = PlayerFactory.createPlayer( Side.BLACK );

new Game( whitePlayer, blackPlayer ).run();
}

}

89 changes: 0 additions & 89 deletions src/main/java/com/leokom/chess/PlayerFactory.java

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down

This file was deleted.

Loading

0 comments on commit 6aa1591

Please sign in to comment.