{"id":15288274,"url":"https://github.com/lpapailiou/chess","last_synced_at":"2025-07-25T09:31:37.149Z","repository":{"id":48826448,"uuid":"243834441","full_name":"lpapailiou/chess","owner":"lpapailiou","description":"A chess game in java, allowing to play against an ai opponent.","archived":false,"fork":false,"pushed_at":"2021-07-09T17:27:23.000Z","size":10562,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T04:22:51.565Z","etag":null,"topics":["ai","artifical-intelligence","chess","chess-game","java","java-8","javafx","javafx-application","javafx-desktop-apps","javafx-games","javafx-gui","minimax","minimax-algorithm","minimax-chess"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lpapailiou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-28T19:01:49.000Z","updated_at":"2024-12-17T20:57:47.000Z","dependencies_parsed_at":"2022-09-23T22:22:36.562Z","dependency_job_id":null,"html_url":"https://github.com/lpapailiou/chess","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lpapailiou/chess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpapailiou%2Fchess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpapailiou%2Fchess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpapailiou%2Fchess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpapailiou%2Fchess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lpapailiou","download_url":"https://codeload.github.com/lpapailiou/chess/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpapailiou%2Fchess/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266985820,"owners_count":24017002,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"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":["ai","artifical-intelligence","chess","chess-game","java","java-8","javafx","javafx-application","javafx-desktop-apps","javafx-games","javafx-gui","minimax","minimax-algorithm","minimax-chess"],"created_at":"2024-09-30T15:45:12.602Z","updated_at":"2025-07-25T09:31:36.383Z","avatar_url":"https://github.com/lpapailiou.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# README\r\n\r\nThis is a __chess game__ written in java 8, using a javafx ui.\r\n\r\nThe goal was to create a user-friendly game which allows the user to play against a computer opponent. \r\nAlso, games can be exported or imported in FEN or PGN.\r\n\r\n## Table of Contents\r\n1. [About the game](#about-the-game)  \r\n\t1.1 [Before you start the game](#before-you-start-the-game)  \r\n\t1.2 [The game](#the-game)  \r\n\t\t1.2.1 [The AI opponent](#the-ai-opponent)  \r\n\t\t1.2.2 [Chess notations](#chess-notations)  \r\n\t\t1.2.3 [Editing a game](#editing-a-game)  \r\n\t\t1.2.4. [Thoughts about this project](#thoughts-about-this-project)  \r\n2. [Project structure](#project-structure)  \r\n3. [How to get it](#how-to-get-it)  \r\n\r\n## About the game\r\n### Before you start the game\r\n![screenshot of settings screen](https://github.com/lpapailiou/chess/blob/master/src/com/chess/resources/img/chess_screenshots_settings.png)\r\n\r\nBefore the game starts, you will be able to adjust some parameters:\r\n* __Color choice__: pieces of chosen color will be initialized at the bottom\r\n* __Rule choice__: as there are some not-sure-if-I-like-this-rules, specific rules can be deactivated\r\n* __Mode choice__: choose how players are controlled (by you or AI)\r\n* __Difficulty choice__: the AI player difficulty can be controlled here. the highest setting is around the difficulty level 5-6 of Chess.com\r\n* __Load__: here, you can load existing games from FEN or PGN code\r\n\r\n### The game\r\n![screenshot of game](https://github.com/lpapailiou/chess/blob/master/src/com/chess/resources/img/chess_screenshots_game.png)\r\n\r\nThe game can be played by clicking or by using drag\u0026drop. For more information about how to handle the application see the [manual](https://github.com/lpapailiou/chess/blob/master/src/com/chess/resources/manual.html). If you are not very familiar with the chess game itself, there is an additional file which quickly explains the [rules](https://github.com/lpapailiou/chess/blob/master/src/com/chess/resources/rules.html).\r\n\r\n#### The AI opponent\r\nThe AI opponent was created by using a minimax algorithm with alpha-beta-pruning. This means, that the opponent will simulate a few moves ahead and then choose the move which seems to avoid the worst situation while maximizing the chance to win.\r\n\r\nThe algorithm takes following to account:\r\n* Recursion depth (steps of simulating moves ahead)\r\n* Heuristics to add recursion depth for the endgame\r\n* Piece values (e.g. a queen is valued higher than a pawn)\r\n* Piece position values (e.g. a knight is valued higher when positioned at the center of the board, as it has more move options there)\r\n* So called 'spasm-parameter', which will generate random moves occasionally to appear more human\r\n* Library of known chess openings to obtain a good starting position\r\n* Heuristics to avoid a a draw by stalemate\r\n* Heuristics to avoid a draw by threefold repetition\r\n* Heuristics to avoid a draw by 50 'moves of no value'\r\n\r\nDepending on the rule and difficulty settings, the behavior of the AI opponent will change accordingly.\r\nExample: On the highest difficulty setting we have a recursion depth of 4, while on the lowest difficulty setting we have a no recursion at all.\r\n\r\nAs the recursion depth has a huge impact on the speed of the caluclations (which increases exponentially), the maximum depth of 4 seemed a suitable compromise to get a more-or-less smart opponent, without having to wait 100 years for the next move.\r\n\r\n#### Chess notations\r\nDuring the game, the moves are logged to the console and can be exported as html file. Here, the __long algebraic notation (LAN)__ is used.  \r\nExample for LAN: \r\n\r\n     e2-e4\r\n\r\nFor importing and exporting games, the __FEN__ and __PGN__ notations are used. These notations are widely used for chess games.    \r\n  \r\nThe __FEN__ notation is a very compact one-line-code for a current board situation. It is useful if a board state should be quickly copied to be recreated later and/or in another chess program.  \r\nExample for FEN: \r\n\r\n    rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\r\n\r\nThe __PGN__ notation is more complex. It contains metadata about the game (players, location, round, etc.) and the complete list of moves. This means, a whole game can be recreated step by step, which is useful if you want to do analyzes.  \r\nExample for PGN:\r\n\r\n    [Event \"Casual waste of time\"]\r\n    [Site \"Your cave, SWITZERLAND\"]\r\n    [Date \"2019.12.08\"]\r\n    [Round \"2\"]\r\n    [White \"Thought, Deep\"]\r\n    [Black \"Blue, Deep\"]\r\n    [Result \"0:1\"]\r\n    \r\n    1. f4 d5 2. Nc3 d4 3. Nb5 a6 4. Na3 Bg4 5. h3 Bh5 6. d3 Nd7\r\n    7. Bd2 e6 8. Nc4 Qh4+ 9. g3 Qxg3# 0:1\r\n\r\n#### Editing a game\r\nI really hated to implement this feature, as in a real chess game, steps should not be undone. Still, it's cool for whait-what-happened-moments or analyzing already played games.\r\n\r\n#### Thoughts about this project\r\nI did this project for fun and curiosity. The main motivation I was driven by was 'how do I get a nice chess game with a really smart AI' (and so far, I was not able to beat the AI myself).\r\nAs you will see in the code, many of the features (e.g. exports, edit mode) grew in in a quite organic way. If I was more serious about it, the architecture should have been restructured accordingly. \r\nThe main issue of the AI opponent is the speed of the calculations, which limits the recursion depth to 4. Recursion depth could be increased if the move generation handling would be closer to machine code (i.e. bit shifting methods). After all, Java might not be the best programming language for that purpose.\r\nAnother issue is testability. As the coupling is not loose enough, I was not going too far with unit tests.\r\nSome other time, I will do further work here or start again from scratch.\r\n\r\n## Project structure\r\n\r\n* ``com.chess.application``     this package contains the main method (in ``Chess.java``), as well as gui related classes\r\n* ``com.chess.model``               enums, container classes, data classes\r\n* ``com.chess.resources``        text and image files\r\n* ``com.chess.root``        \t       contains the 'game engine' (pieces, board, game handling, AI logic)\r\n\r\n## How to get it\r\n\r\nClone the repository with:\r\n\r\n    git clone https://github.com/lpapailiou/chess your-target-path\r\n\r\nFor further help, click [here](https://gist.github.com/lpapailiou/d4d63338ccb1413363970ac571aa71c9).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpapailiou%2Fchess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flpapailiou%2Fchess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpapailiou%2Fchess/lists"}