Skip to content

Commit 84ba99d

Browse files
Merge pull request #164 from Longwater1234/dev
Clearing forcedMoves after either side capture
2 parents 5f27e7e + afb8f4d commit 84ba99d

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

.github/workflows/cmake-single-platform.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
env:
1212
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
1313
BUILD_TYPE: Release
14-
SFML_DIR: "C:/SFML/SFML-2.6.1"
15-
SFML_WIN_ZIP: SFML-2.6.1-windows-vc17-64-bit.zip
14+
SFML_DIR: "C:/SFML/SFML-2.6.2"
15+
SFML_WIN_ZIP: SFML-2.6.2-windows-vc17-64-bit.zip
1616

1717
jobs:
1818
build:
@@ -27,7 +27,7 @@ jobs:
2727
- name: Download and setup SFML for Windows
2828
shell: cmd
2929
run: |
30-
mkdir "C:/SFML" && curl -fsSL "https://www.sfml-dev.org/files/${{ env.SFML_WIN_ZIP }}" -o "C:/SFML/${{ env.SFML_WIN_ZIP }}"
30+
mkdir "C:/SFML" && curl -fsSL "https://github.com/SFML/SFML/releases/download/2.6.2/${{ env.SFML_WIN_ZIP }}" -o "C:/SFML/${{ env.SFML_WIN_ZIP }}"
3131
tar -xvf "C:/SFML/${{env.SFML_WIN_ZIP}}" -C "C:/SFML/"
3232
3333
- name: Configure CMake

BUILDING.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
## On Windows
44

5-
1. Just open this project directly in Visual Studio 2022 (or newer), with native CMake extension installed.
5+
1. Just import this project directly in Visual Studio 2022 (or newer), with native CMake extension installed.
66
2. Wait as Visual Studio auto-configures this project for you.
77
3. Next, from top toolbar, change mode to **'Release'**, and click **Build** > **Build All**.
88
4. Done. That's it! Your game `.exe` will be inside `{project_dir}/out/Release/bin/`. Enjoy!
99

10-
## On MacOS & Linux
10+
## On MacOS & Linux (using Terminal)
1111

12-
1. Open this project directory in your Terminal.
13-
2. Ensure CMake 3.20 or higher is installed. Verify with `cmake --version`
12+
1. Ensure CMake 3.20 or higher is installed. Verify with `cmake --version`
13+
2. Open this project directory in your Terminal.
1414
3. Next, copy and run the following commands:
1515

1616
```bash
17-
mkdir build
18-
cd build
17+
mkdir out/
18+
cd out/
1919
cmake . . -DCMAKE_BUILD_TYPE=Release
20-
cmake --build . --config Release --target all -j
20+
cmake --build . --config Release -j
2121

2222
```
2323

24-
4. Done. Your optimized game executable (`.app` on MacOS) will be found inside `{project_dir}/build/bin/`
24+
4. Done. Your optimized game executable (`.app` on MacOS) will be found inside `{project_dir}/out/bin/`
2525
5. Alternatively, if you have CLion IDE, you can skip ALL steps above, and use it to build in "Release" mode.
2626

2727
## Using CMake GUI (all desktop platforms)
@@ -33,9 +33,9 @@ cmake --build . --config Release --target all -j
3333
- Set "Source Folder" (1) to this project root dir. Then, set "Build Folder" (2) to a NEW _relative_ folder `/build` or `/out`.
3434
- Ensure "CMAKE_BUILD_TYPE" is **Release** (see image above, blue highlight). Ignore other settings. Then (3) click **Configure**.
3535
- In the popup window, choose generator **'Unix Makefiles'** if on Linux; choose **'XCode'** if on MacOS. Choose **'Visual Studio'** if on Windows. Then click OK to save.
36-
- Click **Configure** once again, then **Generate**.
37-
- Finally, on Windows or MacOS, click **Open Project** for building in respective IDE. On Linux desktop, open build folder, then run `make all` in Terminal.
36+
- Click **Configure** once again, then click (4) **Generate**.
37+
- Finally, on Windows or MacOS, click **Open Project** for building in respective IDE. On Linux desktop, open build folder, then run `make -j` in Terminal.
3838

3939
### Important:
4040

41-
For macOS-specific guide with XCode, please [cmake/README.md](cmake/README.md)
41+
For macOS-specific guide with XCode, please see [cmake/README.md](cmake/README.md)

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Offline & Online Multiplayer Checkers game in C++ built with SFML 2.6, imGui, Protobuf and ixWebsockets. With very minimal dependencies
44
and a simple build process. All dependencies are auto-downloaded (as `.tar.gz`) and configured for you using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake). The only dependency you need pre-installed on your OS is SFML 2.6.x (or newer).
55

