mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-14 15:25:08 +01:00
works
This commit is contained in:
parent
59a7ad0af9
commit
b083ef958d
4 changed files with 39 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@ minmax-java/build
|
|||
minmax-java/.gradle
|
||||
.idea
|
||||
target
|
||||
*.so
|
||||
23
README.md
Normal file
23
README.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Minmax in Rust with JNI
|
||||
|
||||
## How to build and run
|
||||
|
||||
### Prerequisites
|
||||
- Gradle
|
||||
- Rust toolchain
|
||||
|
||||
### Compile Rust code
|
||||
|
||||
`cargo build`
|
||||
|
||||
### Assemble shared library
|
||||
|
||||
Copy the shared library in `target/debug/librs_wrapper.so` (or a `.dll` on windows) to a known location like the working directory or the system wide library directory.
|
||||
|
||||
### Build the jar
|
||||
|
||||
Use `./gradlew jar` or whatever you like I don't know.
|
||||
|
||||
### Run the program
|
||||
|
||||
Maybe it works now. If you get a link error you might need to set the `LD_LIBRARY_PATH` env var to the path of the shared library (on linux). Or you have to copy it to the systems library directory. Or something else. But it should work.
|
||||
|
|
@ -11,6 +11,12 @@ java {
|
|||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'ch.bbw.m411.connect4.Connect4ArenaMain'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@ package ch.bbw.m411.connect4;
|
|||
public class RustPlayer extends Connect4ArenaMain.DefaultPlayer {
|
||||
private static native int rustPlay(byte player, byte[] board);
|
||||
|
||||
static {
|
||||
// This actually loads the shared object that we'll be creating.
|
||||
// The actual location of the .so or .dll may differ based on your
|
||||
// platform.
|
||||
System.loadLibrary("rs_wrapper");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int play() {
|
||||
byte player = switch (this.myColor) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue