Skip to content

Commit

Permalink
Merge branch 'java9'
Browse files Browse the repository at this point in the history
  • Loading branch information
No3x committed Jul 3, 2019
2 parents 673deae + fbed4b7 commit f231a9c
Show file tree
Hide file tree
Showing 31 changed files with 247 additions and 86 deletions.
25 changes: 15 additions & 10 deletions build.gradle
@@ -1,47 +1,52 @@
task wrapper(type: Wrapper) {
gradleVersion = '4.5'
distributionType = 'ALL'
}

buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}

}
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply from: rootProject.file('gradle/codecov.gradle')
apply from: rootProject.file('gradle/jmh.gradle')

javafx {
version = "12"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}

group = 'de.kintel'
version = '0.0.2-SNAPSHOT'
sourceCompatibility = 1.8
sourceCompatibility = 9
targetCompatibility = 9

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}


dependencies {
compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.16'
compile 'org.apache.commons:commons-lang3:3.7'
testCompile 'com.shazam:shazamcrest:0.11'
compile 'de.saxsys:mvvmfx:1.7.0'
compile 'com.gluonhq:ignite-spring:1.0.0'
compile 'com.github.lestard:Grid:0190d50d93'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.1.100'
compileOnly 'javax.annotation:javax.annotation-api:1.3.1'
compile 'com.google.guava:guava:19.0'
compile 'com.github.avianey:minimax4j:fcb7a9c77b'
compile('org.springframework.boot:spring-boot-starter')
Expand Down
110 changes: 110 additions & 0 deletions gradle/jmh.gradle
@@ -0,0 +1,110 @@
sourceSets {
jmh {
compileClasspath += sourceSets.test.runtimeClasspath
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}

dependencies {
jmhCompile project
jmhCompile 'org.openjdk.jmh:jmh-core:1.18'
jmhCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.18'
}

eclipse {
classpath {
plusConfigurations.add(configurations.jmhCompile)
defaultOutputDir = file('build/classes-jmh-ide')
}
}

task ('jmhHelp', description:'Print help for the jmh task') {
doLast {
println ""
println "Usage of jmh tasks:"
println ""

println "Only execute specific benchmark(s):"
println "\t./gradlew jmh -Pinclude=\".*MyBenchmark.*\""

println ""
println "Specify extra profilers:"
println "\t./gradlew jmh -Pprofilers=\"gc,stack\""

println ""
println "Prominent profilers (for full list call jmhProfilers task):"
println "\tcomp - JitCompilations, tune your iterations"
println "\tstack - which methods used most time"
println "\tgc - print garbage collection stats"
println "\ths_thr - thread usage"

println ""
println "Change report format from JSON to one of [CSV, JSON, NONE, SCSV, TEXT]:"
println "\t./gradlew jmh -Pformat=csv"

println ""
println "Specify JVM arguments:"
println "\t./gradlew jmh -PjvmArgs=\"-Dtest.cluster=local\""

println ""
println "Run in verification mode (execute benchmarks with minimum of fork/warmup-/benchmark-iterations):"
println "\tgw jmh -Pverify"

println ""
println "Resources:"
println "\thttp://tutorials.jenkov.com/java-performance/jmh.html (Introduction)"
println "\thttp://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/ (Samples)"
}
}

task jmhProfilers(type: JavaExec, description:'Lists the available profilers for the jmh task', group: 'Development') {
classpath = sourceSets.jmh.runtimeClasspath
main = 'org.openjdk.jmh.Main'
args '-lprof'
}

task jmh(type: JavaExec, description: 'Executing JMH benchmarks') {
classpath = sourceSets.jmh.runtimeClasspath
main = 'org.openjdk.jmh.Main'

def include = project.properties.get('include', '');
def exclude = project.properties.get('exclude');
def format = project.properties.get('format', 'json');
def profilers = project.properties.get('profilers');
def jvmArgs = project.properties.get('jvmArgs')
def verify = project.properties.get('verify');

def resultFile = file("build/reports/jmh/result.${format}")

args include
if(exclude) {
args '-e', exclude
}
if(verify != null) { // execute benchmarks with the minimum amount of execution (only to check if they are working)
println "≥≥ Running in verify mode"
args '-f' , 1
args '-wi' , 1
args '-i' , 1
}
args '-foe', 'true' //fail-on-error
args '-v', 'NORMAL' //verbosity [SILENT, NORMAL, EXTRA]
if(profilers) {
profilers.split(',').each {
args '-prof', it
}
}
args '-jvmArgsPrepend', '-Xmx3072m'
args '-jvmArgsPrepend', '-Xms3072m'
if(jvmArgs) {
for(jvmArg in jvmArgs.split(' ')) {
args '-jvmArgsPrepend', jvmArg
}
}
args '-rf', format
args '-rff', resultFile

doFirst {
println "\nExecuting JMH with: $args \n"
resultFile.parentFile.mkdirs()
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
54 changes: 54 additions & 0 deletions src/jmh/java/de/kintel/ki/WeightingBenchmarks.java
@@ -0,0 +1,54 @@
package de.kintel.ki;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import com.google.common.collect.Lists;
import de.kintel.ki.algorithm.MoveClassifier;
import de.kintel.ki.algorithm.Weighting;
import de.kintel.ki.algorithm.WeightingDummyImpl;
import de.kintel.ki.algorithm.WeightingHeightAndRank;
import de.kintel.ki.model.Board;
import de.kintel.ki.model.GridFactory;
import de.kintel.ki.model.Player;
import de.kintel.ki.ruleset.RulesChecker;
import de.kintel.ki.ruleset.rules.RuleDestinationIsEmpty;
import de.kintel.ki.ruleset.rules.RuleDirection;
import de.kintel.ki.ruleset.rules.RuleDistanceAndOpponent;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.slf4j.LoggerFactory;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

@BenchmarkMode({Mode.AverageTime})
@OutputTimeUnit(NANOSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 3, time = 500, timeUnit = MILLISECONDS)
@Measurement(iterations = 5, time = 200, timeUnit = MILLISECONDS)
public class WeightingBenchmarks {

private Weighting weightingDummy;
private Weighting weightingHeightAndRank;
private Board board;

@Setup
public void prepare() {
weightingDummy = new WeightingDummyImpl();
weightingHeightAndRank = new WeightingHeightAndRank(new MoveClassifier(new RulesChecker(Lists.newArrayList(new RuleDirection(), new RuleDestinationIsEmpty(), new RuleDistanceAndOpponent()))));
board = new Board(7, 9, GridFactory.getLaskaInitGrid());
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.ERROR);
}

@Benchmark
public void weightingHeightAndRank(Blackhole fox) {
fox.consume(weightingHeightAndRank.evaluate(board, Player.SCHWARZ));
}

@Benchmark
public void dummyWeighting(Blackhole fox) {
fox.consume(weightingDummy.evaluate(board, Player.SCHWARZ));
}

}
8 changes: 4 additions & 4 deletions src/main/java/de/kintel/ki/algorithm/KI.java
Expand Up @@ -12,10 +12,10 @@
import de.kintel.ki.model.Player;
import de.kintel.ki.util.BoardUtils;
import fr.avianey.minimax4j.impl.ParallelNegamax;
import org.eclipse.jdt.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
Expand All @@ -34,7 +34,7 @@ public class KI extends ParallelNegamax<Move> implements Serializable {
private Player currentPlayer;
private MoveClassifier moveClassifier;

public KI(@Nonnull MoveClassifier moveClassifier, @Nonnull MoveMaker moveMaker, @Nonnull Weighting weighting, @Nonnull Board board) {
public KI(@NonNull MoveClassifier moveClassifier, @NonNull MoveMaker moveMaker, @NonNull Weighting weighting, @NonNull Board board) {
this.moveMaker = moveMaker;
this.weighting = weighting;
this.board = board;
Expand All @@ -60,7 +60,7 @@ public boolean isOver() {
* @see #next()
*/
@Override
public void makeMove(@Nonnull Move move) {
public void makeMove(@NonNull Move move) {
logger.debug("make move " + move);
moveMaker.makeMove(move, board);
next();
Expand All @@ -75,7 +75,7 @@ public void makeMove(@Nonnull Move move) {
* @see #previous()
*/
@Override
public void unmakeMove(@Nonnull Move move) {
public void unmakeMove(@NonNull Move move) {
logger.debug("unmake move " + move);
moveMaker.undoMove(move, board);
previous();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/de/kintel/ki/algorithm/MoveMaker.java
Expand Up @@ -8,19 +8,18 @@

import de.kintel.ki.model.Board;
import de.kintel.ki.model.Move;

import javax.annotation.Nonnull;
import org.eclipse.jdt.annotation.NonNull;

public interface MoveMaker {
/**
* Make a move.
* @param move the move
*/
void makeMove(@Nonnull Move move, Board board);
void makeMove(@NonNull Move move, Board board);

/**
* Undo a move.
* @param move the move
*/
void undoMove(@Nonnull Move move, Board board);
void undoMove(@NonNull Move move, Board board);
}
Expand Up @@ -8,14 +8,14 @@

import de.kintel.ki.model.Board;
import de.kintel.ki.model.Move;
import org.eclipse.jdt.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.HashMap;

/**
Expand All @@ -41,13 +41,13 @@ public MoveMakerGuardDecorator(@Qualifier("moveMakerBasic") MoveMaker moveMakerB
}

@Override
public void makeMove(@Nonnull Move move, Board board) {
public void makeMove(@NonNull Move move, Board board) {
guard.put(move, board.toString());
moveMaker.makeMove(move, board);
}

@Override
public void undoMove(@Nonnull Move move, Board board) {
public void undoMove(@NonNull Move move, Board board) {
moveMaker.undoMove(move, board);
final String expected = guard.get(move);
final String actual = board.toString();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/kintel/ki/algorithm/MoveMakerImpl.java
Expand Up @@ -7,14 +7,14 @@
package de.kintel.ki.algorithm;

import de.kintel.ki.model.*;
import org.eclipse.jdt.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.Optional;

Expand All @@ -38,7 +38,7 @@ public MoveMakerImpl(RankMaker rankMaker) {
* @param move the move
*/
@Override
public void makeMove(@Nonnull final Move move, Board board) {
public void makeMove(@NonNull final Move move, Board board) {
doMove(move, board, false);
}

Expand All @@ -48,7 +48,7 @@ public void makeMove(@Nonnull final Move move, Board board) {
* @param move the move
*/
@Override
public void undoMove(@Nonnull final Move move, Board board) {
public void undoMove(@NonNull final Move move, Board board) {
doMove(move, board, true);
}

Expand Down

0 comments on commit f231a9c

Please sign in to comment.