Skip to content

Commit

Permalink
Prepare v0.24.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 3, 2018
1 parent d690b73 commit f4e146e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 6 deletions.
76 changes: 76 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
Changelog for python-chess
==========================

Upcoming changes
----------------

This is the first release that **drops support for Python 2**. The *0.23.x*
branch will be maintained with critical bugfixes until the end of 2019.

Changes:

* **Require Python 3.4.** Thanks @hugovk.
* No longer using extra pip features:
`pip install python-chess[engine,gaviota]` is now `pip install python-chess`.
* Various keyword arguments can now be used as **keyword arguments only**.
* `chess.pgn.GameNode.accept()` now
**also visits the move leading to that node**.
* `chess.pgn.GameModelCreator` now requires that `begin_game()` be called.
* `chess.pgn.scan_headers()` and `chess.pgn.scan_offsets()` have been removed.
Instead the new functions `chess.pgn.read_headers()` and
`chess.pgn.skip_game()` can be used for a similar purpose.
* `chess.syzygy`: Invalid magic headers now raise `IOError`. Previously they
were only checked in an assertion.
`type(board).{tbw_magic,tbz_magic,pawnless_tbw_magic,pawnless_tbz_magic}`
are now byte literals.
* `board.status()` constants (`STATUS_`) are now typed using `enum.IntFlag`.
Values remain unchanged.
* `chess.svg.Arrow` is no longer a `namedtuple`.
* `chess.PIECE_SYMBOLS[0]` and `chess.PIECE_NAMES[0]` are now `None` instead
of empty strings.
* Performance optimizations:
- `chess.pgn.Game.from_board()`,
- `chess.square_name()`
- Replace `collections.deque` with lists almost everywhere.

Deprecations:

* Renamed methods (aliases will be removed in the next release):
- `chess.BB_VOID` -> `BB_EMPTY`
- `chess.bswap()` -> `flip_vertical()`
- `chess.pgn.GameNode.main_line()` -> `mainline_moves()`
- `chess.pgn.GameNode.is_main_line()` -> `is_mainline()`
- `chess.variant.BB_HILL` -> `chess.BB_CENTER`
- `chess.syzygy.open_tablebases()` -> `open_tablebase()`
- `chess.syzygy.Tablebases` -> `Tablebase`
- `chess.syzygy.Tablebase.open_directory()` -> `add_directory()`
- `chess.gaviota.open_tablebases()` -> `open_tablebase()`
- `chess.gaviota.open_tablebases_native()` -> `open_tablebase_native()`
- `chess.gaviota.NativeTablebases` -> `NativeTablebase`
- `chess.gaviota.PythonTablebases` -> `PythonTablebase`
- `chess.gaviota.NativeTablebase.open_directory()` -> `add_directory()`
- `chess.gaviota.PythonTablebase.open_directory()` -> `add_directory()`

Bugfixes:

* The PGN parser now gives the visitor a chance to handle unknown chess
variants and continue parsing.
* `chess.pgn.GameNode.uci()` was always raising an exception.

New features:

* `chess.SquareSet` now extends `collections.abc.MutableSet` and can be
initialized from iterables.
* `Board.apply_transform(f)` and `Board.transform(f)` can apply bitboard
transformations to a position. Examples:
`chess.flip_{vertical,horizontal,diagonal,anti_diagonal}`.
* `chess.pgn.GameNode.mainline()` iterates over nodes of the mainline.
Can also be used with `reversed()`. Reversal is now also supported for
`chess.pgn.GameNode.mainline_moves()`.
* `chess.svg.Arrow(tail, head, color="#888")` gained an optional *color*
argument.
* `chess.pgn.BaseVisitor.parse_san(board, san)` is used by parsers and can
be overwritten to deal with non-standard input formats.
* `chess.pgn`: Visitors can advise the parser to skip games or variations by
returning the special value `chess.pgn.SKIP` from `begin_game()`,
`end_headers()` or `begin_variation()`. This is treated as a hint.
The corresponding `end_game()` or `end_variation()` will still be called.
* Added `chess.svg.MARGIN`.

New in v0.23.10
---------------

Expand Down
4 changes: 2 additions & 2 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def flip_horizontal(bb):
bb = ((bb >> 4) & 0x0f0f0f0f0f0f0f0f) | ((bb & 0x0f0f0f0f0f0f0f0f) << 4)
return bb

def flip_diag(bb):
def flip_diagonal(bb):
# https://www.chessprogramming.org/Flipping_Mirroring_and_Rotating#FlipabouttheDiagonal
t = (bb ^ (bb << 28)) & 0x0f0f0f0f00000000
bb = bb ^ (t ^ (t >> 28))
Expand All @@ -239,7 +239,7 @@ def flip_diag(bb):
bb = bb ^ (t ^ (t >> 7))
return bb

def flip_anti_diag(bb):
def flip_anti_diagonal(bb):
# https://www.chessprogramming.org/Flipping_Mirroring_and_Rotating#FlipabouttheAntidiagonal
t = bb ^ (bb << 36)
bb = bb ^ ((t ^ (bb >> 36)) & 0xf0f0f0f00f0f0f0f)
Expand Down
6 changes: 6 additions & 0 deletions chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ def is_mainline(self):

return True

# TODO: Deprecated
is_main_line = is_mainline

def is_main_variation(self):
"""
Checks if this node is the first variation from the point of view of its
Expand Down Expand Up @@ -291,6 +294,9 @@ def mainline_moves(self):
"""Returns an iterator over the main moves after this node."""
return Mainline(self, lambda node: node.move)

# TODO: Deprecated
main_line = mainline_moves

def add_line(self, moves, *, comment="", starting_comment="", nags=()):
"""
Creates a sequence of child nodes for the given list of moves.
Expand Down
4 changes: 4 additions & 0 deletions chess/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,7 @@ def find_variant(name):
if any(alias.lower() == name.lower() for alias in variant.aliases):
return variant
raise ValueError("unsupported variant: {}".format(name))


# TODO: Deprecated
BB_HILL = chess.BB_CENTER
8 changes: 4 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,14 +1595,14 @@ def test_mirror(self):
def test_flip(self):
self.assertEqual(chess.flip_vertical(chess.BB_ALL), chess.BB_ALL)
self.assertEqual(chess.flip_horizontal(chess.BB_ALL), chess.BB_ALL)
self.assertEqual(chess.flip_diag(chess.BB_ALL), chess.BB_ALL)
self.assertEqual(chess.flip_anti_diag(chess.BB_ALL), chess.BB_ALL)
self.assertEqual(chess.flip_diagonal(chess.BB_ALL), chess.BB_ALL)
self.assertEqual(chess.flip_anti_diagonal(chess.BB_ALL), chess.BB_ALL)

s = chess.SquareSet(0x1e2222120e0a1222) # Letter R
self.assertEqual(chess.flip_vertical(s), 0x22120a0e1222221e)
self.assertEqual(chess.flip_horizontal(s), 0x7844444870504844)
self.assertEqual(chess.flip_diag(s), 0x000061928c88ff00)
self.assertEqual(chess.flip_anti_diag(s), 0x00ff113149860000)
self.assertEqual(chess.flip_diagonal(s), 0x000061928c88ff00)
self.assertEqual(chess.flip_anti_diagonal(s), 0x00ff113149860000)

def test_len_of_complenent(self):
squares = chess.SquareSet(~chess.BB_ALL)
Expand Down

0 comments on commit f4e146e

Please sign in to comment.