GithubHelp home page GithubHelp logo

torom / polyglot-writer Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 17 KB

Small code snippet to create polyglot books with python-chess.

License: GNU General Public License v3.0

Python 100.00%
chess polyglot python python-chess

polyglot-writer's Introduction

polyglot-writer

Small code snippet to create polyglot books with python-chess.

Usage

The Polyglot_Writer.write() function needs a list of Polyglot_Position and a path under which the book should be written.

A Polyglot_Position consists of the zobrist hash of the position, a Polyglot_Move, the weight and the learn values.

A Polyglot_Move is a move serialized to an integer. For this the Polyglot_Move.from_chess_move() function can be used.

Example

This example creates a polyglot book under the name example.bin. The book contains for the starting position the moves e4 and d4 with equal weighting and for the position after 1. e4 it contains e5 and c5 with equal weight.

import chess
from chess.polyglot import zobrist_hash

from polyglot_writer import Polyglot_Move, Polyglot_Position, Polyglot_Writer

polyglot_positions = [
    Polyglot_Position(zobrist_hash(board := chess.Board('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')),
                      Polyglot_Move.from_chess_move(board, chess.Move.from_uci('e2e4')),
                      65_535,
                      0),
    Polyglot_Position(zobrist_hash(board := chess.Board('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')),
                      Polyglot_Move.from_chess_move(board, chess.Move.from_uci('d2d4')),
                      65_535,
                      0),
    Polyglot_Position(zobrist_hash(board := chess.Board('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1')),
                      Polyglot_Move.from_chess_move(board, chess.Move.from_uci('e7e5')),
                      65_535,
                      0),
    Polyglot_Position(zobrist_hash(board := chess.Board('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1')),
                      Polyglot_Move.from_chess_move(board, chess.Move.from_uci('c7c5')),
                      65_535,
                      0)
]

Polyglot_Writer.write(polyglot_positions, 'example.bin')

Acknowledgements

Polyglot book format by Harm Geert Muller

License

This code is licensed under the GPLv3 (or any later version at your option). Check out the LICENSE file for the full text.

polyglot-writer's People

Contributors

torom avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.