From 6fb91b4523795d64c91359d63a32fb26d73fc234 Mon Sep 17 00:00:00 2001 From: Nicola Revelant Date: Fri, 19 Jan 2024 16:32:29 +0100 Subject: [PATCH] Standardize include guard names and member variable names --- src/ChessboardGrid/ChessboardGrid.h | 6 +- src/ChessboardSquare/ChessboardSquare.h | 6 +- src/Frame/Frame.h | 6 +- src/GameUtils/GameUtils.h | 6 +- src/MatchManager/MatchManager.cpp | 104 ++++++++++++------------ src/MatchManager/MatchManager.h | 20 ++--- src/Resources/Resources.h | 6 +- 7 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/ChessboardGrid/ChessboardGrid.h b/src/ChessboardGrid/ChessboardGrid.h index 18ca900..ba4538a 100644 --- a/src/ChessboardGrid/ChessboardGrid.h +++ b/src/ChessboardGrid/ChessboardGrid.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2023 Nicola Revelant -#ifndef ITALIAN_DRAUGHTS_CHESSBOARD_GRID_H -#define ITALIAN_DRAUGHTS_CHESSBOARD_GRID_H +#ifndef CHESSBOARD_GRID_H +#define CHESSBOARD_GRID_H #include "ChessboardSquare/ChessboardSquare.h" #include "GameUtils/GameUtils.h" @@ -78,4 +78,4 @@ class ChessboardGrid : public wxPanel { }; -#endif //ITALIAN_DRAUGHTS_CHESSBOARD_GRID_H +#endif // CHESSBOARD_GRID_H diff --git a/src/ChessboardSquare/ChessboardSquare.h b/src/ChessboardSquare/ChessboardSquare.h index a00d1b4..b3b620e 100644 --- a/src/ChessboardSquare/ChessboardSquare.h +++ b/src/ChessboardSquare/ChessboardSquare.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2023 Nicola Revelant -#ifndef ITALIAN_DRAUGHTS_CHESSBOARD_SQUARE_H -#define ITALIAN_DRAUGHTS_CHESSBOARD_SQUARE_H +#ifndef CHESSBOARD_SQUARE_H +#define CHESSBOARD_SQUARE_H #include @@ -58,4 +58,4 @@ class ChessboardSquare : public wxWindow { }; -#endif //ITALIAN_DRAUGHTS_CHESSBOARD_SQUARE_H +#endif // CHESSBOARD_SQUARE_H diff --git a/src/Frame/Frame.h b/src/Frame/Frame.h index 8fc0de7..d35fd24 100644 --- a/src/Frame/Frame.h +++ b/src/Frame/Frame.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2023 Nicola Revelant -#ifndef ITALIAN_DRAUGHTS_FRAME_H -#define ITALIAN_DRAUGHTS_FRAME_H +#ifndef FRAME_H +#define FRAME_H #include "Resources/Resources.h" #include "MatchManager/MatchManager.h" @@ -94,4 +94,4 @@ class Frame : public wxFrame { void aboutClicked(wxCommandEvent &); }; -#endif //ITALIAN_DRAUGHTS_FRAME_H +#endif // FRAME_H diff --git a/src/GameUtils/GameUtils.h b/src/GameUtils/GameUtils.h index 7dc1eae..1c94426 100644 --- a/src/GameUtils/GameUtils.h +++ b/src/GameUtils/GameUtils.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2023 Nicola Revelant -#ifndef ITALIAN_DRAUGHTS_MINIMAX_THREAD_H -#define ITALIAN_DRAUGHTS_MINIMAX_THREAD_H +#ifndef GAME_UTILS_H +#define GAME_UTILS_H #include "wx/wx.h" @@ -108,4 +108,4 @@ class GameUtils { static int minimax(const GameUtils::Move *start_move, int oldScore, bool maximizing, int depth, int alpha, int beta); }; -#endif // ITALIAN_DRAUGHTS_MINIMAX_THREAD_H +#endif // GAME_UTILS_H diff --git a/src/MatchManager/MatchManager.cpp b/src/MatchManager/MatchManager.cpp index 46531e4..842a6ec 100644 --- a/src/MatchManager/MatchManager.cpp +++ b/src/MatchManager/MatchManager.cpp @@ -14,39 +14,39 @@ MatchManager::MatchManager(ChessboardGrid *chessboard) { chessboard->Bind(wxEVT_LEFT_UP, &MatchManager::onChessboardSquareClick, this); chessboard->Bind(wxEVT_MENU, &MatchManager::onThreadFinish, this, THREAD_ID); - chessboardGrid = chessboard; - algorithmThread = nullptr; + mChessboardGrid = chessboard; + mAlgorithmThread = nullptr; mIsPlaying = false; mIsEnd = false; mIsPcFirstPlayer = false; } MatchManager::~MatchManager() { - for (GameUtils::Move *move: moves) { + for (GameUtils::Move *move: mMoves) { delete move; } } bool MatchManager::newMatch() { - if (algorithmThread) { - algorithmThread->Delete(); - algorithmThread = nullptr; + if (mAlgorithmThread) { + mAlgorithmThread->Delete(); + mAlgorithmThread = nullptr; } setDefaultLayout(); - chessboardGrid->updateDisposition(m_disposition, mIsPcFirstPlayer); + mChessboardGrid->updateDisposition(mDisposition, mIsPcFirstPlayer); // deletes all moves before re-assignment - for (GameUtils::Move *move: moves) + for (GameUtils::Move *move: mMoves) delete move; mIsEnd = false; if (mIsPcFirstPlayer) { - moves.clear(); + mMoves.clear(); makePCMove(); } else { mIsPlaying = false; - moves = GameUtils::findMoves(m_disposition, true); + mMoves = GameUtils::findMoves(mDisposition, true); notifyUpdate(TURN_PLAYER); } @@ -54,17 +54,17 @@ bool MatchManager::newMatch() { } void MatchManager::setOnUpdateListener(const UpdateCallback &updateCB) { - m_onUpdate = updateCB; + mOnUpdate = updateCB; - // if the game is over it doesn't call the listener - if (!mIsEnd) notifyUpdate(algorithmThread ? TURN_PC : TURN_PLAYER); + // if the game is not over notify the current state + if (!mIsEnd) notifyUpdate(mAlgorithmThread ? TURN_PC : TURN_PLAYER); } bool MatchManager::changeDifficulty(int newDifficulty) { if (newDifficulty < minGD || newDifficulty > maxGD) return false; - gameDifficulty = newDifficulty; + mGameDifficulty = newDifficulty; newMatch(); return true; } @@ -76,7 +76,7 @@ bool MatchManager::flipFirstPlayer() { } int MatchManager::getDifficulty() const { - return gameDifficulty; + return mGameDifficulty; } bool MatchManager::isPlaying() const { @@ -84,15 +84,15 @@ bool MatchManager::isPlaying() const { } void MatchManager::onChessboardSquareClick(wxMouseEvent &event) { - if (algorithmThread || mIsEnd) return; + if (mAlgorithmThread || mIsEnd) return; int currentPos = event.GetId(); - if (selectedPos == selectedNone) { - if ((m_disposition[currentPos] == GameUtils::PLAYER_PAWN || m_disposition[currentPos] == GameUtils::PLAYER_DAME)) { + if (mSelectedPos == selectedNone) { + if ((mDisposition[currentPos] == GameUtils::PLAYER_PAWN || mDisposition[currentPos] == GameUtils::PLAYER_DAME)) { if (highlightPossibleMoves(currentPos)) { - chessboardGrid->SetSquareSelectedOverlay(currentPos); - selectedPos = currentPos; + mChessboardGrid->SetSquareSelectedOverlay(currentPos); + mSelectedPos = currentPos; } else { notifyUpdate(ILLEGAL_SELECTION); } @@ -101,18 +101,18 @@ void MatchManager::onChessboardSquareClick(wxMouseEvent &event) { } // change selection - if ((m_disposition[currentPos] == GameUtils::PLAYER_PAWN || m_disposition[currentPos] == GameUtils::PLAYER_DAME)) { - chessboardGrid->ClearSquareOverlay(); // it clears selectedPos and possible moves - if (currentPos == selectedPos) { - selectedPos = selectedNone; + if ((mDisposition[currentPos] == GameUtils::PLAYER_PAWN || mDisposition[currentPos] == GameUtils::PLAYER_DAME)) { + mChessboardGrid->ClearSquareOverlay(); // it clears selectedPos and possible moves + if (currentPos == mSelectedPos) { + mSelectedPos = selectedNone; return; } if (highlightPossibleMoves(currentPos)) { - chessboardGrid->SetSquareSelectedOverlay(currentPos); - selectedPos = currentPos; + mChessboardGrid->SetSquareSelectedOverlay(currentPos); + mSelectedPos = currentPos; } else { - selectedPos = selectedNone; + mSelectedPos = selectedNone; notifyUpdate(ILLEGAL_SELECTION); } @@ -120,24 +120,24 @@ void MatchManager::onChessboardSquareClick(wxMouseEvent &event) { } // illegal selection, deselect the current selection - if (m_disposition[currentPos] != GameUtils::EMPTY || currentPos % 2 != (currentPos / 8) % 2) { - chessboardGrid->ClearSquareOverlay(); // it clears selectedPos and possible moves - selectedPos = selectedNone; + if (mDisposition[currentPos] != GameUtils::EMPTY || currentPos % 2 != (currentPos / 8) % 2) { + mChessboardGrid->ClearSquareOverlay(); // it clears selectedPos and possible moves + mSelectedPos = selectedNone; return; } - GameUtils::Move *move = findPlayerMove(selectedPos, currentPos); + GameUtils::Move *move = findPlayerMove(mSelectedPos, currentPos); if (move == nullptr) { // illegal move - chessboardGrid->ClearSquareOverlay(); - selectedPos = selectedNone; + mChessboardGrid->ClearSquareOverlay(); + mSelectedPos = selectedNone; notifyUpdate(ILLEGAL_MOVE); return; } // legal move - chessboardGrid->updateDisposition(m_disposition = move->disposition, mIsPcFirstPlayer); - selectedPos = selectedNone; + mChessboardGrid->updateDisposition(mDisposition = move->disposition, mIsPcFirstPlayer); + mSelectedPos = selectedNone; makePCMove(); } @@ -145,22 +145,22 @@ void MatchManager::onChessboardSquareClick(wxMouseEvent &event) { void MatchManager::makePCMove() { mIsPlaying = true; notifyUpdate(TURN_PC); - algorithmThread = new GameUtils::AlgorithmThread(chessboardGrid, m_disposition, gameDifficulty, THREAD_ID); - if (algorithmThread->Create() != wxTHREAD_NO_ERROR || algorithmThread->Run() != wxTHREAD_NO_ERROR) { + mAlgorithmThread = new GameUtils::AlgorithmThread(mChessboardGrid, mDisposition, mGameDifficulty, THREAD_ID); + if (mAlgorithmThread->Create() != wxTHREAD_NO_ERROR || mAlgorithmThread->Run() != wxTHREAD_NO_ERROR) { std::cerr << "Cannot execute thread" << std::endl; exit(1); } } void MatchManager::onThreadFinish(wxCommandEvent &evt) { - if (!algorithmThread) { + if (!mAlgorithmThread) { #ifdef DEBUG std::cerr << "Unwanted thread finished" << std::endl; #endif delete static_cast(evt.GetClientData()); exit(1); } - algorithmThread = nullptr; + mAlgorithmThread = nullptr; auto *pcMove = static_cast(evt.GetClientData()); if (pcMove == nullptr) { @@ -171,15 +171,15 @@ void MatchManager::onThreadFinish(wxCommandEvent &evt) { return; } - chessboardGrid->updateDisposition(m_disposition = pcMove->disposition, mIsPcFirstPlayer); + mChessboardGrid->updateDisposition(mDisposition = pcMove->disposition, mIsPcFirstPlayer); delete pcMove; // deletes all moves before re-assignment - for (GameUtils::Move *move: moves) + for (GameUtils::Move *move: mMoves) delete move; - moves = GameUtils::findMoves(m_disposition, true); - if (moves.empty()) { + mMoves = GameUtils::findMoves(mDisposition, true); + if (mMoves.empty()) { // Player cannot do anything, PC won mIsEnd = true; mIsPlaying = false; @@ -194,14 +194,14 @@ void MatchManager::setDefaultLayout() { for (int i = 0; i < 64; i++) { if ((i / 8) % 2 == i % 2) { if (i < (8 * 3)) { - m_disposition[i] = GameUtils::PC_PAWN; + mDisposition[i] = GameUtils::PC_PAWN; } else if (i >= (8 * 5)) { - m_disposition[i] = GameUtils::PLAYER_PAWN; + mDisposition[i] = GameUtils::PLAYER_PAWN; } else { - m_disposition[i] = GameUtils::EMPTY; + mDisposition[i] = GameUtils::EMPTY; } } else { - m_disposition[i] = GameUtils::EMPTY; + mDisposition[i] = GameUtils::EMPTY; } } } @@ -210,7 +210,7 @@ GameUtils::Move *MatchManager::findPlayerMove(int oldIndex, int newIndex) { GameUtils::PieceType oldValue, newValue; // iterates the possible moves - for (GameUtils::Move *move: moves) { + for (GameUtils::Move *move: mMoves) { oldValue = move->disposition[oldIndex]; if (oldValue != GameUtils::EMPTY) continue; // this is not the correct move @@ -226,13 +226,13 @@ GameUtils::Move *MatchManager::findPlayerMove(int oldIndex, int newIndex) { bool MatchManager::highlightPossibleMoves(int from) { bool isValid = false; - for (GameUtils::Move *move: moves) { + for (GameUtils::Move *move: mMoves) { if (move->disposition[from] != GameUtils::EMPTY) continue; // wrong move isValid = true; for (int i = 0; i < 64; i++) { - if (m_disposition[i] == GameUtils::EMPTY && move->disposition[i] != GameUtils::EMPTY) { + if (mDisposition[i] == GameUtils::EMPTY && move->disposition[i] != GameUtils::EMPTY) { // possible move - chessboardGrid->SetSquarePossibleMoveOverlay(i); + mChessboardGrid->SetSquarePossibleMoveOverlay(i); } } } @@ -241,5 +241,5 @@ bool MatchManager::highlightPossibleMoves(int from) { } void MatchManager::notifyUpdate(MatchManager::UpdateType updateType) { - if (m_onUpdate != nullptr) m_onUpdate(updateType); + if (mOnUpdate != nullptr) mOnUpdate(updateType); } diff --git a/src/MatchManager/MatchManager.h b/src/MatchManager/MatchManager.h index 235d60c..406c7c6 100644 --- a/src/MatchManager/MatchManager.h +++ b/src/MatchManager/MatchManager.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2023 Nicola Revelant -#ifndef ITALIAN_DRAUGHTS_DRAUGHTS_MATCH_MANAGER_H -#define ITALIAN_DRAUGHTS_DRAUGHTS_MATCH_MANAGER_H +#ifndef MATCH_MANAGER_H +#define MATCH_MANAGER_H #include "ChessboardGrid/ChessboardGrid.h" #include "GameUtils/GameUtils.h" @@ -85,14 +85,14 @@ class MatchManager { private: MatchManager(const MatchManager &); // prevents copy-constructor - GameUtils::Disposition m_disposition{}; - GameUtils::AlgorithmThread *algorithmThread; - ChessboardGrid *chessboardGrid; - GameUtils::MoveList moves{}; + GameUtils::Disposition mDisposition{}; + GameUtils::AlgorithmThread *mAlgorithmThread; + ChessboardGrid *mChessboardGrid; + GameUtils::MoveList mMoves{}; bool mIsEnd, mIsPlaying, mIsPcFirstPlayer; - int gameDifficulty = DEFAULT_DIFFICULTY, selectedPos = selectedNone; + int mGameDifficulty = DEFAULT_DIFFICULTY, mSelectedPos = selectedNone; - UpdateCallback m_onUpdate; + UpdateCallback mOnUpdate; void onChessboardSquareClick(wxMouseEvent &evt); @@ -126,10 +126,10 @@ class MatchManager { bool highlightPossibleMoves(int from); /** - * If onUpdate listener is set, it calls the listener with updateType + * If onUpdate listener is set, notify state change * @param updateType Update type */ void notifyUpdate(UpdateType updateType); }; -#endif //ITALIAN_DRAUGHTS_DRAUGHTS_MATCH_MANAGER_H +#endif // MATCH_MANAGER_H diff --git a/src/Resources/Resources.h b/src/Resources/Resources.h index 45adb56..498b809 100644 --- a/src/Resources/Resources.h +++ b/src/Resources/Resources.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2023 Nicola Revelant -#ifndef ITALIAN_DRAUGHTS_STRING_RESOURCES_H -#define ITALIAN_DRAUGHTS_STRING_RESOURCES_H +#ifndef RESOURCES_H +#define RESOURCES_H #include "wx/wx.h" #include @@ -41,4 +41,4 @@ class Resources { }; -#endif //ITALIAN_DRAUGHTS_STRING_RESOURCES_H +#endif // RESOURCES_H