{"id":18840012,"url":"https://github.com/geeekyboy/royal-chess","last_synced_at":"2025-09-03T04:31:44.520Z","repository":{"id":43832937,"uuid":"332572291","full_name":"GeeekyBoy/royal-chess","owner":"GeeekyBoy","description":"A chess game powered by SDL2.","archived":false,"fork":false,"pushed_at":"2022-07-07T22:41:43.000Z","size":27195,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T07:41:33.649Z","etag":null,"topics":["c","chess","chess-engine","chess-game","chessboard","sdl2","sdl2-mixer","sdl2-ttf","svg","windows"],"latest_commit_sha":null,"homepage":"","language":"C","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/GeeekyBoy.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":"2021-01-24T22:41:38.000Z","updated_at":"2025-02-09T17:49:46.000Z","dependencies_parsed_at":"2022-09-22T06:02:01.498Z","dependency_job_id":null,"html_url":"https://github.com/GeeekyBoy/royal-chess","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/GeeekyBoy/royal-chess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeeekyBoy%2Froyal-chess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeeekyBoy%2Froyal-chess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeeekyBoy%2Froyal-chess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeeekyBoy%2Froyal-chess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GeeekyBoy","download_url":"https://codeload.github.com/GeeekyBoy/royal-chess/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeeekyBoy%2Froyal-chess/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273391909,"owners_count":25097254,"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-09-03T02:00:09.631Z","response_time":76,"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":["c","chess","chess-engine","chess-game","chessboard","sdl2","sdl2-mixer","sdl2-ttf","svg","windows"],"created_at":"2024-11-08T02:44:44.190Z","updated_at":"2025-09-03T04:31:42.353Z","avatar_url":"https://github.com/GeeekyBoy.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Royal Chess\n\n![main](https://github.com/GeeekyBoy/royal-chess/workflows/main/badge.svg)\n\n![](./img/textLogo.png)\n\n## Table Of Contents:\n\n* [Overview](#overview)\n* [Features](#features)\n* [Screenshots](#screenshots)\n* [Compatibility](#compatibility)\n* [Build Instructions](#build-instructions)\n* [Test Cases](#test-cases)\n* [Data Structures](#data-structures)\n* [Pseudocode Of Important Functions](#pseudocode-of-important-functions)\n* [Visual Pseudocode (aka. Flowchart)](#visual-pseudocode-aka-flowchart)\n* [Credits](#credits)\n* [License](#license)\n\n## Overview\n\n*Royal Chess* is an open source 2D chess game made with *Simple DirectMedia Layer* 2. Its source code is completely written using the most recent standard for C programming language *(C17)*. We believe that this repository is a good starting point for everyone who wants to develop a real game using SDL2. *Royal Chess* is different from most of other SDL2-based games, becuase all of the resources are bundled with the game in one executable file, in addition to the prevention of pixelation of images by including them as SVG files.\n\n## Features\n\n* A fully functional chess game made with *SDL2*.\n* Supported by well-selected sound effects.\n* Customized cursor matching the royal design of the game.\n* Customized loading screen to promote yourself.\n* Game can be run in either Fullscreen mode or Windowed mode.\n* Supports any resolution that is a multiplier of (640*480).\n* All images and textures are included as SVG files.\n* All assets are bundled with the actual game in one executable file.\n* Showing the algebraic notations of every played move during the game.\n* Supports undoing game till the first move or redoing it till the last move.\n* Game can be saved locally to be continued later.\n* Saved game includes its movements history.\n* Showing all possible moves that can be moved by the selected piece.\n* Chess board is rotated when the second player should play.\n* Possibility of starting a new game without toothing the existing saved game.\n* Supports *En Passant* and *Castling* moves.\n* Supports pawn promotion.\n* Detection of dead position in case one of the following conditions is met:\n  * king versus king.\n  * king and bishop versus king.\n  * king and knight versus king.\n  * king and bishop versus king and bishop with the bishops on the same color.\n* Game can be ended by one of the following means:\n  * Checkmate\n  * Stalemate\n  * Dead Position\n  * Draw Offer\n  * Resign\n* Once a game is ended, a PGN file for this game is saved automatically.\n\n## Screenshots\n\n![](./img/mainMenu.png)\n\n![](./img/gameplay.png)\n\n![](./img/promotion.png)\n\n![](./img/saveGame.png)\n\n![](./img/saveCompleted.png)\n\n![](./img/victory.png)\n\n![](./img/gameDrawn.png)\n\n![](./img/exitGame.png)\n\n![](./img/drawOffer.png)\n\n## Compatibility\n\n*Royal Chess* is supposed to work on all platforms supported by [SDL2](https://wiki.libsdl.org/Installation). However, It was tested only on the following operating systems:\n\n* Microsoft Windows 2000 Service Pack 4 ***(SDL2 have to be recompiled with SDL_Log removed)***\n* Microsoft Windows XP Service Pack 3\n* Microsoft Windows 7 Service Pack 1\n* Microsoft Windows 10 Insider Preview Build 21292\n\n![](./img/WindowsXP.png)\n\n![](./img/Windows7.png)\n\n![](./img/Windows10.png)\n\n## Build Instructions\n\n### Github Workflow\n\nThis project comes with a ready Github workflow that builds *Royal Chess* automatically on every commit then pushes the compiled as a release called *Nightly Builds*.\n\n### Windows\n\nIn order to build *Royal Chess* for 32bit and 64bit versions of *Windows*, you have to follow the following procedure. ***You may skip some steps if you have done them already !***\n\n1. Install *MSYS2* from https://www.msys2.org/\n\n2. Run *MSYS2*.\n\n3. Execute commands below in order to get *GCC* and SDL2 installed.\n\n```bash\n   pacman -S --needed base-devel mingw-w64-x86_64-toolchain\n   pacman -S --needed base-devel mingw-w64-i686-toolchain\n   pacman -S mingw64/mingw-w64-x86_64-SDL2\n   pacman -S mingw32/mingw-w64-i686-SDL2\n   pacman -S mingw64/mingw-w64-x86_64-SDL2_mixer\n   pacman -S mingw32/mingw-w64-i686-SDL2_mixer\n   pacman -S mingw64/mingw-w64-x86_64-SDL2_ttf\n   pacman -S mingw32/mingw-w64-i686-SDL2_ttf\n```\n\n4. Within *MSYS2* terminal, go to the root of *Royal Chess* source code where *Makefile* exists.\n\n5. Execute the command below.\n\n```bash\n   make\n```\n\n## Test Cases\n\n### Jonathan F Parker vs Nicholas Pert (1999)\n\n**This game was ended by a resign.**\n\n```\n[Event \"Royal Chess\"]\n[Site \"Personal Computer\"]\n[Date \"2021.01.22\"]\n[Round \"1\"]\n[White \"Player 1\"]\n[Black \"Player 2\"]\n[PlyCount \"64\"]\n[Result \"0-1\"]\n\n1.d2d4 e7e6 2.c2c4 f7f5 3.g2g3 Ng8f6 4.Bf1g2 Bf8e7 5.Ng1f3 O-O 6.O-O Nf6e4 7.d4d5 Be7f6 8.Nf3d2 Ne4xd2 9.Qd1xd2 Qd8e7 10.Nb1c3 Bf6xc3 11.Qd2xc3 e6e5 12.b2b3 d7d6 13.c4c5 b7b6 14.c5c6 a7a5 15.a2a3 f5f4 16.Bc1b2 Nb8a6 17.b3b4 Bc8g4 18.Ra1e1 Ra8e8 19.Qc3c4 Bg4c8 20.Bb2c1 Qe7g5 21.f2f3 Rf8f6 22.Rf1f2 Rf6h6 23.g3g4 Qg5h4 24.h2h3 Qh4g3 25.e2e3 a5xb4 26.a3xb4 Rh6xh3 27.b4b5 Na6c5 28.e3xf4 Rh3h2 29.Re1e2 e5e4 30.f4f5 Kg8f7 31.f3xe4 Nc5d3 32.Qc4c3 Rh2h1+\n```\n\n### James Adams Congdon vs Eugene Delmar (1880)\n\n**This game was ended by a stalemate.**\n\n```\n[Event \"Royal Chess\"]\n[Site \"Personal Computer\"]\n[Date \"2021.01.22\"]\n[Round \"1\"]\n[White \"Player 1\"]\n[Black \"Player 2\"]\n[PlyCount \"88\"]\n[Result \"1/2-1/2\"]\n\n1.e2e4 e7e5 2.Ng1f3 Nb8c6 3.Bf1b5 Nc6d4 4.Nf3xd4 e5xd4 5.O-O c7c6 6.Bb5c4 Ng8f6 7.d2d3 d7d5 8.e4xd5 Nf6xd5 9.Rf1e1+ Bf8e7 10.Qd1e2 Bc8e6 11.c2c3 d4xc3 12.Nb1xc3 O-O 13.Bc4xd5 c6xd5 14.b2b3 Be7f6 15.Bc1b2 Ra8c8 16.Ra1c1 Qd8a5 17.Nc3a4 d5d4 18.h2h3 Qa5g5 19.Qe2f3 b7b5 20.h3h4 Qg5d2 21.Re1d1 Rc8xc1 22.Bb2xc1 Qd2xa2 23.Na4c5 Bf6xh4 24.g2g3 Bh4e7 25.Nc5xe6 f7xe6 26.Bc1f4 Qa2xb3 27.Rd1c1 e6e5 28.Qf3b7 e5xf4 29.Qb7xe7 f4xg3 30.f2xg3 Qb3xd3 31.Qe7e6+ Kg8h8 32.Rc1c8 Qd3xg3+ 33.Kg1h1 Qg3f3+ 34.Kh1h2 h7h6 35.Rc8xf8+ Qf3xf8 36.Qe6e4 Qf8d8 37.Qe4d3 b5b4 38.Kh2g2 a7a5 39.Kg2f2 a5a4 40.Kf2e2 a4a3 41.Qd3b3 d4d3+ 42.Ke2d2 Qd8d4 43.Kd2d1 Qd4c3 44.Qb3g8+ Kh8xg8\n```\n\n### Ossip Bernstein vs Jose Raul Capablanca (1914)\n\n**This game was ended by a resign.**\n\n```\n[Event \"Royal Chess\"]\n[Site \"Personal Computer\"]\n[Date \"2021.01.23\"]\n[Round \"1\"]\n[White \"Player 1\"]\n[Black \"Player 2\"]\n[PlyCount \"58\"]\n[Result \"0-1\"]\n\n1.d2d4 d7d5 2.c2c4 e7e6 3.Nb1c3 Ng8f6 4.Ng1f3 Bf8e7 5.Bc1g5 O-O 6.e2e3 Nb8d7 7.Ra1c1 b7b6 8.c4xd5 e6xd5 9.Qd1a4 Bc8b7 10.Bf1a6 Bb7xa6 11.Qa4xa6 c7c5 12.Bg5xf6 Nd7xf6 13.d4xc5 b6xc5 14.O-O Qd8b6 15.Qa6e2 c5c4 16.Rf1d1 Rf8d8 17.Nf3d4 Be7b4 18.b2b3 Ra8c8 19.b3xc4 d5xc4 20.Rc1c2 Bb4xc3 21.Rc2xc3 Nf6d5 22.Rc3c2 c4c3 23.Rd1c1 Rc8c5 24.Nd4b3 Rc5c6 25.Nb3d4 Rc6c7 26.Nd4b5 Rc7c5 27.Nb5xc3 Nd5xc3 28.Rc2xc3 Rc5xc3 29.Rc1xc3 Qb6b2\n```\n\n### Albert Sandrin vs Phil Le Cornu (1949)\n\n**This game was ended by a checkmate.**\n\n```\n[Event \"Royal Chess\"]\n[Site \"Personal Computer\"]\n[Date \"2021.01.23\"]\n[Round \"1\"]\n[White \"Player 1\"]\n[Black \"Player 2\"]\n[PlyCount \"55\"]\n[Result \"1-0\"]\n\n1.c2c4 Ng8f6 2.Nb1c3 d7d5 3.c4xd5 Nf6xd5 4.g2g3 g7g6 5.Bf1g2 Bc8e6 6.Ng1f3 Nd5xc3 7.b2xc3 Bf8g7 8.O-O O-O 9.d2d4 c7c6 10.e2e4 Be6c4 11.Rf1e1 Nb8d7 12.Bc1e3 Qd8a5 13.Nf3d2 Bc4a6 14.Qd1b3 c6c5 15.e4e5 c5xd4 16.c3xd4 Nd7b6 17.Ra1c1 Ra8c8 18.Rc1c5 Rc8xc5 19.d4xc5 Nb6d7 20.e5e6 Nd7xc5 21.e6xf7+ Kg8h8 22.Qb3d5 b7b6 23.Be3d4 Nc5d3 24.Re1xe7 Qa5xd2 25.Re7e8 h7h6 26.Re8xf8+ Kh8h7 27.Rf8h8+ Bg7xh8 28.f7f8=N#\n```\n\n### Frank Melville Teed vs Eugene Delmar (1896)\n\n**This game was ended by a checkmate.**\n\n```\n[Event \"Royal Chess\"]\n[Site \"Personal Computer\"]\n[Date \"2021.01.23\"]\n[Round \"1\"]\n[White \"Player 1\"]\n[Black \"Player 2\"]\n[PlyCount \"15\"]\n[Result \"1-0\"]\n\n1.d2d4 f7f5 2.Bc1g5 h7h6 3.Bg5f4 g7g5 4.Bf4g3 f5f4 5.e2e3 h6h5 6.Bf1d3 Rh8h6 7.Qd1xh5+ Rh6xh5 8.Bd3g6#\n```\n\n### Milan Vidmar vs Geza Maroczy (1932)\n\n**This game is drawn due to a dead position.**\n\n```\n[Event \"Royal Chess\"]\n[Site \"Personal Computer\"]\n[Date \"2021.01.23\"]\n[Round \"1\"]\n[White \"Player 1\"]\n[Black \"Player 2\"]\n[PlyCount \"253\"]\n[Result \"1/2-1/2\"]\n\n1.d2d4 d7d5 2.c2c4 e7e6 3.Ng1f3 c7c5 4.c4xd5 e6xd5 5.g2g3 Nb8c6 6.Bf1g2 Ng8f6 7.O-O Bf8e7 8.Nb1c3 O-O 9.d4xc5 d5d4 10.Nc3b5 Be7xc5 11.Bc1f4 a7a6 12.Ra1c1 Bc5b6 13.Nb5d6 Nf6h5 14.Nd6xc8 Ra8xc8 15.Bf4g5 Qd8d5 16.g3g4 h7h6 17.Bg5xh6 g7xh6 18.g4xh5 Qd5xa2 19.Nf3h4 Qa2e6 20.Qd1d3 Qe6f6 21.Nh4f5 Kg8h8 22.Nf5g3 Rf8e8 23.Qd3b3 Nc6a5 24.Qb3a4 Qf6e7 25.Bg2e4 Rc8xc1 26.Rf1xc1 Re8g8 27.Qa4c2 Qe7b4 28.Be4d5 d4d3 29.e2xd3 Bb6d4 30.Rc1f1 Qb4d6 31.Bd5g2 f7f5 32.Kg1h1 Qd6f6 33.Qc2c7 f5f4 34.Qc7xa5 f4xg3 35.f2xg3 Qf6e5 36.Qa5xe5+ Bd4xe5 37.Bg2xb7 Be5xb2 38.Bb7xa6 Rg8g5 39.Rf1b1 Bb2f6 40.Rb1b5 Rg5xb5 41.Ba6xb5 Bf6d4 42.Kh1g2 Kh8g7 43.Kg2f3 Kg7f6 44.Kf3e4 Bd4g1 45.h2h3 Bg1f2 46.g3g4 Bf2g1 47.Ke4d5 Bg1f2 48.Kd5d6 Bf2e3 49.Kd6d7 Be3f2 50.Kd7e8 Bf2c5 51.Bb5c6 Kf6g7 52.Bc6e4 Kg7f6 53.Be4g6 Kf6g7 54.Ke8d7 Kg7f6 55.Kd7c6 Bc5f2 56.Kc6d5 Bf2g1 57.Bg6f5 Bg1f2 58.Kd5e4 Bf2g1 59.d3d4 Bg1f2 60.d4d5 Bf2c5 61.Ke4d3 Kf6e5 62.Bf5e6 Bc5e7 63.Kd3c4 Be7f8 64.Kc4d3 Bf8c5 65.Kd3c4 Bc5e7 66.Be6f5 Be7f8 67.Bf5b1 Bf8e7 68.Bb1a2 Be7f8 69.Kc4d3 Bf8c5 70.Ba2b3 Bc5e7 71.Kd3e3 Be7c5+ 72.Ke3f3 Bc5e7 73.Bb3a2 Be7f8 74.Kf3e2 Bf8e7 75.Ke2d3 Be7f8 76.Kd3c4 Bf8e7 77.Ba2b1 Be7f8 78.Bb1f5 Bf8e7 79.Bf5e6 Be7f8 80.Be6d7 Bf8e7 81.Bd7c8 Be7f8 82.Bc8e6 Bf8e7 83.Kc4b5 Ke5d6 84.Be6g8 Be7f8 85.Kb5c4 Kd6e5 86.Kc4d3 Bf8e7 87.Kd3e3 Be7c5+ 88.Ke3f3 Bc5e7 89.Kf3g3 Be7f8 90.Bg8f7 Bf8e7 91.Kg3f2 Be7c5+ 92.Kf2e2 Bc5e7 93.Ke2d3 Be7f8 94.Kd3c4 Bf8e7 95.Kc4b5 Ke5d6 96.Bf7e6 Be7f8 97.Kb5b6 Bf8e7 98.Kb6b7 Be7h4 99.Kb7a6 Bh4d8 100.Ka6b5 Bd8e7 101.Kb5c4 Kd6e5 102.Kc4d3 Be7f8 103.Kd3e3 Bf8c5+ 104.Ke3f3 Bc5f8 105.Kf3g3 Bf8e7 106.Be6g8 Be7f8 107.h3h4 Bf8e7 108.Bg8f7 Be7d8 109.Kg3h3 Bd8e7 110.Bf7g8 Ke5f6 111.Bg8e6 Kf6e5 112.Be6f7 Ke5f6 113.Bf7e8 Kf6e5 114.Be8f7 Ke5f6 115.Bf7g8 Kf6e5 116.g4g5 h6xg5 117.h5h6 Ke5f6 118.h4h5 Be7f8 119.Kh3g4 Bf8xh6 120.d5d6 Bh6f8 121.d6d7 Bf8e7 122.h5h6 Kf6g6 123.h6h7 Kg6g7 124.h7h8=B+ Kg7xh8 125.d7d8=B Kh8xg8 126.Bd8c7 Be7d6 127.Kg4xg5\n```\n\n## Data Structures\n\n### Game Data\n\n#### int player\n\nA variable indicating the current player. It has two possible values: *1* or *2*.\n\n#### PlayerState playerState\n\nThe state of the current player. It can be one of the following values: *NONE*, *CHECK*, *CHECKMATE*, *STALEMATE* or *DEAD_POSITION*.\n\n#### Coordinate kingPos[2]\n\nIt is an array of 2 coordinates. The first coordinate represents the current position of the white king, while the other represents that of the black king.\n\n#### Step *undoData\n\nA dynamic array holding all the information required to undo/redo game.\n\n#### int undoDataSize\n\nNumber of steps saved within *Undo Data*.\n\n#### int nextUndoIndex\n\nIndex of step that is going to be redone next time the user wants to undo the last move.\n\n#### char capturedPieces\\[2\\]\\[15\\]\n\nA 2D array holding pieces captured by both players. The first sub-array contains pieces captured by second player, while the second one contains those captured by first player.\n\n#### int capturedNum\\[2\\]\n\nA 1D Array of 2 items. The first item represents number of pieces captured by second player, while the second one represents number of those captured by first player.\n\n#### _Bool castlingData\\[2\\]\\[3\\]\n\nA 2D array consisting of 2 sub-arrays of 3 Booleans each. It holds information required to know if each one of kings and rooks is qualified for doing castling or not. The couple of sub-arrays represents the two players. The first one of 3 Booleans tells us if rook standing on column *0* hasn’t been moved before or not. The second Boolean tells us if king hasn’t been moved before or not. The last tells us if rook standing on column *7* hasn’t been moved before or not. The initial value of this array can be found below.\n\n```c\n  {\n  \t{1, 1, 1},\n  \t{1, 1, 1}\n  }\n```\n\n#### Coordinate enPassantData\n\nCoordinates of the skipped square by a pawn during the last move. If there is no skipped squares, its value will be (-1, -1).\n\n#### char boardData\\[8\\]\\[8\\]\n\nA 2D matrix representing the actual chess board. White and black pieces are represented by lowercase letters and uppercase letters respectevely. Empty squares *aka. DUMP_PIECE* are represented by a single dot. The initial value of this matrix can be found below.\n\n```c\n  {{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},\n  {'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},\n  {'.', '.', '.', '.', '.', '.', '.', '.'},\n  {'.', '.', '.', '.', '.', '.', '.', '.'},\n  {'.', '.', '.', '.', '.', '.', '.', '.'},\n  {'.', '.', '.', '.', '.', '.', '.', '.'},\n  {'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},\n  {'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'}}\n```\n\n### Step\n\n#### char firstPiece\n\nThe moving piece.\n\n#### Coordinate firstSquare\n\nCoordinates of the initial square of the moving piece.\n\n#### char secondPiece\n\nPiece standing on the destination of the moving piece.\n\n#### Coordinate secondSquare\n\nCoordinates of the destination of the moving piece.\n\n#### int capturedPlayer\n\nNumber of player whose piece was captured during this step. Its value is 0 in case no pieces were captured during this step.\n\n#### char newRank\n\nPreserves the new rank of a pawn promoted during that step to use it in redoing that step. It has no values in case no promotions occurred during this step. \n\n#### _Bool castlingData\\[2\\]\\[3\\]\n\nPreserves castling data of this step.\n\n#### Coordinate enPassantData\n\nPreserves en passant data of this step.\n\n#### PlayerState playerState\n\nPreserves player state during this step.\n\n#### char algebraicData\\[10\\]\n\nHolds algebraic notation of the move happened during this step.\n\n### Coordinate\n\n#### int row\n\nAn integer representing row where the required square exists. *(From 0 to 7)*\n\n#### int col\n\nAn integer representing column where the required square exists. *(From 0 to 7)*\n\n### GameInstance\n\n#### SDL_bool running\n\nA Boolean variable telling us if game should starts or not. Used to know when to start drawing frames and when to stop.\n\n#### screen \u003e unsigned int w\n\nWidth of the current window.\n\n#### screen \u003e unsigned int h\n\nHeight of the current window.\n\n#### screen \u003e const char *name\n\nName of the current window.\n\n#### screen \u003e SDL_Window *window\n\nA pointer to the current window.\n\n#### screen \u003e SDL_Renderer *renderer\n\nA pointer to the main and the only renderer.\n\n#### void (*init)(void)\n\nA pointer to the the function initializing the game.\n\n#### void (*quit)(void)\n\nA pointer to the the function quitting the game.\n\n### Image\n\n#### SDL_Texture *tex\n\nThe actual image stored as *SDL_Texture*.\n\n#### int width\n\nOriginal width of the image.\n\n#### int height\n\nOriginal height of the image. \n\n## Windows \u0026 Dialogs\n\n*Royal Chess* has 10 different windows. To make development of the game easier, they are represented by an enumeration called *GameWindow*. You can find the complete list of all windows below.\n\n* MAIN_MENU\n* PLAYER_ONE_VICTORY_WINDOW\n* PLAYER_TWO_VICTORY_WINDOW\n* IN_GAME_WINDOW\n* PROMOTION_WINDOW\n* DRAW_AGREEMENT\n* DRAW_WINDOW\n* SAVE_WINDOW\n* SAVE_COMPLETE_WINDOW\n* END_GAME_WINDOW\n\n## Pseudocode Of Important Functions\n\n### static _Bool isPosChecked(int row, int col, char board\\[8\\]\\[8\\])\n\nA function that checks if the given square can be captured by any of the opponent's pieces.\n\nIt searches for an attacker in 16 different directions:\n\n* **Direction 1:** Diagonally (+X, +Y)\n\n* **Direction 2:** Diagonally (-X, -Y)\n\n* **Direction 3:** Diagonally (-X, +Y)\n\n* **Direction 4:** Diagonally (+X, -Y)\n\n* **Direction 5:** Straight (+Y)\n\n* **Direction 6:** Straight (-Y)\n\n* **Direction 7:** Straight (+X)\n\n* **Direction 8:** Straight (-X)\n\n* **Direction 9\\:16:** All 8 L-shaped movements.\n\n```pseudocode\nDECLARE IS_CHECKED = FALSE\nFOR every search direction\n\tMOVE one step in current direction\n\tIF search direction is not L-shaped\n\t\tDECLARE IS_FIRST_STEP = TRUE\n\t\tWHILE current step exists\n\t\t\tIF IS_FIRST_STEP = TRUE and step is diagonally forward and contains pawn\n\t\t\t\tIS_CHECKED = TRUE\n\t\t\t\tSTOP searching in this direction\n\t\t\tELIF step contains queen whatever the direction or bishop if the direction is diagonal or rook if the direction is straight or king iff IS_FIRST_STEP = TRUE\n\t\t\t\tIS_CHECKED = TRUE\n\t\t\t\tSTOP searching in this direction\n\t\t\tELIF step is not empty\n\t\t\t\tSTOP searching in the direction\n\t\t\tEND\n\t\t\tIS_FIRST_STEP = FALSE\n\t\t\tMOVE one step in current direction\n\t\tNEXT\n\tELIF current step exists and contains knight\n\t\tIS_CHECKED = TRUE\n\t\tSTOP searching in this direction\n\tEND\n\tIF IS_CHECKED = TRUE\n\t\tSTOP the whole searching process\n\tEND\nNEXT\nRETURN IS_CHECKED\n```\n\n### _Bool isMovable(Coordinate coordinate, _Bool isInternal)\n\nA function that computes all possible moves for a specific piece and by the way it returns true iff there is at least one possible move.\n\nIt searches for possible moves in 16 different directions:\n\n* **Direction 1:** Diagonally (+X, +Y)\n\n* **Direction 2:** Diagonally (-X, -Y)\n\n* **Direction 3:** Diagonally (-X, +Y)\n\n* **Direction 4:** Diagonally (+X, -Y)\n\n* **Direction 5:** Straight (+Y)\n\n* **Direction 6:** Straight (-Y)\n\n* **Direction 7:** Straight (+X)\n\n* **Direction 8:** Straight (-X)\n\n* **Direction 9:16:** All 8 L-shaped movements.\n\n```pseudocode\nDECLARE RESULT = FALSE\nFOR every search direction\n\tDECLARE STEPS_COUNT = 1\n\tMOVE one step in current direction\n\tIF SEARCH_DIRECTION \u003c 9\n\t\tWHILE current step exists\n\t\t\tIF piece is pawn \u0026 STEPS_COUNT = 1\n\t\t\t\tIF current step is diagonally forward and contains an enemy or qualified for en passant move or it is forward and contains nothing\n\t\t\t\t\tIF moving to this step won't result in self-check\n\t\t\t\t\t\tAPPEND current step to the allowed squares\n\t\t\t\t\t\tIF pawn hasn't moved yet \u0026 current step is forward\n\t\t\t\t\t\t\tAPPEND next step to the allowed squares\n\t\t\t\t\t\tEND\n\t\t\t\t\t\tRESULT = TRUE\n\t\t\t\t\tEND\n\t\t\t\tEND\n\t\t\tELIF piece is queen whatever the direction or bishop if the direction is diagonal or rook if the direction is straight\n\t\t\t\tIF current step is empty or occupied by enemy\n\t\t\t\t\tIF moving to this step won't result in self-check\n\t\t\t\t\t\tAPPEND current step to the allowed squares\n\t\t\t\t\t\tRESULT = TRUE\n\t\t\t\t\tEND\n\t\t\t\tEND\n\t\t\t\tIF current step is not empty\n\t\t\t\t\tSTOP seaching in this direction\n\t\t\t\tEND\n\t\t\tELIF piece is king and current step isn't checked\n\t\t\t\tIF STEPS_COUNT = 1\n\t\t\t\t\tIF current step is empty or occupied by enemy\n\t\t\t\t\t\tAPPEND current step to the allowed squares\n\t\t\t\t\t\tRESULT = TRUE\n\t\t\t\t\tEND\n\t\t\t\t\tIF (current direction isn't leftward or backward) or (current step is not empty)\n\t\t\t\t\t\tSTOP searching in this direction\n\t\t\t\t\tEND\n\t\t\t\tELIF king is qualified for castling \u0026 current step is empty\n\t\t\t\t\tIF (STEPS_COUNT = 2 and direction is rightward and right castle is qualified for castling) or (STEPS_COUNT = 3 \u0026 direction is leftward \u0026 left castle is qualified for castling)\n\t\t\t\t\t\tAPPEND current step to the allowed squares\n\t\t\t\t\t\tRESULT = TRUE\n\t\t\t\t\t\tSTOP searching in this direction\n\t\t\t\t\tELIF current step is empty\n\t\t\t\t\t\tSTOP searching in this direction\n\t\t\t\t\tEND\n\t\t\t\tEND\n\t\t\tEND\n\t\t\tSTEPS_COUNT++\n\t\t\tMOVE one step in current direction\n\t\tNEXT\n\tELIF piece is knight and step exists on board\n\t\tIF current step is empty or occupied by enemy\n\t\t\tIF moving to this step won't result in self-check\n\t\t\t\tAPPEND current step to the allowed squares\n\t\t\t\tRESULT = TRUE\n\t\t\tEND\n\t\tEND\n\tEND\nNEXT\nRETURN RESULT\n```\n\n### static _Bool isDeadPos()\nA function that checks if the current position is dead. It only returns true if and only if the following conditions are met:\n\n* King vs. King\n* King and Bishops vs. King\n* King and Knight vs. King\n* King and Bishop vs. King and Bishop. (The two bishops have to be placed on squares of the same color).\n\n```pseudocode\nDECLARE DARK_BISHOPS = 0\nDECLARE LIGHT_BISHOPS = 0\nDECLARE KNIGHTS = 0\nDECLARE PIECES = 0\nFOR every piece on the board\n\tIF this piece is anything but not king\n\t\tPIECES++\n\t\tIF this piece is bishop\n\t\t\tIF it was dark\n\t\t\t\tDARK_BISHOPS++\n\t\t\tELSE\n\t\t\t\tLIGHT_BISHOPS\n\t\t\tEND\n\t\tELIF this piece is knight\n\t\t\tKNIGHTS++\n\t\tEND\n\tEND\nNEXT\nIF (PIECES = 2 and (DARK_BISHOPS = 2 or LIGHT_BISHOPS = 2)) or (PIECES = 1 and (LIGHT_BISHOPS = 1 or DARK_BISHOPS = 1 or KNIGHTS = 1)) or (PIECES = 0)\n\tRETURN TRUE\nELSE\n\tRETURN FALSE\nEND\n```\n\n### static void setPlayerState()\n\nA function that decides which state to which the game should set. The game game can be set to one of the following states:\n\n* None\n* Check\n* Checkmate\n* Stalemate\n* Dead Position\n\n```pseudocode\nIF dead position exists\n\tSET player state to dead position\n\tRETURN\nEND\nIF king is not movable\n\tFOR every piece owned by current player excluding king\n\t\tIF this piece is movable\n\t\t\tIF king is in check\n\t\t\t\tSET player state to check\n\t\t\tELSE\n\t\t\t\tSET player state to none\n\t\t\tEND\n\t\t\tRETURN\n\t\tEND\n\tNEXT\n\tIF king is not in check\n\t\tSET player state to stalemate\n\tELSE\n\t\tSET player state to ckeckmate\n\tEND\nELIF king is in check\n\tSET player state to check\nELSE\n\tSET player state to none;\nEND\n```\n\n### void askForMove(Coordinate firstSquare, Coordinate secondSquare)\n\nThe main trigger for pieces moving. It does nothing but ORGANIZES the whole process of moving.\n\n```pseudocode\nAPPEND captured piece to inventory\nUPDATE king position\nAPPEND current move information to the history\nDO promotion if applies\nDO castling if applies\nDO En Passant if applies\nUPDATE list of pieces qualified for castling\nUPDATE En Passant skipped square\nMOVE selected piece to the desired square\nSWITCH current player\nSET current player state\nRESET piece selection\nPLAY move sound\nAPPLY current player state\nAPPEND algebraic notation of current move to the history\nSCROLL moves log down\n```\n\n### void setCastlingState (Coordinate coordinate)\n\nA function that modifies the list of pieces qualified for castling. Only makes sense in case the moved piece is king or rook moving from its initial place.\n\n```pseudocode\nIF current moving piece is king\n\tKing is no longer qualified for castling\nELIF current moving piece is rook\n\tIf it is the left rook\n\t\tLeft rook is no longer qualified for castling\n\tELIF it is the right rook\n\t\tRight rook is no longer qualified for castling\n\tEND\nEND\n```\n\n### void setEnPassantData (Coordinate firstSquare, Coordinate secondSquare)\n\nA function that updates the square skipped by the moving pawn during the last move. A pawn can skip a square through moving 2 steps forward. Only makes sense in case the moved piece is a pawn moving 2 steps forward.\n\n```pseudocode\nIF current moving piece is pawn\n\tIF it is going to move two steps forward\n\t\tPRESERVE the coordinates of the skipped square\n\tEND\nEND\n```\n\n### void doCastling(Coordinate firstSquare, Coordinate secondSquare, _Bool isUndo)\n\nA function that executes the actual procedure of castling. It is triggered by *askForMove()*.\n\n```pseudocode\nIF current moving piece is king\n\tIF it is going to move more than one step\n\t\tMOVE the appropriate rook two steps in the reverse direction\n\tEND\nEND\n```\n\n### void doEnpassant (Coordinate firstSquare, Coordinate secondSquare, _Bool isUndo)\n\nA function that executes the actual procedure of the en passant move. It is triggered by *askForMove()*.\n\n```pseudocode\nIF current moving piece is pawn\n\tIF it is going to move diagonally\n\t\tIF new square was skipped by a pawn during the last move\n\t\t\tCapture the pawn presents on original row of moving pawn and column of the skipped square\n\t\tEND\n\tEND\nEND\n```\n\n### void doPromotion (Coordinate firstSquare, Coordinate secondSquare, _Bool isRedo)\n\nA function that saves the coordinates of the square on which promotion should occurs and then opens promotion dialog to let user chooses the new rank of the brave pawn. It is triggered by *askForMove()*.\n\n```pseudocode\nIF current moving piece is pawn and is going to reach the other side\n\tPRESERVE the coordinates of the square on which the promotion will occur\n\tREMOVE pawn from chess board\n\tOPEN promotion dialog that will further place the new piece on the preserved square\nEND\n```\n\n### _Bool isToBeChecked(Coordinate firstSquare, Coordinate secondSquare)\n\nA function that returns a Boolean value telling the program if moving a specific piece to a specific square will result in self-check or not. It is used by *isMovable()*.\n\n```pseudocode\nCLONE the current chess board\nTEST the move on that board board\nIF king is in check on the cloned board\n\tRETURN TRUE\nELSE\n\tRETURN FALSE\nEND\n```\n\n## Visual Pseudocode (aka. Flowchart)\n\nYou can find the visualized version of pseudocode above [here](https://htmlpreview.github.io/?https://raw.githubusercontent.com/GeeekyBoy/royal-chess/main/img/flowchart.html). For best experience, please view the flowcharts on a device supporting mouse.\n\n## Credits\n\n### Design\n\n**Starline:** https://www.freepik.com/starline\n\n* **Classic Ornamental Decorative Frames:** https://www.freepik.com/free-vector/classic-ornamental-decorative-frames-set-eight_10125119.htm\n\n**Pch.Vector:** https://www.freepik.com/pch-vector\n\n* **Retro Craft Labels Set:** https://www.freepik.com/free-vector/retro-craft-labels-set_9176293.htm\n\n**Ilonitta:** https://www.freepik.com/ilonitta\n\n* **Set Of Isolated Headpiece Floral Decoration:** https://www.freepik.com/free-vector/set-isolated-headpiece-floral-decoration_4102388.htm\n\n**Visnezh:** https://www.freepik.com/visnezh\n\n* **Luxury Ornamental Mandala Background:** https://www.freepik.com/free-vector/luxury-ornamental-mandala-background_6460547.htm\n\n**Harryarts:** https://www.freepik.com/harryarts\n\n* **Collection Of Wood Textures:** https://www.freepik.com/free-vector/collection-wood-textures_822609.htm\n\n**Rawpixel:** https://www.rawpixel.com/\n\n* **Cute Design Business Card:** https://www.freepik.com/free-vector/cute-design-business-card_4122260.htm\n\n**Freepik:** https://www.freepik.com/\n\n* **Blue Cursor Set:** https://www.freepik.com/free-vector/blue-cursor-set_1538073.htm\n\n**Wikimedia Commons:** https://commons.wikimedia.org/\n\n* **SVG Chess Pieces:** https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces\n\n**Material Foundation**: https://material.io/\n\n* **Icons:** https://material.io/resources/icons\n\n**Pixel Perfect:** https://icon54.com/\n\n* **Hand Shake:** https://www.flaticon.com/free-icon/hand-shake_493881\n\n### Colors\n\n**Starline:** https://www.freepik.com/starline\n\n* **Premium Golden Gradients Swatches Set:** https://www.freepik.com/free-vector/premium-golden-gradients-swatches-set_2478703.htm\n* **Golden Frame And Ribbon Background With Text Space:** https://www.freepik.com/free-vector/golden-frame-ribbon-background-with-text-space_9191807.htm\n\n**Teinstud:** https://www.freepik.com/teinstud\n\n* **Wooden Backgrounds Collection:** https://www.freepik.com/free-vector/wooden-backgrounds-collection_939296.htm\n\n### Fonts\n\n**Christian Robertson:** http://christianrobertson.com/\n\n* **Roboto:** https://fonts.google.com/specimen/Roboto\n\n**Google:** https://fonts.google.com/\n\n* **Noto Serif:** https://fonts.google.com/specimen/Noto+Serif\n* **Noto Sans:** https://fonts.google.com/specimen/Noto+Sans\n\n**Monotype:** https://www.fonts.com/font/monotype\n\n* **Arial:** https://www.fonts.com/font/monotype/arial\n\n**ITC:** https://www.fonts.com/font/itc\n\n* **Edwardian Script:** https://www.fonts.com/font/itc/itc-edwardian-script\n\n**URW Type Foundry:** https://www.myfonts.com/type-foundry/urw\n\n* **Bauhaus 93:** https://docs.microsoft.com/en-us/typography/font-list/bauhaus-93\n\n### Audio\n\n**Kenney:** https://www.kenney.nl/\n\n* **Digital Audio:** https://www.kenney.nl/assets/digital-audio\n* **Interface Sounds:** https://www.kenney.nl/assets/interface-sounds\n* **UI Audio:** https://www.kenney.nl/assets/ui-audio\n\n**Play.ht:** https://www.play.ht/?via=ahmed\n\n**Kronbits:** https://kronbits.itch.io/\n\n* **Free SFX Pack:** https://kronbits.itch.io/freesfx\n\n**mh2o:** https://freesound.org/people/mh2o/\n\n* **Chess Move On Alabaster:** https://freesound.org/people/mh2o/sounds/351518/\n\n### Libraries\n\n**Dale Weiler:** https://github.com/graphitemaster\n\n* **Incbin:** https://github.com/graphitemaster/incbin\n\n**Mikko Mononen:** https://github.com/memononen\n\n* **Nano SVG:** https://github.com/memononen/nanosvg\n\n**SDL Team:** https://www.libsdl.org/ \n\n### Development\n\n**SDL Team:** https://www.libsdl.org/ \n\n* **SDL Wiki:** https://wiki.libsdl.org/FrontPage\n\n**Lazy Foo Productions:** https://lazyfoo.net/\n\n* **Beginning Game Programming v2.0:** https://lazyfoo.net/tutorials/SDL/index.php\n\n**Stephen Meier:** https://stephenmeier.net/\n\n* **SDL 2.0 Tutorial:** https://stephenmeier.net/2014/08/10/sdl-2-0-tutorial-00-the-basic-sturcture/\n\n**Programiz:** https://www.programiz.com/\n\n* **Learn C Programming:** https://www.programiz.com/c-programming\n\n**Tutorialspoint:** https://www.tutorialspoint.com/index.htm\n\n* **C Standard Library Reference:** https://www.tutorialspoint.com/c_standard_library/index.htm\n\n### License\n\n*Royal Chess* is released under the **GNU AGPLv3** license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeekyboy%2Froyal-chess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeeekyboy%2Froyal-chess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeekyboy%2Froyal-chess/lists"}