Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notation conversion, get_num_pieces function, and misc. #112

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
25a5beb
Initial stuff for convert_human_notation_into_sf_notation.
johndoknjas Aug 2, 2022
0a495dd
Raise ValueError when there's an issue. Also use 'is' for None checks.
johndoknjas Aug 2, 2022
13064eb
Use the re module instead of regex. Also write some test code.
johndoknjas Aug 2, 2022
f3d5902
Modify code to fix failing tests. Also handle mypy errors.
johndoknjas Aug 2, 2022
1068790
Modify tests slightly.
johndoknjas Aug 2, 2022
a99a853
Update README.md
johndoknjas Aug 2, 2022
317ec23
Merge branch 'notation-conversion' of https://github.com/johndoknjas/…
johndoknjas Aug 2, 2022
0dd95d7
Modify test
johndoknjas Aug 2, 2022
1499496
Update README.md
johndoknjas Aug 7, 2022
beaf64e
Don't send the ucinewgame command when setting a new position. Instea…
johndoknjas Aug 7, 2022
9c9f49c
Update README.md
johndoknjas Aug 8, 2022
bb30dd2
Implement PR feedback from FalcoGer.
johndoknjas Aug 9, 2022
f8195d3
Update README.md
johndoknjas Aug 9, 2022
2f62057
Update tests, and also include the move param in some ValueError mess…
johndoknjas Aug 9, 2022
d70afb1
Merge branch 'notation-conversion' of https://github.com/johndoknjas/…
johndoknjas Aug 9, 2022
4f32bbb
Add additional test move.
johndoknjas Aug 9, 2022
7d7618e
Update README.md
johndoknjas Aug 9, 2022
3436518
Regex fix to catch moves already in SF notation.
johndoknjas Aug 9, 2022
ebb3b68
Update README.md
johndoknjas Aug 9, 2022
30d2797
A few more test moves.
johndoknjas Aug 9, 2022
497eba0
get_num_pieces function
johndoknjas Aug 13, 2022
18f16b3
Update README.md
johndoknjas Aug 13, 2022
6fccad1
Update README.md
johndoknjas Aug 13, 2022
a14d63e
Add a way for the user to only count certain pieces for each side, if…
johndoknjas Aug 13, 2022
436d1a2
Test the get_num_pieces function more.
johndoknjas Aug 17, 2022
c4c1fc5
Format with updated version of black.
johndoknjas Aug 17, 2022
6234746
Test two FENs for same piece placement.
johndoknjas Aug 17, 2022
8a75c95
Fix bug in _is_fen_syntax_valid, by using fen.split() instead of rege…
johndoknjas Aug 17, 2022
9e82dbb
Update README.md
johndoknjas Aug 17, 2022
82d0bec
Accept custom ranges for files and ranks, instead of just one or all.
johndoknjas Aug 19, 2022
e1ae590
Update README.md
johndoknjas Aug 19, 2022
1e25c19
Update README.md
johndoknjas Aug 19, 2022
457537d
Return a deep copy of self._parameters from get_parameters().
johndoknjas Oct 9, 2022
a9ec12f
Update readme.
johndoknjas Nov 30, 2022
8a4116f
Fix errors given by new version of mypy, and format with black.
johndoknjas Nov 30, 2022
56ea969
Fix failing test for versions of Stockfish at and below 10.
johndoknjas Nov 30, 2022
4ced778
Format with black.
johndoknjas Nov 30, 2022
200a725
Delete test case.
johndoknjas Nov 30, 2022
d38277e
Update the workflow versions
kieferro Feb 22, 2023
5e9d9d3
Add missing type annotations
kieferro Feb 22, 2023
2b9f0a6
Fix test for stockfish version 14
kieferro Feb 22, 2023
f98cf0d
Merge pull request #1 from py-stockfish/update-workflows
kieferro Feb 22, 2023
ca85121
Give coverage workflow the required permission (#3)
kieferro Feb 22, 2023
26386bd
Change links and add information to README
kieferro Feb 22, 2023
8497504
Merge pull request #4 from py-stockfish/update-readme
johndoknjas Feb 25, 2023
7a10c80
Link to issue in old repo (#7)
kieferro Mar 7, 2023
d27eec4
Merge branch 'master' into notation-conversion
johndoknjas Mar 8, 2023
e367235
Merge branch 'master' into notation-conversion
johndoknjas Mar 8, 2023
e2f8c4c
Refactor and add `num_nodes` and `verbose` options to `get_top_moves(…
knutole Apr 20, 2023
6dc94c2
Use bools (#21)
johndoknjas Apr 22, 2023
3f8d8cf
Use `python3.11` in automated testing (#5)
kieferro Apr 23, 2023
9d1a585
Add python 3.11 to setup.py. (#24)
johndoknjas Apr 24, 2023
106ff61
Api documentation (#26)
knutole May 11, 2023
922030f
Add option to view all communication between engine and library (#30)
kieferro May 11, 2023
18eb3f5
Use turn perspective in get_evaluation(), if it's enabled. (#34)
johndoknjas May 15, 2023
5176411
Skip slow tests option (#31)
johndoknjas May 17, 2023
417e57d
Functions for static evaluation and resuming full strength. Also upda…
johndoknjas May 23, 2023
108b98b
Merge master into notation-merge-may-25 (using imerge)
johndoknjas May 26, 2023
427487e
Update test to refer to the new get_engine_parameters function.
johndoknjas May 26, 2023
3bf2dd1
Minor edits to docs.
johndoknjas May 26, 2023
5d4f89b
Add some type hints (#40)
johndoknjas May 31, 2023
b22afd3
Merge branch 'master' into notation-conversion
johndoknjas Jun 1, 2023
39c5f08
Add type hints in test_models, and fix a mypy error.
johndoknjas Jun 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ There are some default engine settings used by this wrapper. For increasing Stoc
}
```

You can change them, as well as the default search depth, during your Stockfish class initialization:
You can change them, as well as the search depth, during your Stockfish class initialization:
```python
stockfish = Stockfish(path="/Users/zhelyabuzhsky/Work/stockfish/stockfish-9-64", depth=18, parameters={"Threads": 2, "Minimum Thinking Time": 30})
```
Expand All @@ -58,6 +58,11 @@ These parameters can also be updated at any time by calling the "update_engine_p
stockfish.update_engine_parameters({"Hash": 2048, "UCI_Chess960": "true"}) # Gets stockfish to use a 2GB hash table, and also to play Chess960.
```

As for the depth, it can also be updated, by using the following function. Note that if you don't set depth to a value yourself, the python module will initialize it to 15 by default.
```python
stockfish.set_depth(12)
```

When you're done using the Stockfish engine process, you can send the "quit" uci command to it with:
```python
stockfish.send_quit_command()
Expand Down Expand Up @@ -121,6 +126,7 @@ e2e4
```

### Check is move correct with current position
Returns True if the passed in move is legal in the current position.
```python
stockfish.is_move_correct('a2a3')
```
Expand All @@ -129,17 +135,33 @@ True
```

### Get info on the top n moves
Returns a list of dictionaries, where each dictionary represents a move's info. Each dictionary will contain a value for the 'Move' key,
and either the 'Centipawn' or 'Mate' value will be a number (the other will be None). Positive values mean advantage for White, negative means
advantage for Black. E.g., 'Mate': 3 means that White can mate in three moves, 'Mate': -2 means Black mates in two moves, 'Centipawn': -20 means the
evaluation is -0.20 (0.20 advantage in Black's favour).
E.g., for an example position where White is to move, and the top moves are either a mate, winning material, or being slightly worse:
```python
stockfish.get_top_moves(3)
```
```text
[
{'Move': 'f5h7', 'Centipawn': None, 'Mate': 1},
{'Move': 'f5d7', 'Centipawn': 713, 'Mate': None},
{'Move': 'f5h5', 'Centipawn': -31, 'Mate': None}
{'Move': 'f5h7', 'Centipawn': None, 'Mate': 1}, # the move f5h7 leads to a mate in 1
{'Move': 'f5d7', 'Centipawn': 713, 'Mate': None}, # f5d7 leads to an evaluation of +7.13
{'Move': 'f5h5', 'Centipawn': -31, 'Mate': None} # f5h5 leads to an evaluation of -0.31
]
```

### Get current board evaluation in centipawns or mate in x
```python
stockfish.get_evaluation()
```
Positive is advantage white, negative is advantage black.
```text
{"type":"cp", "value":12} # This being the return value would mean White is better by 0.12.

{"type":"mate", "value":-3} # This being the return value would mean Black can checkmate in 3.
```

### Get Stockfish's win/draw/loss stats for the side to move in the current position
Before calling this function, it is recommended that you first check if your version of Stockfish is recent enough to display WDL stats. To do this,
use the "does_current_engine_version_have_wdl_option()" function below.
Expand Down Expand Up @@ -168,11 +190,6 @@ stockfish.set_skill_level(15)
stockfish.set_elo_rating(1350)
```

### Set current engine's depth
```python
stockfish.set_depth(15)
```

### Get current engine's parameters
```python
stockfish.get_parameters()
Expand Down Expand Up @@ -258,16 +275,6 @@ stockfish.get_board_visual(False)
h g f e d c b a
```

### Get current board evaluation in centipawns or mate in x
```python
stockfish.get_evaluation()
```
Positive is advantage white, negative is advantage black
```text
{"type":"cp", "value":12}
{"type":"mate", "value":-3}
```

### Run benchmark

#### BenchmarkParameters
Expand Down Expand Up @@ -311,6 +318,12 @@ stockfish.is_development_build_of_engine()
False
```

### Send the "ucinewgame" command to the Stockfish engine process.
The main effect this command has is clearing SF's transposition table, and for most use cases it's probably not worth doing this. Frequently sending this command can end up being a bottleneck on performance.
```python
stockfish.send_ucinewgame_command()
```

### Find what is on a certain square
If the square is empty, the None object is returned. Otherwise, one of 12 enum members of a custom
Stockfish.Piece enum will be returned. Each of the 12 members of this enum is named in the following pattern:
Expand All @@ -334,6 +347,19 @@ stockfish.will_move_be_a_capture("e5d6") # returns Stockfish.Capture.EN_PASSANT
stockfish.will_move_be_a_capture("f1e2") # returns Stockfish.Capture.NO_CAPTURE
```

### Convert human-style notation into the notation Stockfish uses
johndoknjas marked this conversation as resolved.
Show resolved Hide resolved
The argument is a string representing the move, written in some form that's used by humans. E.g., for using an e4-pawn to capture on d5, a string like
"e4xd5" or "exd5" could be sent in as a valid argument. The function would then return "e4d5".
```python
stockfish.convert_human_notation_to_sf_notation("e4xd5") # returns "e4d5"
```
Or, say there are two rooks on a5 and b6, and an enemy piece on a6. The following are all valid "human-style" notations for the a5-rook capturing on a6: "Raxa6", "Raa6", "R5xa6", "R5a6".
```python
stockfish.convert_human_notation_to_sf_notation("Raxa6") # returns "a5a6"
```
It's also valid for the argument to already be in the style Stockfish uses. E.g., sending in "a5a6" to the function just gets "a5a6" back.
If an invalid argument (bad syntax, or an illegal move) is sent to the function, a ValueError will be raised.

### StockfishException

The `StockfishException` is a newly defined Exception type. It is thrown when the underlying Stockfish process created by the wrapper crashes. This can happen when an incorrect input like an invalid FEN (for example ```8/8/8/3k4/3K4/8/8/8 w - - 0 1``` with both kings next to each other) is given to Stockfish. \
Expand Down
Loading