{"id":22355985,"url":"https://github.com/curso-r/stockfish","last_synced_at":"2025-06-22T17:34:40.505Z","repository":{"id":52181568,"uuid":"321140994","full_name":"curso-r/stockfish","owner":"curso-r","description":"An R package to analyze chess games with the Stockfish engine","archived":false,"fork":false,"pushed_at":"2022-03-20T04:40:53.000Z","size":27805,"stargazers_count":31,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-06T06:24:08.433Z","etag":null,"topics":["chess","r","stockfish","uci"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/curso-r.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-13T19:15:34.000Z","updated_at":"2024-11-24T08:13:49.000Z","dependencies_parsed_at":"2022-08-21T05:50:24.623Z","dependency_job_id":null,"html_url":"https://github.com/curso-r/stockfish","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/curso-r/stockfish","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curso-r%2Fstockfish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curso-r%2Fstockfish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curso-r%2Fstockfish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curso-r%2Fstockfish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/curso-r","download_url":"https://codeload.github.com/curso-r/stockfish/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curso-r%2Fstockfish/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261334804,"owners_count":23143423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chess","r","stockfish","uci"],"created_at":"2024-12-04T14:08:49.885Z","updated_at":"2025-06-22T17:34:35.467Z","avatar_url":"https://github.com/curso-r.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# stockfish \u003ca href='https://curso-r.com/'\u003e\u003cimg src='man/figures/logo.png' align=\"right\" height=\"139\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/stockfish)](https://CRAN.R-project.org/package=stockfish)\n[![Codecov test coverage](https://codecov.io/gh/curso-r/stockfish/branch/master/graph/badge.svg)](https://app.codecov.io/gh/curso-r/stockfish?branch=master)\n[![R-CMD-check](https://github.com/curso-r/stockfish/workflows/R-CMD-check/badge.svg)](https://github.com/curso-r/stockfish/actions)\n\u003c!-- badges: end --\u003e\n\n## Overview\n\n`{stockfish}` is an R package that implements the\n[UCI](http://wbec-ridderkerk.nl/html/UCIProtocol.html) open communication\nprotocol and ships with\n[Stockfish](https://github.com/official-stockfish/Stockfish), a very popular,\nopen source, powerful chess engine written in C++.\n\n## Installation\n\nInstall the released version of `{stockfish}` from CRAN:\n\n``` r\ninstall.packages(\"stockfish\")\n```\n\nOr install the development version from\n[GitHub](https://github.com/curso-r/stockfish):\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"curso-r/stockfish\")\n```\n\nYou can also find more (and more recent) versions of the Stockfish engine to use\nwith `{stockfish}` at their [download page](https://stockfishchess.org/download/).\n\n## Example\n\n`{stockfish}` is as simple to use as any other UCI package. You should start the\nengine with `fish$new()` and send commands with its internal methods, only\nremembering to run `quit()` once you're done.\n\n```{r}\nlibrary(stockfish)\n\n# Start the engine\nengine \u003c- fish$new()\n\n# Examine background process\nengine$process\n\n# Search for best move\nengine$go()\n\n# Setup a game from FEN\nengine$ucinewgame()\nengine$position(\"6rk/2Q3p1/5qBp/5P2/8/7P/6PK/8 w - - 15 51\")\nengine$go()\n\n# Stop the engine\nengine$quit()\n```\n\n## Usage\n\n`fish`, this package's main class, represents a Stockfish engine, allowing the\nuser to send commands and receive outputs according to the UCI protocol. In\nshort, a `fish` object, when created, spawns a detached Stockfish process and\npipes into its stdin and stdout.\n\nFor more information, see its full documentation by running `?fish`.\n\n### Bundled Stockfish\n\nThis package comes bundled with\n[Stockfish](https://github.com/official-stockfish/Stockfish), a very popular,\nopen source, powerful chess engine written in C++. It can achieve an ELO of\n3544, runs on Windows, macOS, Linux, iOS and Android, and can be compiled in\nless than a minute.\n\nWhen installing `{stockfish}` (lower case), Stockfish's (upper case) source\ncode is compiled and the resulting executable is stored with your R packages.\nThis is not a system-wide installation! You don't have to give it\nadministrative privileges to run or even worry about any additional software.\n\nBut there are two main downsides:\n\n1. While the bundled version of the engine (Stockfish 14.1) is up-to-date as of\nMarch 2022, it isn't able to update itself. This means that, if I'm not able to\nport an upcomming version of Stockfish, the package will stay behind. Luckly,\nyou can always [download](https://stockfishchess.org/download/) the\nversion of your choosing and pass the executable as an argument to `fish$new()`.\n\n2. Since version 12, Stockfish supports\n[NNUE evaluation](https://github.com/official-stockfish/Stockfish#a-note-on-classical-evaluation-versus-nnue-evaluation),\nbut this requires some pretty heavy binaries. In order to avoid bundling large\nfiles with `{stockfish}`, **I have decided to disable NNUE** in the source code.\nAgain, you are free to [download](https://stockfishchess.org/download/) a\nNNUE-capable version and use it instead of the bundled executable.\n\n### UCI Protocol\n\nUCI (Universal Chess Interface) is an open communication protocol that\nenables chess engines to communicate with user interfaces. Strictly speaking,\nthe `fish` class implements the\n[UCI protocol](http://wbec-ridderkerk.nl/html/UCIProtocol.html) as\npublicized by Stefan-Meyer Kahlen, just with a focus on the Stockfish engine.\nThis means that some methods are not implemented (see **Common Gotchas**) and\nthat all tests are run on Stockfish, but everything else should work fine\nwith other engines.\n\nThe quoted text at the end of the documentation of each method was extracted\ndirectly from the official UCI protocol, so you can see exactly what that\ncommand can do. In general, the commands are pretty self-explanatory, except\nfor long algebraic notation (LAN), the move notation used by UCI. In this\nnotation, moves are recorded using the starting and ending positions of each\npiece, e.g. e2e4, e7e5, e1g1 (white short castling), e7e8q (for promotion),\n0000 (nullmove).\n\n### Implementation\n\nAll the heavy lifting of the `fish` class is done by the `{processx}` package.\nThe Stockfish process is created with `processx::process$new` and IO is done\nwith `write_input()` and `read_output()`. An important aspect of the\ncommunication protocol of any UCI engine is waiting for replies, and here this\nis done with a loop that queries the process with `poll_io()` and stops once the\noutput comes back empty.\n\nBefore implementing the UCI protocol manually, this package used\n`{bigchess}`. It is a great package created by\n[\\@rosawojciech](https://github.com/rosawojciech), but it has some\ndependencies that are beyond the scope of this package and ultimately I\nwanted more control over the API (e.g. using `{R6}`).\n\n### Common Gotchas\n\nThe `fish` class has some specifics that the user should keep in mind when\ntrying to communicate with Stockfish. Some of them are due to implementation\nchoices, but others are related to the UCI protocol itself. This is by no\nmeans a comprehensive list (and you should probably read\n[UCI's documentation](http://wbec-ridderkerk.nl/html/UCIProtocol.html)), but\nhere are a few things to look out for:\n\n- Not every UCI method is implemented: since `{stockfish}` was made with\nStockfish in mind, a couple of UCI methods that don't work with the engine were\nnot implemented. They are `debug()` and `register()`.\n\n- Most methods return silently: since most UCI commands don't output anything\nor output boilerplate text, most methods return silently. The\nexceptions are `run()`, `isready()`, `go()` and `stop()`; you can see exactly\nwhat they return by reading their documentations.\n\n- Not every Stockfish option will work: at least when using the bundled\nversion of Stockfish, not every documented option will work with `setoption()`.\nThis happens because, as described above, the bundled version has some\nlimitations. Options that will not work are labeled with an asterisk.\n\n- Times are in milliseconds: unlike most R functions, every method that takes\na time interval expects them in milliseconds, not seconds.\n\n## Code of Conduct\n\nPlease note that the `{stockfish}` project is released with a\n[Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).\nBy contributing to this project, you agree to abide by its terms.\n\n## Copyright Notice\n\nThe [C++ code](https://github.com/curso-r/stockfish/tree/master/src) of the\n`{stockfish}` project is derived from\n[Stockfish 14.1](https://github.com/official-stockfish/Stockfish/releases/tag/sf_14.1),\nand its main authors are listed as contributors in the\n[DESCRIPTION](https://github.com/curso-r/stockfish/blob/master/DESCRIPTION)\nfile. For a full list of Stockfish 14.1's authors, please see their\n[AUTHORS](https://github.com/official-stockfish/Stockfish/blob/7262fd5d14810b7b495b5038e348a448fda1bcc3/AUTHORS)\nlist. Finally, as per Stockfish's terms of use, `{stockfish}` is also licensed\nunder the GPL 3 (or any later version at your option). Check out\n[LICENSE.md](https://github.com/curso-r/stockfish/blob/master/LICENSE.md) for\nthe full text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurso-r%2Fstockfish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcurso-r%2Fstockfish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurso-r%2Fstockfish/lists"}