> For the complete documentation index, see [llms.txt](https://organized-chaos.gitbook.io/organized-chaos-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://organized-chaos.gitbook.io/organized-chaos-docs/chess/ratings-stake-and-saved-files.md).

# Ratings, stake and saved files

How ratings and stakes work, and which files Chess writes.

## Ratings

Every player has a rating (Elo) that moves with each game against another player. It starts at `Config.RatingStart` and changes by up to `Config.RatingK` per game. The rating is shown next to the name, and after a game together with the change, counting up on the card at the end of the game.

* `/chess_stats` tells a player their own rating with wins, draws and losses.
* Games with fewer than two moves do not count.
* Games against the computer are not rated.
* `Config.Ratings = false` switches ratings off.
* With Qbox, QBCore or ESX the rating belongs to the character. Without a framework it belongs to the player's licence.

The best players are on the [leaderboard](/organized-chaos-docs/chess/leaderboard.md).

## Puzzle rating

Every player also has a puzzle rating, which moves with each [puzzle](/organized-chaos-docs/chess/puzzles.md): a puzzle solved without a wrong move is a win, otherwise a loss. It starts at `Config.PuzzleRatingStart` and changes by up to `Config.PuzzleK` per puzzle. It has a leaderboard of its own.

## Stake

With `Config.BuyIn` above 0, both players pay the stake when the game starts. The winner takes the pot, and a draw returns each stake.

* The stake needs a framework: Qbox, QBCore or ESX, the cash of `ox_inventory`, or functions of your own (`Config.Framework`). Without one the game is played for nothing.
* `Config.BuyInAccount` chooses between cash (`'money'`) and the bank account (`'bank'`).
* Games against the computer are never played for money.
* If a player is not connected when money is due to them, it is credited and paid out as soon as they are back.

## Saved games

The last finished games are kept as PGN, the standard format every chess program reads. `Config.GameLog` sets how many, and `0` keeps none.

## Files the resource writes

These files are created in the resource folder when they are first needed:

| File          | Contents                                                       |
| ------------- | -------------------------------------------------------------- |
| `tables.json` | Tables placed with `/chess_place` or the item, with their look |
| `stats.json`  | Ratings, records and puzzle ratings                            |
| `owed.json`   | Money for players who were away when it was due                |
| `games.pgn`   | The last finished games                                        |

{% hint style="warning" %}
Keep these files when you update the resource. Overwriting them resets your placed tables and every player's rating.
{% endhint %}

## Files that come with it

| File                 | Contents                    |
| -------------------- | --------------------------- |
| `data/puzzles.json`  | The 2,800 puzzles           |
| `data/openings.json` | The names of 3,300 openings |

Both come from Lichess's open databases (CC0, free to use in any way). Replace them with the resource's own when you update it.
