https://github.com/loloof64/reactnativestockfish
Use stockfish chess engine in your React Native application
https://github.com/loloof64/reactnativestockfish
android ios-untested react-native stockfish-17 stockfish-engine turbomodules
Last synced: 6 months ago
JSON representation
Use stockfish chess engine in your React Native application
- Host: GitHub
- URL: https://github.com/loloof64/reactnativestockfish
- Owner: loloof64
- License: mit
- Created: 2024-12-21T10:23:26.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-01-05T21:55:05.000Z (9 months ago)
- Last Synced: 2025-04-09T11:51:00.234Z (6 months ago)
- Topics: android, ios-untested, react-native, stockfish-17, stockfish-engine, turbomodules
- Language: C++
- Homepage:
- Size: 2.01 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @loloof64/react-native-stockfish
Use stockfish chess engine in your React Native application.
## Installation
```sh
npm install @loloof64/react-native-stockfish
```## Usage
```js
import {
useStockfish
} from '@loloof64/react-native-stockfish';// ...
const [stockfishOutput, setStockfishOutput] = useState('');
const {startStockfish, stopStockfish, sendCommandToStockfish} = useStockfish({
onOutput: useCallback((output: string) => {
setStockfishOutput((prev) => prev + output);
}, []),
onError: useCallback((error: string) => {
setStockfishOutput((prev) => `${prev}\n###Err\n${error}\n###`);
}, [])
});// ...
startStockfish();
// ...
sendCommandToStockfish('go movetime 1000');
// ...
stopStockfish();
```## Testing example project
Get started with the project:
$ yarn
Run the example app on iOS:
$ yarn example ios
Run the example app on Android:
$ yarn example android
## Contributing
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
### Changing Stockfish source files
If you need to upgrade Stockfish source files, create a folder **stockfish** inside **cpp** folder, copy the **src** folder from the stockfish sources into the new **stockfish folder**.
In **stockfish/src/main.cpp** replace the name of function `main` with `stockfish_core`.
Also you need to make some more adaptive works :
#### Adapting streams
- copy the **cpp/fixes** folder inside the **cpp/stockfish** folder
- replace all calls to `cout << #SomeContent# << endl` by `fakeout << #SomeContent# << fakeendl` (And ajust also calls to `cout.rdbuf()` by `fakeout.rdbuf()`) **But do not replace calls to sync_cout**.
- copy folder **cpp/fixes** inside the **stockfish** folder
- add include to **../fixes/fixes.h** in all related files (and adjust the include path accordingly)
- proceed accordingly for `cin` : replace by `fakein`
- and the same for `cerr`: replace by `fakeerr`
- in **misc.h** replace```cpp
#define sync_cout std::cout << IO_LOCK
#define sync_endl std::endl << IO_UNLOCK
```with
```cpp
#define sync_cout fakeout << IO_LOCK
#define sync_endl fakeendl << IO_UNLOCK
```and include **../../fixes/fixes.h**
#### Adapting NNUE
In file **CMakeLists.txt** replace the names of big and small NNUE by the ones you can find in file **cpp/stockfish/src/evaluate.h**. Also replace those values in the file **loloof64-react-native-stockfish.podspec**, as well as in the file **android/CMakeLists.txt**.
## License
MIT
---
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
## Credits
Using sources of [Stockfish 17](https://stockfishchess.org/).