@loloof64/react-native-stockfish
v0.2.0
Published
Use stockfish chess engine in your React Native application
Downloads
132
Readme
@loloof64/react-native-stockfish
Use stockfish chess engine in your React Native application.
Installation
npm install @loloof64/react-native-stockfish
Usage
import {
stockfishLoop,
sendCommandToStockfish,
subscribeToStockfishOutput,
subscribeToStockfishError,
stopStockfish,
} from '@loloof64/react-native-stockfish';
// ...
stockfishLoop();
// ...
useEffect(() => {
const unsubscribe = subscribeToStockfishOutput((output) => {
console.log('Stockfish Output:', output);
});
return () => unsubscribe();
}, []);
useEffect(() => {
const unsubscribe = subscribeToStockfishError((error) => {
console.log('Stockfish Error:', error);
});
return () => unsubscribe();
}, []);
// ...
sendCommandToStockfish('go movetime 1000');
// ...
stopStockfish();
Contributing
See the contributing guide 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. 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
byfakeout << #SomeContent# << fakeendl
(And ajust also calls tocout.rdbuf()
byfakeout.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 byfakein
and the same for
cerr
: replace byfakeerr
in misc.h replace
#define sync_cout std::cout << IO_LOCK
#define sync_endl std::endl << IO_UNLOCK
with
#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.
License
MIT
Made with create-react-native-library
Credits
Using sources of Stockfish 17.