6-
7-
This game can connect to both Private and Public game servers. The Server project for this game is written in Golang, and is [available here](https://github.com/Longwater1234/checkers-backend) which you can self-host!
6+
This game can connect to both Private and Public game servers. The backend server for this game is written in Golang, and is [available on GitHub](https://github.com/Longwater1234/checkers-backend) which you can self-host! You can download pre-built game (Windows x64 exe) from Actions tab (on GitHub Web). For other platforms, use the itch.io link above.
87

98
### Main Libraries Used
109

@@ -23,17 +22,17 @@ This game can connect to both Private and Public game servers. The Server projec
2322

2423
### For Windows
2524

26-
- At least Windows 10
25+
- At least Windows 10 / Server 2016
2726
- MS Visual Studio 2022 or newer (NOT vscode), with "**Desktop C++ Development**" bundle.
2827
- Please download "Visual C++ 64bit" edition of SFML; ignore others.
2928
- Move your unzipped `SFML-2.6.x` folder to its own home, example: `C:/SFML/SFML-2.6.1`.
3029
- Edit **line 24** in [CMakeLists.txt](CMakeLists.txt#L24), to set value `SFML_HOME` to folder path you moved SFML into (from previous step)
3130

3231
### For macOS (x64 & arm64)
3332

34-
- Please install SFML 2.6 as **Frameworks**, not as "dylibs", as shown in [official SFML guide](https://www.sfml-dev.org/tutorials/2.6/start-osx.php).
3533
- XCode 14 or newer from AppStore (with MacOS SDK)
36-
- Apple Developer tools. After Xcode is installed, run this in your Terminal:
34+
- Please install SFML 2.6 as **Frameworks**, not as "dylibs", as shown in [official SFML guide](https://www.sfml-dev.org/tutorials/2.6/start-osx.php).
35+
- Download Apple Developer tools. After Xcode is installed, run this in your Terminal:
3736

3837
```bash
3938
sudo xcode-select --install
@@ -50,22 +49,22 @@ This game can connect to both Private and Public game servers. The Server projec
5049
- Latest display drivers
5150
- Use your OS package manager (`apt` or `yum`) to install SFML 2.6 or newer.
5251
- Alternatively, you may build SFML 2.6 from source, see [official SFML docs](https://www.sfml-dev.org/tutorials/2.6/start-linux.php).
53-
- You are required to install latest **OpenSSL Dev** library. See example on Ubuntu / Debian below.
52+
- You are required to install latest **OpenSSL Dev** library. See example for Ubuntu / Debian below.
5453

5554
```bash
5655
sudo apt install libsfml-dev
5756
sudo apt install libssl-dev
5857
```
5958

60-
- Luckily, Windows and macOS come with their **native SSL libs pre-installed**, so nothing more to do 😁
59+
- Luckily, Windows and macOS come with their **native SSL libs pre-installed**, so nothing more to do 😊
6160

6261
## Build Instructions
6362

6463
Please see [BUILDING.md](BUILDING.md) for detailed instructions for each platform.
6564

6665
## Code Contributions
6766

68-
Pull requests are welcome! See GitHub Issues tab to help with new Features. Just kindly remember run `lint.sh` script before you git push. Also, for this project, header files should end with `.hpp`.
67+
Pull requests are welcome! See GitHub Issues tab to help with new Features. Just kindly remember run `./lint.sh` script before you git push. Also, for this project, header files should end with `.hpp`.
6968

7069
## License
7170

cmake/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
This contains CMake script to build MacOS GUI `.app` bundle. It embeds the icon to the app bundle. It also copies all static assets (resources) into the bundle at build time.
44

5-
**IMPORTANT**: If you installed SFML as "Frameworks" (recommended), you will need to manually instruct XCode to embed them into the bundle at Build time. Otherwise, the game won't work on other similar MacOS devices!
5+
**IMPORTANT**: If you installed SFML as "Frameworks" (recommended), you will need to manually instruct XCode to embed them into the bundle at Build time. Otherwise, the game won't work on other similar Macs!
66

77
Kindly follow these steps:
88

99
- Use CMake to generate "XCode Project". Refer to [BUILDING.md](../BUILDING.md). Open the project.
1010
- From top toolbar inside Xcode, click **Product** > **Add New Build Phase** > choose **Copy Files**. See official [Apple guide](https://developer.apple.com/documentation/xcode/customizing-the-build-phases-of-a-target)
11+
- Expand the "Copy Files" section, select destination: **Frameworks**.
1112
- Click the `+` (add button) to begin. A new window will pop up.
1213
- Now select all SFML frameworks listed: `sfml-graphics.framework`, `sflml-window.framework` etc.
13-
- Finally, you will need to add `freetype.framework`. Click **Other Locations**, find it inside `/Library/Frameworks`. Click "Copy as reference folder". Click OK
14-
- Now you can build your project. From top toolbar, Click **Product** > **Build**.
14+
- Lastly, you will need to add `freetype.framework` (for text support). Click **"Add Other..."**, find it inside `/Library/Frameworks`. Click "Copy as reference folder". Click OK.
15+
- You should have output similar to screenshot below (I renamed "Copy Files" to "Copy Frameworks"):
16+
![xcode screenshot](./xcode_copy_frameworks.png)
17+
- Now you can build your project. From top toolbar, Click **Product** > **Build**. Done!

cmake/xcode_copy_frameworks.png

343 KB
Loading

src/managers/GameManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void GameManager::handleCapturePiece(const chk::PlayerPtr &hunter, const chk::Pl
159159
return;
160160
}
161161
// Check for extra opportunities (only if hunter has NOT just became KING)
162+
this->forcedMoves.clear();
162163
if (isKingBefore == isKingNow)
163164
{
164165
GameManager::identifyTargets(hunter, targetCell);

src/managers/OnlineGameManager.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace chk
88
{
99
using chk::payload::TeamColor;
10+
1011
/**
1112
* This class is responsible for online gameplay
1213
* @since 2024-04-11
@@ -292,11 +293,12 @@ inline void OnlineGameManager::handleCapturePiece(const chk::PlayerPtr &hunter,
292293
return;
293294
}
294295

296+
// CREATE SOME COPIES BEFORE UPDATING:
295297
int copyHunterPiece = 0; // hunter pieceId
296-
int copySrcCell = 0; // hunter src cell
298+
int copySrcCell = 0; // hunter src cell index
297299
int copyPreyPieceId = 0;
298300
int copyPreyCell = 0;
299-
// track King status for Hunter piece
301+
// for tracking King status of Hunter piece
300302
bool isKingBefore = false;
301303
bool isKingNow = false;
302304

@@ -330,7 +332,7 @@ inline void OnlineGameManager::handleCapturePiece(const chk::PlayerPtr &hunter,
330332
{
331333
return;
332334
}
333-
// prey details (must use raw pointers for embedded protobuf)
335+
// prey details (must use raw ptr for embedded protobuf)
334336
auto *details = new chk::payload::CapturePayload_TargetDetails();
335337
details->set_hunter_src_cell(copySrcCell);
336338
details->set_prey_cell_idx(copyPreyCell);
@@ -374,6 +376,7 @@ inline void OnlineGameManager::handleCapturePiece(const chk::PlayerPtr &hunter,
374376
// NO MORE JUMPS AVAILABLE. SWITCH TURNS to opponent
375377
chk::GameManager::identifyTargets(prey);
376378
this->isMyTurn = !this->isMyTurn;
379+
this->updateMessage("It's " + prey->getName() + "'s turn");
377380
}
378381
else
379382
{
@@ -414,7 +417,7 @@ inline void OnlineGameManager::handleCellTap(const chk::PlayerPtr &hunter, const
414417
}
415418
else
416419
{
417-
// Cell is Empty! Let's judge if this is SIMPLE move or ATTACK move
420+
// Cell is Empty! Let's evaluate if this is SIMPLE move or ATTACK move
418421
if (!buffer.isEmpty())
419422
{
420423
const short movablePieceId = buffer.getFront();
@@ -445,7 +448,7 @@ inline void OnlineGameManager::handleCellTap(const chk::PlayerPtr &hunter, const
445448
inline void OnlineGameManager::startMoveListener()
446449
{
447450
this->wsClient->setOnMovePieceCallback([this](const chk::payload::MovePayload &payload) {
448-
// which color is my Opponent?
451+
// which color is the Opponent?
449452
// clang-format off
450453
const chk::PlayerPtr &enemy = (payload.from_team() == TeamColor::TEAM_RED) ? this->playerRed : this->playerBlack;
451454
const chk::PlayerPtr &myTeam = (enemy->getPlayerType() == PlayerType::PLAYER_RED) ? this->playerBlack : this->playerRed;
@@ -507,6 +510,7 @@ inline void OnlineGameManager::startCaptureListener()
507510
});
508511

509512
// Check for extra opportunities (for Enemy), only if Enemy did NOT just become King
513+
this->forcedMoves.clear();
510514
if ((isKingBefore == isKingNow) && it != this->blockList.end())
511515
{
512516
GameManager::identifyTargets(opponent, *it);
@@ -517,6 +521,7 @@ inline void OnlineGameManager::startCaptureListener()
517521
// NO MORE JUMPS AVAILABLE. SWITCH TURNS to myself.
518522
chk::GameManager::identifyTargets(myTeam);
519523
this->isMyTurn = !this->isMyTurn;
524+
this->updateMessage("It's now your turn!");
520525
}
521526
});
522527
}

0 commit comments

Comments
 (0)