{"id":15647643,"url":"https://github.com/dylhunn/dragontoothmg","last_synced_at":"2025-09-05T10:44:04.237Z","repository":{"id":57521437,"uuid":"89517999","full_name":"dylhunn/dragontoothmg","owner":"dylhunn","description":"A fast Go chess library. Legal move generation, move/board types, apply/unapply, FEN parsing, Zobrist hashing.","archived":false,"fork":false,"pushed_at":"2022-09-17T01:47:54.000Z","size":1065,"stargazers_count":48,"open_issues_count":4,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-26T00:41:28.530Z","etag":null,"topics":["chess","chess-board","chess-engine"],"latest_commit_sha":null,"homepage":"https://dylhunn.github.io/dragontoothmg/","language":"Go","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/dylhunn.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-26T19:17:18.000Z","updated_at":"2025-02-20T12:28:16.000Z","dependencies_parsed_at":"2022-09-26T18:30:41.932Z","dependency_job_id":null,"html_url":"https://github.com/dylhunn/dragontoothmg","commit_stats":null,"previous_names":["dylhunn/dragontooth-movegen"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylhunn%2Fdragontoothmg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylhunn%2Fdragontoothmg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylhunn%2Fdragontoothmg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylhunn%2Fdragontoothmg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dylhunn","download_url":"https://codeload.github.com/dylhunn/dragontoothmg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666975,"owners_count":21624412,"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","chess-board","chess-engine"],"created_at":"2024-10-03T12:20:26.958Z","updated_at":"2025-04-30T08:22:59.826Z","avatar_url":"https://github.com/dylhunn.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)\n[![Build Status](https://travis-ci.org/dylhunn/dragontoothmg.svg?branch=master)](https://travis-ci.org/dylhunn/dragontoothmg)\n[![Documentation](https://img.shields.io/badge/Documentation-GoDoc-green.svg)](https://godoc.org/github.com/dylhunn/dragontoothmg)\n\n\nDragontooth Movegen | Dylan D. Hunn\n==================================\n\nDragontooth Movegen is a fast, no-compromises chess move generator written entirely in Go. It provides a simple API for `GenerateLegalMoves()`. It also provides `Board` and `Move` types, `Apply()` and `Unapply()` functionality, and easy-to-use Zobrist-backed `hash`ing of board positions. FEN parsing/serializing and Move parsing/serializing are supported out of the box.\n\n`Dragontoothmg` is based on *magic bitboards* for maximum performance, and generates legal moves only using *pinned piece tables*.\n\n**This project is currently stable and fully functional.** Optimizations are underway, to improve on the benchmarks listed below.\n\nRepo summary\n============\n\nHere is a summary of the important files in the repo:\n\n| **File**         | **Description**                                                                                                                                         |\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| movegen.go   | This is the \"primary\" source file. Functions are located here if, and only if, they are performance critical and executed to generate moves in-game. |\n| types.go     | This file contains the Board and Moves types, along with some supporting helper functions and types.                                                 |\n| constants.go | All constants for move generation are hard-coded here, along with functions to compute the magic bitboard lookup tables when the file loads.         |\n| util.go      | This file contains supporting library functions, for FEN reading and conversions.                                                                    |\n| apply.go     | This provides functions to apply and unapply moves to the board. (Useful for Perft as well.)                                                         |\n| perft.go     | The actual Perft implementation is contained in this file.                                                                                           |\n\nAPI\n===\n\nHere are significant API calls that this library provides. For invocation details, see the [docs](https://godoc.org/github.com/dylhunn/dragontoothmg).\n\n| **Function**         | **Description**                                                                                                                                         |\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| GenerateLegalMoves   | A fast way to generate all moves in the current position. |\n| Board.Apply     | Apply a move to the board. Returns a function that allows it to be unapplied.                                                         |                                                      |\n| Perft     | Standard \"performance test,\" which recursively counts all of the moves from a position to a given depth.                                                         |\n| ParseFen     | Construct a Board from a standard chess FEN string.                                               |\n| Board.ToFen | Convert a Board to a standard FEN string.         |\n| Board.Hash     | Generate a hash value for a Board, using the Zobrist method.                                                                                           |\n| ParseMove     | Parse a long-algbraic notation move from a string.                                                                                           |\n| Move.String     | Convert a Move to a string, in normal long-algebraic notation.                                                                                           |\n\nInstalling and building the library\n===================================\n\nThis project requires Go 1.9. As of the time of writing, 1.9 is still a pre-release version. You can get it by cloning the official [Go Repo](https://github.com/golang/go), and building it yourself. There are [instructions for this](https://golang.org/doc/install/source). (Once Go 1.9 comes out in a few weeks, this will become unnecessary.)\n\nTo use this package in your own code, make sure your `GO_PATH` environment variable is correctly set, and install it using `go get`:\n\n    go get github.com/dylhunn/dragontoothmg\n\nThen, you can include it in your project:\n\n\timport \"github.com/dylhunn/dragontoothmg\"\n\nAlternatively, you can clone it yourself:\n\n    git clone https://github.com/dylhunn/dragontoothmg.git\n\nTesting and benchmarking\n========================\n\nTo run all tests, `cd` into the directory and use:\n\n\tgo test -v\n\nThe `-v` shows verbose progress output, since some of the Perft tests can take some time.\n\nTo run benchmarks:\n\n\tgo run bench/runbench.go\n\nCurrent benchmark results are around 60 million NPS (nodes per second) on a modern Intel i5. This [significantly outperforms](http://i68.tinypic.com/r8rwow.png) the best current Go chess engines, and is about 40% of the performance of the Stockfish move generator. (Not bad for a garbage-collected language!) Improvements are continually underway, and results will vary on your machine.\n\n![Sample Benchmark Results](/benchmarks.png?raw=true \"Sample Benchmark Results\")\n\nDocumentation and examples\n==========================\n\nYou can find the documentation [here](https://godoc.org/github.com/dylhunn/dragontoothmg).\n\nHere is a simple example invocation:\n\n    // Read a position from a FEN string\n    board := dragontoothmg.ParseFen(\"1Q2rk2/2p2p2/1n4b1/N7/2B1Pp1q/2B4P/1QPP4/4K2R b K e3 4 30\")\n    // Generate all legal moves\n    moveList := board.GenerateLegalMoves()\n    // For every legal move\n    for _, currMove := range moveList {\n        // Apply it to the board\n        unapplyFunc := board.Apply(currMove)\n        // Print the move, the new position, and the hash of the new position\n        fmt.Println(\"Moved to:\", \u0026currMove) // Reference converts Move to string automatically\n        fmt.Println(\"New position is:\", b.ToFen())\n        fmt.Println(\"This new position has Zobrist hash:\", board.Hash())\n        // Unapply the move\n        unapplyFunc()\n    }","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylhunn%2Fdragontoothmg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdylhunn%2Fdragontoothmg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylhunn%2Fdragontoothmg/lists"}