{"id":49288365,"url":"https://github.com/brighamskarda/chess","last_synced_at":"2026-05-02T02:02:02.751Z","repository":{"id":256447886,"uuid":"843210087","full_name":"brighamskarda/chess","owner":"brighamskarda","description":"Chess library in go","archived":false,"fork":false,"pushed_at":"2026-04-25T21:47:54.000Z","size":512,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-25T23:28:08.436Z","etag":null,"topics":["chess","golang","library"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/brighamskarda/chess/v2","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brighamskarda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-16T02:40:10.000Z","updated_at":"2025-10-09T06:42:10.000Z","dependencies_parsed_at":"2024-12-30T00:23:02.806Z","dependency_job_id":"9ffa8b4a-0db2-42d0-9d44-7d3d278697e2","html_url":"https://github.com/brighamskarda/chess","commit_stats":null,"previous_names":["brighamskarda/chess"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/brighamskarda/chess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brighamskarda%2Fchess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brighamskarda%2Fchess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brighamskarda%2Fchess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brighamskarda%2Fchess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brighamskarda","download_url":"https://codeload.github.com/brighamskarda/chess/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brighamskarda%2Fchess/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32520156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","golang","library"],"created_at":"2026-04-25T23:04:04.694Z","updated_at":"2026-05-02T02:02:02.740Z","avatar_url":"https://github.com/brighamskarda.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# brighamskarda/chess\n\n**chess** is a go module with useful utilities for playing and manipulating the game of chess. It was created to expand the selection of chess libraries available in golang. As of now, there are few fleshed out libraries that are documented and performant. Some of the functionality provided in this library includes:\n\n- Magic bitboard accelerated move generation\n- Pseudo-legal move generation\n- Legal move generation\n- FEN position parsing\n- Extensive PGN support\n- Bitboard utilities\n\n## Performance\n\nThis module is designed with performance in mind. It aims to be performant enough for engine development, while still being easy to use. Performance testing (Perft) is one way to test the performance and correctness of a chess library. It involves generating all legal moves for a position up to a certain depth. Perft(6) indicates the time for a library to generate all legal moves 6 plys deep.\n\n### Popular Go Chess Library Performance Comparison (In Seconds)\n\n| Repository            | Starting Position (Perft 6) | KiwiPete Position (Perft 5) | End Position (Perft 6) |\n| --------------------- | --------------------------- | --------------------------- | ---------------------- |\n| brighamskarda/chess   | 7.58                        | 12.04                       | 0.69                   |\n| CorentinGS/chess      | 32.49                       | 52.94                       | 4.95                   |\n| dylhunn/dragontoothmg | 1.44                        | 1.46                        | 0.22                   |\n| keelus/chess          | 435                         | \\*                          | 37.86                  |\n| malbrecht/chess       | 77.39                       | 147.97                      | 5.44                   |\n| eightsquared/chess    | 7.075                       | 22.35                       | 1.01                   |\n\n\u003csub\u003eAll tests done on an Intel I7-1265U (I know a laptop is not the best for benchmarks, but you can at least get a general idea for how each of the libraries perform)\u003c/sub\u003e\n\n\u003csub\u003eStarting Position - `rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1`\u003c/sub\u003e\n\n\u003csub\u003eKiwi Pete Position - `r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1` (a popular midgame position for testing)\u003c/sub\u003e\n\n\u003csub\u003eEnd Position - `8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1`\u003c/sub\u003e\n\nOf course there are other hyper-specialized go programs and libraries that are able to achieve even faster times (such as [this one](https://github.com/bluescreen10/chester) which claims 300ms for perft 6 from the starting position). For this list I am looking at libraries that show up in the first couple pages of search results, and that provide a usable API with at least some documentation. If you have a library you think should be here let me know.\n\nBut as the results show this library is one of the quickest. Notably it is about **4x** as fast as _CorentingGS/chess_ (a fork of notnil/chess that focuses on reducing memory allocations). _dylhunn/dragontoothmg_ is an amazing library for pure speed if that is what you are looking for. It lacks PGN utilities though.\n\nThe fastest time I got for Perft 6 from the starting position was 6.5 seconds. Utilizing profile-guided optimization (PGO) seems to give about a 10-12% improvement for this code.\n\n## Future Development\n\nThere is still a lot of work to do to make this library as great as possible. Currently there are two future releases planned.\n\n- v2.1 - UCI support to aid engine development\n- v2.2 - Chess 960 support\n\n## Contributing\n\nI'm open to suggestions and contributions. Feel free to post them on github issues and pull requests. You can also email me directly at [brighamskarda@gmail.com](mailto:brighamskarda@gmail.com). Also take a look at [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## Usage\n\nYou can find the full documentation at \u003chttps://pkg.go.dev/github.com/brighamskarda/chess/v2\u003e. Here are a few useful tips though:\n\n- Use the **Game** type to play, and keep track of your games. This struct is how you can read and manipulate PGN's.\n- Use the **Position** type for high performance applications. Using Position.Move is much faster than Game.Move since it doesn't validate the move, or keep a history.\n- If your developing an engine, use **Position.Bitboard** to get bitboards for pieces and colors. Bit operations can accelerate your engine.\n\n### Example Game Against Dumb Computer\n\n```go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/brighamskarda/chess/v2\"\n)\n\nfunc main() {\n\t// Initialize a new game of chess\n\tmyGame := chess.NewGame()\n\t// Get input reader\n\tinput := bufio.NewReader(os.Stdin)\n\n\t// Game Loop\n\tfor !myGame.IsStalemate() \u0026\u0026 !myGame.IsCheckmate() {\n\t\tcurrentPosition := myGame.Position()\n\t\tif currentPosition.SideToMove == chess.White {\n\t\t\t// Player plays white\n\t\t\tfmt.Println(currentPosition.String(true, false))\n\t\t\tfmt.Print(\"Enter Move (\u003csquare1\u003e\u003csquare2\u003e\u003cpromotion\u003e): \")\n\t\t\tplayerInput, _ := input.ReadString('\\n')\n\t\t\tplayerInput = strings.TrimSpace(playerInput)\n\t\t\t// MoveUCI automatically parses the players move\n\t\t\terr := myGame.MoveUCI(playerInput)\n\t\t\tif err != nil {\n\t\t\t\tfmt.Println(\"Invalid Move\")\n\t\t\t}\n\t\t} else if currentPosition.SideToMove == chess.Black {\n\t\t\t// Computer plays the first legal move it sees\n\t\t\tlegalMoves := myGame.LegalMoves()\n\t\t\tmyGame.Move(legalMoves[0])\n\t\t\tfmt.Printf(\"\\nBlack performed move %v\\n\\n\", legalMoves[0])\n\t\t}\n\t}\n\n\t// Game detected stalemate or checkmate, so we print the result.\n\tswitch myGame.Result {\n\tcase chess.Draw:\n\t\tfmt.Println(\"Draw\")\n\tcase chess.WhiteWins:\n\t\tfmt.Println(\"White Wins\")\n\tcase chess.BlackWins:\n\t\tfmt.Println(\"Black Wins\")\n\tdefault:\n\t\tpanic(\"game ended without result.\")\n\t}\n}\n```\n\n## Attributions\n\nHuge thanks to Chess Programming and his example implementation of magic bitboards. It was extremely useful. \u003chttps://youtu.be/4ohJQ9pCkHI?si=4QQG2BntrELO2JYi\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrighamskarda%2Fchess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrighamskarda%2Fchess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrighamskarda%2Fchess/lists"}