From c759f0d802c78514883daa114bf07265d8a4b110 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 01:30:03 -0400 Subject: [PATCH 1/8] chore: adds modernize-deprecated-headers --- .clang-tidy | 7 ++++++- main.cpp | 34 ++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 5c44609..7c06e38 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,12 @@ # clang-tidy configuration for Go-Board-Game # Keep checks at tool defaults while treating all warnings as errors. +# clang-diagnostic-* : surface compiler-style warnings (unused variables, conversions, etc.) +# clang-analyzer-* : enable static analysis passes for deeper bug finding +# google-build-using-namespace : reject global using-namespace directives +# modernize-deprecated-headers : prefer C++ standard headers over legacy C ones Checks: > clang-diagnostic-*, clang-analyzer-*, - google-build-using-namespace + google-build-using-namespace, + modernize-deprecated-headers WarningsAsErrors: '*' diff --git a/main.cpp b/main.cpp index 883e56a..a20fb4a 100644 --- a/main.cpp +++ b/main.cpp @@ -2,14 +2,14 @@ //#include //#include //#include -//#include - -//using namespace std; - -// NEW INCLUDES/USINGS +// Standard library +#include +#include -//#pragma comment(lib, "DevIL.lib") -//#pragma comment(lib, "ILU.lib") +//For Sleep in Windows +//#include +//For Sleep in Linux +#include //#pragma comment(lib, "ILUT.lib") #include @@ -32,10 +32,6 @@ ILuint il[3] = { 0, 1, 2 }; GLuint texture[3] = { 0, 1, 2 }; -#include -#include -#include -#include // For the queue @@ -63,6 +59,8 @@ GLdouble camXPos = 0.0; GLdouble camYPos = 0.0; GLdouble camZPos = -1.5; +constexpr float PI = 3.14159265358979323846F; // Pi constant for trigonometric helpers + const GLdouble CAMERA_FOVY = 60.0; const GLdouble NEAR_CLIP = 0.1; const GLdouble FAR_CLIP = 1000.0; @@ -627,7 +625,7 @@ void display() glPushMatrix(); //////////////////// MOVING LIGHT!!!!! //////////////////// - glTranslatef(2 * sin(translatelight * 2 * 3.14 / 360), 0.0, 0.0); + glTranslatef(2.0F * std::sin(translatelight * 2.0F * PI / 360.0F), 0.0F, 0.0F); if (lighting) { lightingFunc(); @@ -706,7 +704,7 @@ void ApplyTransformations(float indx, float indy, float z) int i; if (indx < 0) { - for (i = 0; i Date: Sun, 2 Nov 2025 01:37:26 -0400 Subject: [PATCH 2/8] chore: use modernize-use-using --- .clang-tidy | 4 +++- main.cpp | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7c06e38..55bf8ba 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,9 +4,11 @@ # clang-analyzer-* : enable static analysis passes for deeper bug finding # google-build-using-namespace : reject global using-namespace directives # modernize-deprecated-headers : prefer C++ standard headers over legacy C ones +# modernize-use-using : prefer 'using' type alias declarations over 'typedef's Checks: > clang-diagnostic-*, clang-analyzer-*, google-build-using-namespace, - modernize-deprecated-headers + modernize-deprecated-headers, + modernize-use-using WarningsAsErrors: '*' diff --git a/main.cpp b/main.cpp index a20fb4a..a716529 100644 --- a/main.cpp +++ b/main.cpp @@ -40,7 +40,6 @@ GLuint texture[3] = { 0, 1, 2 }; #include #define GL_CLAMP_TO_EDGE 0x812F -typedef std::queue INTQUEUE; // Window settings int windowID; // Glut window ID (for display) @@ -92,7 +91,7 @@ float inc = 0.002; // Depicts how fast time increments. int board_status[19][19]; int liberties_status[19][19]; int restart_option = 0; -INTQUEUE rm_queue; +std::queue rm_queue; std::list> L; //float rm_array[1083]; // Holds the objects that will be removed. From 94f367dd7e3d5fad2d1d98fa7db0953c0e81924c Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 12:52:31 -0500 Subject: [PATCH 3/8] chore: adds modernize-loop-convert --- .clang-tidy | 2 ++ main.cpp | 18 +++++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 55bf8ba..3af6c03 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,11 +4,13 @@ # clang-analyzer-* : enable static analysis passes for deeper bug finding # google-build-using-namespace : reject global using-namespace directives # modernize-deprecated-headers : prefer C++ standard headers over legacy C ones +# modernize-loop-convert : prefer range-based for loops over traditional loops # modernize-use-using : prefer 'using' type alias declarations over 'typedef's Checks: > clang-diagnostic-*, clang-analyzer-*, google-build-using-namespace, modernize-deprecated-headers, + modernize-loop-convert, modernize-use-using WarningsAsErrors: '*' diff --git a/main.cpp b/main.cpp index a716529..a040c66 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ //#include //#include // Standard library +#include #include #include @@ -678,8 +679,8 @@ void display() // THE REMOVAL OF PIECE PORTION if (!L.empty()) { - for (std::list>::iterator i = L.begin(); i != L.end(); ++i) { - jump_off((*i)[0], (*i)[1], (*i)[2]); + for (const auto& piece : L) { + jump_off(piece[0], piece[1], piece[2]); } t += (inc*L.size()); } @@ -795,20 +796,11 @@ void SetImages() /////////////////////////////////////////////////////////////////////////////// void init_board() { - - for (int i = 0; i < 19; i++) { - for (int j = 0; j < 19; j++) { - board_status[i][j] = 0; - } - } + std::fill(&board_status[0][0], &board_status[0][0] + 19 * 19, 0); } void clear_liberties() { - for (int i = 0; i < 19; i++) { - for (int j = 0; j < 19; j++) { - liberties_status[i][j] = -1; - } - } + std::fill(&liberties_status[0][0], &liberties_status[0][0] + 19 * 19, -1); } int check_liberties(int x, int y, int originx, int originy, int piece) { From 718afc41916768f80c34a25eb59a4b200a1f6c3a Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 18:51:12 -0500 Subject: [PATCH 4/8] chore: adds modernize-use-stdarray --- .clang-tidy | 2 ++ main.cpp | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 3af6c03..069c88e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ # google-build-using-namespace : reject global using-namespace directives # modernize-deprecated-headers : prefer C++ standard headers over legacy C ones # modernize-loop-convert : prefer range-based for loops over traditional loops +# modernize-use-stdarray : prefer 'std::array' over C-style arrays # modernize-use-using : prefer 'using' type alias declarations over 'typedef's Checks: > clang-diagnostic-*, @@ -12,5 +13,6 @@ Checks: > google-build-using-namespace, modernize-deprecated-headers, modernize-loop-convert, + modernize-use-stdarray, modernize-use-using WarningsAsErrors: '*' diff --git a/main.cpp b/main.cpp index a040c66..0249c19 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ //#include // Standard library #include +#include #include #include @@ -55,6 +56,8 @@ int lastX = 0; int lastY = 0; const float ZOOM_SCALE = 0.01; +constexpr int BOARD_SIZE = 19; + GLdouble camXPos = 0.0; GLdouble camYPos = 0.0; GLdouble camZPos = -1.5; @@ -89,8 +92,8 @@ float t = 0; float inc = 0.002; // Depicts how fast time increments. // Behind the Scenes -int board_status[19][19]; -int liberties_status[19][19]; +std::array, BOARD_SIZE> board_status{}; +std::array, BOARD_SIZE> liberties_status{}; int restart_option = 0; std::queue rm_queue; std::list> L; @@ -796,11 +799,15 @@ void SetImages() /////////////////////////////////////////////////////////////////////////////// void init_board() { - std::fill(&board_status[0][0], &board_status[0][0] + 19 * 19, 0); + for (auto& column : board_status) { + column.fill(0); + } } void clear_liberties() { - std::fill(&liberties_status[0][0], &liberties_status[0][0] + 19 * 19, -1); + for (auto& column : liberties_status) { + column.fill(-1); + } } int check_liberties(int x, int y, int originx, int originy, int piece) { From ee28174478cf84b86d5fe88b5e3b7fa16811929c Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 20:00:03 -0500 Subject: [PATCH 5/8] ci: updates to C++20 --- .clang-tidy | 8 ++++++-- CMakeLists.txt | 9 ++++++--- main.cpp | 45 ++++++++++++++++++++++++++------------------- scripts/run_lint.sh | 7 ++++++- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 069c88e..7756ffa 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,18 +1,22 @@ # clang-tidy configuration for Go-Board-Game # Keep checks at tool defaults while treating all warnings as errors. -# clang-diagnostic-* : surface compiler-style warnings (unused variables, conversions, etc.) # clang-analyzer-* : enable static analysis passes for deeper bug finding +# clang-diagnostic-* : surface compiler-style warnings (unused variables, conversions, etc.) +# clang-diagnostic-unused-const-variable : warn on unused 'const' variables # google-build-using-namespace : reject global using-namespace directives # modernize-deprecated-headers : prefer C++ standard headers over legacy C ones # modernize-loop-convert : prefer range-based for loops over traditional loops # modernize-use-stdarray : prefer 'std::array' over C-style arrays # modernize-use-using : prefer 'using' type alias declarations over 'typedef's +# readability-magic-numbers : discourage use of magic numbers in code Checks: > - clang-diagnostic-*, clang-analyzer-*, + clang-diagnostic-*, + clang-diagnostic-unused-const-variable, google-build-using-namespace, modernize-deprecated-headers, modernize-loop-convert, modernize-use-stdarray, modernize-use-using + WarningsAsErrors: '*' diff --git a/CMakeLists.txt b/CMakeLists.txt index 51ca1b6..3f83888 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ -cmake_minimum_required(VERSION 3.10) # Set minimum cmake version (what's set in this version of image version) -project(main) # set project name -set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard +cmake_minimum_required(VERSION 3.20) # C++20 features require newer CMake tooling +project(main LANGUAGES CXX) # set project name and language + +set(CMAKE_CXX_STANDARD 20) # Enable C++20 standard +set(CMAKE_CXX_STANDARD_REQUIRED ON) # Fail configuration if the compiler can't do C++20 +set(CMAKE_CXX_EXTENSIONS OFF) # Use -std=c++20, not compiler-specific gnu++20 set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json for tooling set(SOURCE_FILES main.cpp) # Add main.cpp file of project root directory as source file diff --git a/main.cpp b/main.cpp index 0249c19..a45797e 100644 --- a/main.cpp +++ b/main.cpp @@ -58,17 +58,21 @@ const float ZOOM_SCALE = 0.01; constexpr int BOARD_SIZE = 19; -GLdouble camXPos = 0.0; -GLdouble camYPos = 0.0; -GLdouble camZPos = -1.5; - +// Global Constants +// Camera initial position +constexpr GLdouble INITIAL_CAM_X = 0.0; +constexpr GLdouble INITIAL_CAM_Y = 0.0; +constexpr GLdouble INITIAL_CAM_Z = -1.5; constexpr float PI = 3.14159265358979323846F; // Pi constant for trigonometric helpers -const GLdouble CAMERA_FOVY = 60.0; -const GLdouble NEAR_CLIP = 0.1; -const GLdouble FAR_CLIP = 1000.0; +struct Camera { + GLdouble x; + GLdouble y; + GLdouble z; +}; + + -// global variables int wireframe = 0; int lighting = 1; int material = 1; @@ -79,11 +83,13 @@ int depthTest = 1; int cullFace = 1; int smooth = 1; int enabletexture = 0; -float angle_y = 0; float angle_x = 45; +float angle_y = 0; float angle2 = 0; // Useless float translatelight = 0; +Camera camera{ INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z }; + // Behind the Scenes variables int placex = 0; int placey = 0; @@ -107,8 +113,8 @@ void keyboard(unsigned char, int, int); void init(); void idle(); void SetImage(); -void DrawSphere(int color); -void DrawUnitCube(int color); +void DrawSphere(int); +void DrawUnitCube(int); void ApplyTransformations(float indx, float indy, float z); void ApplyTransformationGeneral(float indx, float indy, float z); @@ -158,7 +164,7 @@ int main(int argc, char** argv) { return 0; } -void keyboard(unsigned char key, int x, int y) +void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) { /* @@ -343,9 +349,9 @@ void motion(int x, int y) // If the RMB is pressed and dragged then zoom in / out if (updateCamZPos) { - // Update camera z position - camZPos += (y - lastY) * ZOOM_SCALE; - camXPos += (x - lastX) * ZOOM_SCALE; + // Update camera position while the mouse is dragged + camera.z += (y - lastY) * ZOOM_SCALE; + camera.x += (x - lastX) * ZOOM_SCALE; lastX = x; lastY = y; @@ -443,8 +449,9 @@ void lightingFunc() glLightfv(GL_LIGHT0, GL_DIFFUSE, lightstrength); // Specify specular component. Specular component is green. - //GLfloat lightspecular[4] = {0.0, 0.0, 0.0, 1.0}; - GLfloat lightspecular[4] = { 0.0, 2.0, 0.0, 1.0 }; + // TODO: Decide on desired specular component -- IF NEEDED + // GLfloat lightspecular[4] = {0.0, 0.0, 0.0, 1.0}; + // GLfloat lightspecular[4] = { 0.0, 2.0, 0.0, 1.0 }; glLightfv(GL_LIGHT0, GL_SPECULAR, lightstrength); GLfloat spread = 90 - 90 * t; @@ -620,7 +627,7 @@ void display() glLoadIdentity(); // Specify camera transformation - glTranslatef(camXPos, camYPos, camZPos); + glTranslatef(static_cast(camera.x), static_cast(camera.y), static_cast(camera.z)); // Specify the lighting we'll be using for this app. Note that // the lights can be transformed using the usual translate, rotate, @@ -702,7 +709,7 @@ void display() glutSwapBuffers(); } -void ApplyTransformations(float indx, float indy, float z) +void ApplyTransformations(float indx, float indy, [[maybe_unused]] float z) { int i; if (indx < 0) diff --git a/scripts/run_lint.sh b/scripts/run_lint.sh index 57a2011..bf9723f 100755 --- a/scripts/run_lint.sh +++ b/scripts/run_lint.sh @@ -6,7 +6,12 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" BUILD_DIR="${REPO_ROOT}/build" # Configure the build tree and (re)generate compile_commands.json used by the linters. -cmake -S "${REPO_ROOT}" -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON +# Enable comprehensive warnings so clang diagnostics (unused constants, etc.) surface during analysis. +cmake -S "${REPO_ROOT}" \ + -B "${BUILD_DIR}" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic" # Static analysis with clang-tidy; uses the compile database for accurate diagnostics. clang-tidy "${REPO_ROOT}/main.cpp" -p "${BUILD_DIR}" From 16c7217408dd708643120ac4ec4796fc43c61f8b Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 22:56:59 -0500 Subject: [PATCH 6/8] chore: additional cleanup --- main.cpp | 57 ++++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/main.cpp b/main.cpp index a45797e..75157f4 100644 --- a/main.cpp +++ b/main.cpp @@ -57,6 +57,7 @@ int lastY = 0; const float ZOOM_SCALE = 0.01; constexpr int BOARD_SIZE = 19; +constexpr int BOARD_CENTER = BOARD_SIZE / 2; // Global Constants // Camera initial position @@ -83,8 +84,11 @@ int depthTest = 1; int cullFace = 1; int smooth = 1; int enabletexture = 0; -float angle_x = 45; -float angle_y = 0; + +constexpr int INITIAL_TEAPOT_ANGLE_X = 45; +constexpr int INITIAL_TEAPOT_ANGLE_Y = 0; +float angle_x = INITIAL_TEAPOT_ANGLE_X; +float angle_y = INITIAL_TEAPOT_ANGLE_Y; float angle2 = 0; // Useless float translatelight = 0; @@ -95,9 +99,9 @@ int placex = 0; int placey = 0; int col = 1; float t = 0; -float inc = 0.002; // Depicts how fast time increments. +constexpr float TIME_INCREMENT = 0.002; // Depicts how fast time increments. - // Behind the Scenes +// Behind the Scenes std::array, BOARD_SIZE> board_status{}; std::array, BOARD_SIZE> liberties_status{}; int restart_option = 0; @@ -128,17 +132,21 @@ void jump_off(int x0, int y0, int color); //! Program entry point int main(int argc, char** argv) { - + const int DEFAULT_WINDOW_WIDTH = 512; + const int DEFAULT_WINDOW_HEIGHT = 512; + const int DEFAULT_WINDOW_X = 100; + const int DEFAULT_WINDOW_Y = 100; + const char *WINDOW_TITLE = "Go Board Game"; // initialize GLUT glutInit(&argc, argv); // set visual glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); // set physical window properties - glutInitWindowSize(512, 512); + glutInitWindowSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); // position window on the screen - glutInitWindowPosition(100, 100); + glutInitWindowPosition(DEFAULT_WINDOW_X, DEFAULT_WINDOW_Y); // create window - windowID = glutCreateWindow("hello"); + windowID = glutCreateWindow(WINDOW_TITLE); ilInit(); iluInit(); @@ -279,35 +287,35 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) case 'a': case 'A': - if (placex > -9) { placex -= 1; } + if (placex > -BOARD_CENTER) { placex -= 1; } break; case 'w': case 'W': - if (placey < 9) { placey += 1; } + if (placey < BOARD_CENTER) { placey += 1; } break; case 's': case 'S': - if (placey > -9) { placey -= 1; } + if (placey > -BOARD_CENTER) { placey -= 1; } break; case 'd': case 'D': - if (placex < 9) { placex += 1; } + if (placex < BOARD_CENTER) { placex += 1; } break; - case 13: - if (board_status[placex + 9][placey + 9] != 0) + case '\r': + if (board_status[placex + BOARD_CENTER][placey + BOARD_CENTER] != 0) { std::cout << "YOU CAN'T PLACE A PIECE HERE BECAUSE THERE ALREADY IS A PIECE HERE!!!\n"; } else { std::cout << "ENTER KEY PRESSED!!!\n"; - make_move(placex + 9, placey + 9, col); + make_move(placex + BOARD_CENTER, placey + BOARD_CENTER, col); if (col == 1) { col = 2; } else { col = 1; } } @@ -380,23 +388,6 @@ void mouse(int button, int state, int x, int y) } } -void printMatrix() -{ - float matrixData[16]; - - glGetFloatv(GL_MODELVIEW_MATRIX, matrixData); - - std::cout << std::endl; - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - std::cout << matrixData[i + 4 * j] << ", "; - } - - std::cout << std::endl; - } -} - void idle() { @@ -692,7 +683,7 @@ void display() for (const auto& piece : L) { jump_off(piece[0], piece[1], piece[2]); } - t += (inc*L.size()); + t += (TIME_INCREMENT*L.size()); } if (t > 1) { t = 0; From 847369e77f8e43f22e797ba09d23a8b4d4cafb2a Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 23:27:05 -0500 Subject: [PATCH 7/8] chore: adds .clang-format --- .clang-format | 246 +++++ main.cpp | 1583 +++++++++++++++---------------- scripts/install_dependencies.sh | 1 + scripts/run_lint.sh | 3 + 4 files changed, 1027 insertions(+), 806 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..297ee4f --- /dev/null +++ b/.clang-format @@ -0,0 +1,246 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 88 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +... + diff --git a/main.cpp b/main.cpp index 75157f4..c229421 100644 --- a/main.cpp +++ b/main.cpp @@ -1,24 +1,24 @@ // OLD INCLUDES/USINGS -//#include -//#include -//#include +// #include +// #include +// #include // Standard library #include #include #include #include -//For Sleep in Windows -//#include -//For Sleep in Linux +// For Sleep in Windows +// #include +// For Sleep in Linux #include -//#pragma comment(lib, "ILUT.lib") +// #pragma comment(lib, "ILUT.lib") #include -//For Sleep in Windows -//#include -//For Sleep in Linux +// For Sleep in Windows +// #include +// For Sleep in Linux #include #include @@ -32,28 +32,27 @@ #include #include -ILuint il[3] = { 0, 1, 2 }; -GLuint texture[3] = { 0, 1, 2 }; - +ILuint il[3] = {0, 1, 2}; +GLuint texture[3] = {0, 1, 2}; // For the queue -#include #include +#include #include #define GL_CLAMP_TO_EDGE 0x812F // Window settings -int windowID; // Glut window ID (for display) +int windowID; // Glut window ID (for display) - // Camera methods +// Camera methods void mouse(int button, int state, int x, int y); void motion(int x, int y); // Camera settings bool updateCamZPos = false; -int lastX = 0; -int lastY = 0; +int lastX = 0; +int lastY = 0; const float ZOOM_SCALE = 0.01; constexpr int BOARD_SIZE = 19; @@ -67,13 +66,11 @@ constexpr GLdouble INITIAL_CAM_Z = -1.5; constexpr float PI = 3.14159265358979323846F; // Pi constant for trigonometric helpers struct Camera { - GLdouble x; - GLdouble y; - GLdouble z; + GLdouble x; + GLdouble y; + GLdouble z; }; - - int wireframe = 0; int lighting = 1; int material = 1; @@ -92,7 +89,7 @@ float angle_y = INITIAL_TEAPOT_ANGLE_Y; float angle2 = 0; // Useless float translatelight = 0; -Camera camera{ INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z }; +Camera camera{INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z}; // Behind the Scenes variables int placex = 0; @@ -108,8 +105,8 @@ int restart_option = 0; std::queue rm_queue; std::list> L; -//float rm_array[1083]; // Holds the objects that will be removed. -//int p = 0; // Always points to the last index of rm_array. +// float rm_array[1083]; // Holds the objects that will be removed. +// int p = 0; // Always points to the last index of rm_array. // declaration, forward void display(); @@ -131,606 +128,592 @@ void remove_block(int x, int y, int piece); void jump_off(int x0, int y0, int color); //! Program entry point -int main(int argc, char** argv) { - const int DEFAULT_WINDOW_WIDTH = 512; - const int DEFAULT_WINDOW_HEIGHT = 512; - const int DEFAULT_WINDOW_X = 100; - const int DEFAULT_WINDOW_Y = 100; - const char *WINDOW_TITLE = "Go Board Game"; - // initialize GLUT - glutInit(&argc, argv); - // set visual - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); - // set physical window properties - glutInitWindowSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); - // position window on the screen - glutInitWindowPosition(DEFAULT_WINDOW_X, DEFAULT_WINDOW_Y); - // create window - windowID = glutCreateWindow(WINDOW_TITLE); - - ilInit(); - iluInit(); - ilutInit(); - ilutRenderer(ILUT_OPENGL); - - ilGenImages(2, il); - glGenTextures(2, texture); - - // initialize OpenGL - init(); - - // register rendering mainloop - glutKeyboardFunc(keyboard); - glutDisplayFunc(display); - glutIdleFunc(idle); - - glutMouseFunc(mouse); // Call mouse whenever mouse button pressed - glutMotionFunc(motion); // Call motion whenever mouse moves while button pressed - // let's rock ... - glutMainLoop(); - - return 0; +int main(int argc, char **argv) { + const int DEFAULT_WINDOW_WIDTH = 512; + const int DEFAULT_WINDOW_HEIGHT = 512; + const int DEFAULT_WINDOW_X = 100; + const int DEFAULT_WINDOW_Y = 100; + const char *WINDOW_TITLE = "Go Board Game"; + // initialize GLUT + glutInit(&argc, argv); + // set visual + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); + // set physical window properties + glutInitWindowSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); + // position window on the screen + glutInitWindowPosition(DEFAULT_WINDOW_X, DEFAULT_WINDOW_Y); + // create window + windowID = glutCreateWindow(WINDOW_TITLE); + + ilInit(); + iluInit(); + ilutInit(); + ilutRenderer(ILUT_OPENGL); + + ilGenImages(2, il); + glGenTextures(2, texture); + + // initialize OpenGL + init(); + + // register rendering mainloop + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutIdleFunc(idle); + + glutMouseFunc(mouse); // Call mouse whenever mouse button pressed + glutMotionFunc(motion); // Call motion whenever mouse moves while button + // pressed let's rock ... + glutMainLoop(); + + return 0; } -void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) -{ - /* - - 1 : Toggle specularity - 2 : Toggle lighting - 3 : Toggle wireframe - 4 : Toggle light animation - 5 : Toggle depth testing - 6 : Toggle culling (try disabling both depth testing and culling) - 7 : Toggle between smooth and flat shading - 8 : Toggle texture - - o,O : Toggle teapot rotation along the y-axis - p,P : Toggle teapot rotation along the x-axis - r,R : Activate "reset board option" - y,Y : Confirm "reset board option" - n,N : Cancel "reset board option" - v,V : Set color to white (This makes testing a bit faster) - b,B : Set color to black (This makes testing a bit faster) - - wasd : Move a piece around the board - enter : Place a piece on the board - - ON RIGHT CLICK AND HOLD MOUSE: - slide left : move camera left - slide right : move camera right - slide up : zoom camera in - slide down : zoom camera out - */ - - switch (key) - { - case '1': - // Enable/disable wireframe mode - wireframe = !wireframe; - - if (wireframe) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - } - else { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } - - break; - - case '3': - material = !material; - - break; - - case '5': - depthTest = !depthTest; - - if (depthTest) { - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); - } - else { - glDisable(GL_DEPTH_TEST); - } - - break; - - case '6': - cullFace = !cullFace; - - if (cullFace) { - glEnable(GL_CULL_FACE); - } - else { - glDisable(GL_CULL_FACE); - } - - break; - - case '7': - smooth = !smooth; - - if (smooth) { - glShadeModel(GL_SMOOTH); - } - else { - glShadeModel(GL_FLAT); - } - - break; - - case '8': - enabletexture = !enabletexture; - - if (enabletexture) { - glEnable(GL_TEXTURE_2D); - } - else { - glDisable(GL_TEXTURE_2D); - } - break; - - case 'o': - case 'O': - std::cout << "PRESSED O\n"; - pauseTeapot_y = !pauseTeapot_y; - - break; - - case 'p': - case 'P': - std::cout << "PRESSED P\n"; - pauseTeapot_x = !pauseTeapot_x; - - break; - - case 'a': - case 'A': - if (placex > -BOARD_CENTER) { placex -= 1; } - - break; - - case 'w': - case 'W': - if (placey < BOARD_CENTER) { placey += 1; } - - break; - case 's': - case 'S': - if (placey > -BOARD_CENTER) { placey -= 1; } - - break; - case 'd': - case 'D': - if (placex < BOARD_CENTER) { placex += 1; } - - break; - - case '\r': - if (board_status[placex + BOARD_CENTER][placey + BOARD_CENTER] != 0) - { - std::cout << "YOU CAN'T PLACE A PIECE HERE BECAUSE THERE ALREADY IS A PIECE HERE!!!\n"; - } - else - { - std::cout << "ENTER KEY PRESSED!!!\n"; - make_move(placex + BOARD_CENTER, placey + BOARD_CENTER, col); - if (col == 1) { col = 2; } - else { col = 1; } - } - break; - case 'r': - case 'R': - std::cout << "You pressed 'r', the restart button. Press 'y' to confirm restart. Press 'n' to cancel.\n"; - restart_option = 1; - break; - case 'n': - case 'N': - if (restart_option) { - std::cout << "You pressed 'n'. Restart option cancelled.\n"; - restart_option = 0; - } - break; - case 'y': - case 'Y': - if (restart_option) { - std::cout << "You pressed 'y'. The game has been restarted.\n"; - init_board(); - col = 1; - } - break; - - case 'b': - case 'B': - col = 2; break; - case 'v': - case 'V': - col = 1; break; - - } +void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) { + /* + + 1 : Toggle specularity + 2 : Toggle lighting + 3 : Toggle wireframe + 4 : Toggle light animation + 5 : Toggle depth testing + 6 : Toggle culling (try disabling both depth testing and culling) + 7 : Toggle between smooth and flat shading + 8 : Toggle texture + + o,O : Toggle teapot rotation along the y-axis + p,P : Toggle teapot rotation along the x-axis + r,R : Activate "reset board option" + y,Y : Confirm "reset board option" + n,N : Cancel "reset board option" + v,V : Set color to white (This makes testing a bit faster) + b,B : Set color to black (This makes testing a bit faster) + + wasd : Move a piece around the board + enter : Place a piece on the board + + ON RIGHT CLICK AND HOLD MOUSE: + slide left : move camera left + slide right : move camera right + slide up : zoom camera in + slide down : zoom camera out + */ + + switch (key) { + case '1': + // Enable/disable wireframe mode + wireframe = !wireframe; + + if (wireframe) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } + + break; + + case '3': + material = !material; + + break; + + case '5': + depthTest = !depthTest; + + if (depthTest) { + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + } else { + glDisable(GL_DEPTH_TEST); + } + + break; + + case '6': + cullFace = !cullFace; + + if (cullFace) { + glEnable(GL_CULL_FACE); + } else { + glDisable(GL_CULL_FACE); + } + + break; + + case '7': + smooth = !smooth; + + if (smooth) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + + break; + + case '8': + enabletexture = !enabletexture; + + if (enabletexture) { + glEnable(GL_TEXTURE_2D); + } else { + glDisable(GL_TEXTURE_2D); + } + break; + + case 'o': + case 'O': + std::cout << "PRESSED O\n"; + pauseTeapot_y = !pauseTeapot_y; + + break; + + case 'p': + case 'P': + std::cout << "PRESSED P\n"; + pauseTeapot_x = !pauseTeapot_x; + + break; + + case 'a': + case 'A': + if (placex > -BOARD_CENTER) { + placex -= 1; + } + + break; + + case 'w': + case 'W': + if (placey < BOARD_CENTER) { + placey += 1; + } + + break; + case 's': + case 'S': + if (placey > -BOARD_CENTER) { + placey -= 1; + } + + break; + case 'd': + case 'D': + if (placex < BOARD_CENTER) { + placex += 1; + } + + break; + + case '\r': + if (board_status[placex + BOARD_CENTER][placey + BOARD_CENTER] != 0) { + std::cout << "YOU CAN'T PLACE A PIECE HERE BECAUSE THERE ALREADY IS A " + "PIECE HERE!!!\n"; + } else { + std::cout << "ENTER KEY PRESSED!!!\n"; + make_move(placex + BOARD_CENTER, placey + BOARD_CENTER, col); + if (col == 1) { + col = 2; + } else { + col = 1; + } + } + break; + case 'r': + case 'R': + std::cout << "You pressed 'r', the restart button. Press 'y' to confirm " + "restart. Press 'n' to cancel.\n"; + restart_option = 1; + break; + case 'n': + case 'N': + if (restart_option) { + std::cout << "You pressed 'n'. Restart option cancelled.\n"; + restart_option = 0; + } + break; + case 'y': + case 'Y': + if (restart_option) { + std::cout << "You pressed 'y'. The game has been restarted.\n"; + init_board(); + col = 1; + } + break; + + case 'b': + case 'B': + col = 2; + break; + case 'v': + case 'V': + col = 1; + break; + } } // Handles mouse motion events while a button is pressed -void motion(int x, int y) -{ - // If the RMB is pressed and dragged then zoom in / out - if (updateCamZPos) - { - // Update camera position while the mouse is dragged - camera.z += (y - lastY) * ZOOM_SCALE; - camera.x += (x - lastX) * ZOOM_SCALE; - lastX = x; - lastY = y; - - // Redraw the scene from updated camera position - glutSetWindow(windowID); - glutPostRedisplay(); - } +void motion(int x, int y) { + // If the RMB is pressed and dragged then zoom in / out + if (updateCamZPos) { + // Update camera position while the mouse is dragged + camera.z += (y - lastY) * ZOOM_SCALE; + camera.x += (x - lastX) * ZOOM_SCALE; + lastX = x; + lastY = y; + + // Redraw the scene from updated camera position + glutSetWindow(windowID); + glutPostRedisplay(); + } } // Handles mouse button pressed / released events -void mouse(int button, int state, int x, int y) -{ - // If the RMB is pressed and dragged then zoom in / out - if (button == GLUT_RIGHT_BUTTON) - { - if (state == GLUT_DOWN) - { - lastX = x; - lastY = y; - updateCamZPos = true; - } - else - { - updateCamZPos = false; - } - } +void mouse(int button, int state, int x, int y) { + // If the RMB is pressed and dragged then zoom in / out + if (button == GLUT_RIGHT_BUTTON) { + if (state == GLUT_DOWN) { + lastX = x; + lastY = y; + updateCamZPos = true; + } else { + updateCamZPos = false; + } + } } -void idle() -{ +void idle() { + if (!pauseTeapot_y) { + angle_y = angle_y + 0.5; - if (!pauseTeapot_y) { - angle_y = angle_y + 0.5; + if (angle_y > 360) { + angle_y = angle_y - 360; + } + } - if (angle_y > 360) { - angle_y = angle_y - 360; - } - } + if (!pauseTeapot_x) { + angle_x = angle_x + 0.5; - if (!pauseTeapot_x) { - angle_x = angle_x + 0.5; + if (angle_x > 360) { + angle_x = angle_x - 360; + } + } - if (angle_x > 360) { - angle_x = angle_x - 360; - } - } + angle2 = angle2 + 0.5; - angle2 = angle2 + 0.5; + if (angle2 > 360) { + angle2 = angle2 - 360; + } - if (angle2 > 360) { - angle2 = angle2 - 360; - } + /* + if (!pauseLighting) { + translatelight = translatelight + 0.5; - /* - if (!pauseLighting) { - translatelight = translatelight + 0.5; + if (translatelight > 360) { + translatelight = translatelight - 360; + } + } + */ - if (translatelight > 360) { - translatelight = translatelight - 360; - } - } - */ - - glutPostRedisplay(); + glutPostRedisplay(); } +void lightingFunc() { + // Specify light position + GLfloat lightposition[4] = {0.0, 0.0, -0.5, 1.0}; + glLightfv(GL_LIGHT0, GL_POSITION, lightposition); -void lightingFunc() -{ - - // Specify light position - GLfloat lightposition[4] = { 0.0, 0.0, -0.5, 1.0 }; - glLightfv(GL_LIGHT0, GL_POSITION, lightposition); + // Specify diffuse component. Diffuse component is white. + // GLfloat lightdiffuse[4] = {0.0, 0.0, 0.0, 1.0}; + GLfloat lightstrength[4] = {2.0, 2.0, 2.0, 2.0}; + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightstrength); - // Specify diffuse component. Diffuse component is white. - //GLfloat lightdiffuse[4] = {0.0, 0.0, 0.0, 1.0}; - GLfloat lightstrength[4] = { 2.0, 2.0, 2.0, 2.0 }; - glLightfv(GL_LIGHT0, GL_DIFFUSE, lightstrength); + // Specify specular component. Specular component is green. + // TODO: Decide on desired specular component -- IF NEEDED + // GLfloat lightspecular[4] = {0.0, 0.0, 0.0, 1.0}; + // GLfloat lightspecular[4] = { 0.0, 2.0, 0.0, 1.0 }; + glLightfv(GL_LIGHT0, GL_SPECULAR, lightstrength); - // Specify specular component. Specular component is green. - // TODO: Decide on desired specular component -- IF NEEDED - // GLfloat lightspecular[4] = {0.0, 0.0, 0.0, 1.0}; - // GLfloat lightspecular[4] = { 0.0, 2.0, 0.0, 1.0 }; - glLightfv(GL_LIGHT0, GL_SPECULAR, lightstrength); + GLfloat spread = 90 - 90 * t; + glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, &spread); - GLfloat spread = 90 - 90 * t; - glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, &spread); - - glEnable(GL_LIGHT0); + glEnable(GL_LIGHT0); } -void materialFunc() -{ - // Add a diffuse component to our teapot. The diffuse reflection constant - // is white (white light source produces white reflection). - GLfloat materialdiffuse[4] = { 0.5, 0.5, 1.0, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialdiffuse); - - // Add a specular component to our teapot. The specular reflection constant - // is white (white light source produces white reflection). - GLfloat materialspecular[4] = { 1.0, 1.0, 1.0, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialspecular); - - // Defines the shinyness (the exponent to the phong model). - GLfloat materialshininess[1] = { 100.0 }; - glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, materialshininess); -} +void materialFunc() { + // Add a diffuse component to our teapot. The diffuse reflection constant + // is white (white light source produces white reflection). + GLfloat materialdiffuse[4] = {0.5, 0.5, 1.0, 1.0}; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialdiffuse); + // Add a specular component to our teapot. The specular reflection constant + // is white (white light source produces white reflection). + GLfloat materialspecular[4] = {1.0, 1.0, 1.0, 1.0}; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialspecular); -void DrawSphere(int color) -{ - float colorNone[4] = { 0.0, 0.0, 0.0, 0.0 }; - - if (color == 0) - { - float colorRed[4] = { 1.0, 0.0, 0.0, 0.0 }; - glColor4fv(colorRed); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorRed); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - - if (color == 1) - { - float colorWhite[4] = { 1.0, 1.0, 1.0, 1.0 }; - glColor4fv(colorWhite); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorWhite); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - - if (color == 2) - { - float colorBlack[4] = { 0.0, 0.0, 0.0, 0.0 }; - glColor4fv(colorBlack); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlack); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - - if (color == 3) - { - float colorGreen[4] = { 0.0, 0.0, 1.0, 0.0 }; - glColor4fv(colorGreen); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorGreen); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - - if (color == 4) - { - float colorBlue[4] = { 0.0, 1.0, 0.0, 0.0 }; - glColor4fv(colorBlue); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - - - - glBegin(GL_TRIANGLES); - GLUquadricObj *quadratic; - quadratic = gluNewQuadric(); // Create A Pointer To The Quadric Object - gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals - gluQuadricTexture(quadratic, GL_TRUE); // Create Texture Coords - - gluSphere(quadratic, 1.0f, 32, 32); - glEnd(); + // Defines the shinyness (the exponent to the phong model). + GLfloat materialshininess[1] = {100.0}; + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, materialshininess); } -void DrawUnitCube(int color) -{ - if (color == 0) { glBindTexture(GL_TEXTURE_2D, texture[0]); } - else if (color == 3) - { - float colorNone[4] = { 0.0, 0.0, 0.0, 0.0 }; - float colorGreen[4] = { 0.0, 0.0, 1.0, 0.0 }; - glColor4fv(colorGreen); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorGreen); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - else if (color == 4) - { - float colorNone[4] = { 0.0, 0.0, 0.0, 0.0 }; - float colorBlue[4] = { 0.0, 1.0, 0.0, 0.0 }; - glColor4fv(colorBlue); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); - } - - glBegin(GL_QUADS); - - // Front Face - glNormal3f(0.0f, 0.0f, 2.0f); - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); - glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); - glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); - // Back Face - glNormal3f(0.0f, 0.0f, -2.0f); - glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); - glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); - glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); - glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, -1.0f); - // Bottom Face - glNormal3f(0.0f, -2.0f, 0.0f); - glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); - glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f); - glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); - glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); - // Right face - glNormal3f(2.0f, 0.0f, 0.0f); - glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, -1.0f); - glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); - glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); - glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); - // Left Face - glNormal3f(-2.0f, 0.0f, 0.0f); - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); - glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); - glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); - - if (color == 0) - { - glEnd(); - - glBindTexture(GL_TEXTURE_2D, texture[1]); - glBegin(GL_QUADS); - } - - // Top Face - glNormal3f(0.0f, 2.0f, 0.0f); - glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); - glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); - glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 1.0f); - glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); - - glEnd(); - - // Windows - //Sleep(3000); - // Linux - usleep(3000); - +void DrawSphere(int color) { + float colorNone[4] = {0.0, 0.0, 0.0, 0.0}; + + if (color == 0) { + float colorRed[4] = {1.0, 0.0, 0.0, 0.0}; + glColor4fv(colorRed); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorRed); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } + + if (color == 1) { + float colorWhite[4] = {1.0, 1.0, 1.0, 1.0}; + glColor4fv(colorWhite); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorWhite); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } + + if (color == 2) { + float colorBlack[4] = {0.0, 0.0, 0.0, 0.0}; + glColor4fv(colorBlack); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlack); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } + + if (color == 3) { + float colorGreen[4] = {0.0, 0.0, 1.0, 0.0}; + glColor4fv(colorGreen); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorGreen); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } + + if (color == 4) { + float colorBlue[4] = {0.0, 1.0, 0.0, 0.0}; + glColor4fv(colorBlue); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } + + glBegin(GL_TRIANGLES); + GLUquadricObj *quadratic; + quadratic = gluNewQuadric(); // Create A Pointer To The Quadric Object + gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals + gluQuadricTexture(quadratic, GL_TRUE); // Create Texture Coords + + gluSphere(quadratic, 1.0f, 32, 32); + glEnd(); } -void display() -{ - // clear screen to background color - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // draw a white quad - glColor4f(1.0, 1.0, 1.0, 1.0); - - // Push lighting bit; we'll pop it later so that the lighting state - // isn't saved onto the next frame. We do this so that we can disable - // lighting more easily. - glPushAttrib(GL_LIGHTING_BIT); - - glLoadIdentity(); - - // Specify camera transformation - glTranslatef(static_cast(camera.x), static_cast(camera.y), static_cast(camera.z)); - - // Specify the lighting we'll be using for this app. Note that - // the lights can be transformed using the usual translate, rotate, - // and scale commands. - glPushMatrix(); - - //////////////////// MOVING LIGHT!!!!! //////////////////// - glTranslatef(2.0F * std::sin(translatelight * 2.0F * PI / 360.0F), 0.0F, 0.0F); - - if (lighting) { - lightingFunc(); - } - - glPopMatrix(); - - - glTranslatef(0.0, 0.0, -2.0); // Move objects to viewing area. - glRotatef(angle_x, 1.0, 0.0, 0.0); // To allow rotation on the x-axis - glRotatef(angle_y, 0.0, 1.0, 0.0); // To allow rotation on the y-axis - glPushMatrix(); - - glScalef(1.0, 0.05, 1.0); // Flatten the Cube. - // It should look like a board now. - - // Specify material for the teapot we'll be drawing. - if (material) { - materialFunc(); - } - - DrawUnitCube(0); - - - glPopMatrix(); - glPushMatrix(); - // Draw Beads - - glBindTexture(GL_TEXTURE_2D, 0); - - glScalef(0.0525, 0.0525, 0.0525); // Just the right size :) - glTranslatef(0.0, 1.0, 0.0); // The centre - - - glPushMatrix(); - ApplyTransformations(placex, placey, 0); - DrawSphere(0); - glPopMatrix(); - - for (int i = 0; i < 19; i++) { - for (int j = 0; j < 19; j++) { - if (board_status[i][j] != 0) { - glPushMatrix(); - ApplyTransformations(i - 9, j - 9, 0); - DrawSphere(board_status[i][j]); - glPopMatrix(); - } - } - } - - // THE REMOVAL OF PIECE PORTION - if (!L.empty()) { - - for (const auto& piece : L) { - jump_off(piece[0], piece[1], piece[2]); - } - t += (TIME_INCREMENT*L.size()); - } - if (t > 1) { - t = 0; - L.clear(); - } - - glPopMatrix(); - glPopAttrib(); - - // immediately process commands - glFlush(); +void DrawUnitCube(int color) { + if (color == 0) { + glBindTexture(GL_TEXTURE_2D, texture[0]); + } else if (color == 3) { + float colorNone[4] = {0.0, 0.0, 0.0, 0.0}; + float colorGreen[4] = {0.0, 0.0, 1.0, 0.0}; + glColor4fv(colorGreen); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorGreen); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } else if (color == 4) { + float colorNone[4] = {0.0, 0.0, 0.0, 0.0}; + float colorBlue[4] = {0.0, 1.0, 0.0, 0.0}; + glColor4fv(colorBlue); + glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue); + glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + } + + glBegin(GL_QUADS); + + // Front Face + glNormal3f(0.0f, 0.0f, 2.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + // Back Face + glNormal3f(0.0f, 0.0f, -2.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + // Bottom Face + glNormal3f(0.0f, -2.0f, 0.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + // Right face + glNormal3f(2.0f, 0.0f, 0.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + // Left Face + glNormal3f(-2.0f, 0.0f, 0.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + if (color == 0) { + glEnd(); + + glBindTexture(GL_TEXTURE_2D, texture[1]); + glBegin(GL_QUADS); + } + + // Top Face + glNormal3f(0.0f, 2.0f, 0.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + glEnd(); + + // Windows + // Sleep(3000); + // Linux + usleep(3000); +} - // immediately call display loop again - glutSwapBuffers(); +void display() { + // clear screen to background color + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // draw a white quad + glColor4f(1.0, 1.0, 1.0, 1.0); + + // Push lighting bit; we'll pop it later so that the lighting state + // isn't saved onto the next frame. We do this so that we can disable + // lighting more easily. + glPushAttrib(GL_LIGHTING_BIT); + + glLoadIdentity(); + + // Specify camera transformation + glTranslatef(static_cast(camera.x), static_cast(camera.y), + static_cast(camera.z)); + + // Specify the lighting we'll be using for this app. Note that + // the lights can be transformed using the usual translate, rotate, + // and scale commands. + glPushMatrix(); + + //////////////////// MOVING LIGHT!!!!! //////////////////// + glTranslatef(2.0F * std::sin(translatelight * 2.0F * PI / 360.0F), 0.0F, 0.0F); + + if (lighting) { + lightingFunc(); + } + + glPopMatrix(); + + glTranslatef(0.0, 0.0, -2.0); // Move objects to viewing area. + glRotatef(angle_x, 1.0, 0.0, 0.0); // To allow rotation on the x-axis + glRotatef(angle_y, 0.0, 1.0, 0.0); // To allow rotation on the y-axis + glPushMatrix(); + + glScalef(1.0, 0.05, 1.0); // Flatten the Cube. + // It should look like a board now. + + // Specify material for the teapot we'll be drawing. + if (material) { + materialFunc(); + } + + DrawUnitCube(0); + + glPopMatrix(); + glPushMatrix(); + // Draw Beads + + glBindTexture(GL_TEXTURE_2D, 0); + + glScalef(0.0525, 0.0525, 0.0525); // Just the right size :) + glTranslatef(0.0, 1.0, 0.0); // The centre + + glPushMatrix(); + ApplyTransformations(placex, placey, 0); + DrawSphere(0); + glPopMatrix(); + + for (int i = 0; i < 19; i++) { + for (int j = 0; j < 19; j++) { + if (board_status[i][j] != 0) { + glPushMatrix(); + ApplyTransformations(i - 9, j - 9, 0); + DrawSphere(board_status[i][j]); + glPopMatrix(); + } + } + } + + // THE REMOVAL OF PIECE PORTION + if (!L.empty()) { + for (const auto &piece : L) { + jump_off(piece[0], piece[1], piece[2]); + } + t += (TIME_INCREMENT * L.size()); + } + if (t > 1) { + t = 0; + L.clear(); + } + + glPopMatrix(); + glPopAttrib(); + + // immediately process commands + glFlush(); + + // immediately call display loop again + glutSwapBuffers(); } -void ApplyTransformations(float indx, float indy, [[maybe_unused]] float z) -{ - int i; - if (indx < 0) - { - for (i = 0; i < std::abs(indx); i++) - { - glTranslatef(-2.0, 0.0, 0.0); - } - } - else - { - for (i = 0; i 18 || y < 0 || y > 18) { - return 0; - } - if (board_status[x][y] == 0) { - return 1; - } - if (board_status[x][y] != piece) { - return 0; - } - if (liberties_status[x][y] != -1) { - return liberties_status[x][y]; - } - int direcx = x - originx; - int direcy = y - originy; - if ((direcx >= 0 && check_liberties(x + 1, y, originx, originy, piece)) || - (direcx <= 0 && check_liberties(x - 1, y, originx, originy, piece)) || - (direcy >= 0 && check_liberties(x, y + 1, originx, originy, piece)) || - (direcy <= 0 && check_liberties(x, y - 1, originx, originy, piece))) { - liberties_status[x][y] = 1; - } - else { - liberties_status[x][y] = 0; - } - return liberties_status[x][y]; + if (x < 0 || x > 18 || y < 0 || y > 18) { + return 0; + } + if (board_status[x][y] == 0) { + return 1; + } + if (board_status[x][y] != piece) { + return 0; + } + if (liberties_status[x][y] != -1) { + return liberties_status[x][y]; + } + int direcx = x - originx; + int direcy = y - originy; + if ((direcx >= 0 && check_liberties(x + 1, y, originx, originy, piece)) || + (direcx <= 0 && check_liberties(x - 1, y, originx, originy, piece)) || + (direcy >= 0 && check_liberties(x, y + 1, originx, originy, piece)) || + (direcy <= 0 && check_liberties(x, y - 1, originx, originy, piece))) { + liberties_status[x][y] = 1; + } else { + liberties_status[x][y] = 0; + } + return liberties_status[x][y]; } void jump_off(int x0, int z0, int color) { - // For now, let's just assume they're all jumping to point (-4,0,-4) - - int x1 = -4; float xt = x0*(1 - t) + x1*t; - int y0 = 9; float yt = -y0 * std::pow(t, 2.0F) + y0 * t + y0; - int z1 = -4; float zt = z0*(1 - t) + z1*t; - - glPushMatrix(); - ApplyTransformationGeneral((xt - 9), (yt - 9), -(zt - 9)); - DrawSphere(color); - - // Draw Thigh - glPushMatrix(); - if (t < 0.1) { glRotatef(-80 + 80 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); } - else { glRotatef(-80, 1.0, 0.0, 1.0); } - glScalef(2.0 / 5.0, 1.0, 2.0 / 5.0); - glTranslatef(0.0, -1.0, 0.0); - DrawUnitCube(3); - glScalef(5.0 / 2.0, 1.0, 5.0 / 2.0); - - // Draw Shin - glPushMatrix(); - - glTranslatef(0, -0.8, 0); - if (t < 0.1) { glRotatef(90 - 90 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); } - else { glRotatef(90, 1.0, 0.0, 1.0); } - glScalef(1.0 / 5.0, 1.0, 1.0 / 5.0); - glTranslatef(0, -1.0, 0); - DrawUnitCube(4); - glScalef(5.0, 1.0, 5.0); - - // Draw Ankle - glPushMatrix(); - glTranslatef(0, -1.0, 0); - if (t < 0.1) { glRotatef(-100 + 100 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); } - else { glRotatef(-100, 1.0, 0.0, 1.0); } - glScalef(1.0 / 2.0, 2.0 / 3.0, 1.0 / 2.0); - glTranslatef(0, -1.0, 0); - DrawSphere(0); - glPopMatrix(); - glPopMatrix(); - glPopMatrix(); - glPopMatrix(); + // For now, let's just assume they're all jumping to point (-4,0,-4) + + int x1 = -4; + float xt = x0 * (1 - t) + x1 * t; + int y0 = 9; + float yt = -y0 * std::pow(t, 2.0F) + y0 * t + y0; + int z1 = -4; + float zt = z0 * (1 - t) + z1 * t; + + glPushMatrix(); + ApplyTransformationGeneral((xt - 9), (yt - 9), -(zt - 9)); + DrawSphere(color); + + // Draw Thigh + glPushMatrix(); + if (t < 0.1) { + glRotatef(-80 + 80 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); + } else { + glRotatef(-80, 1.0, 0.0, 1.0); + } + glScalef(2.0 / 5.0, 1.0, 2.0 / 5.0); + glTranslatef(0.0, -1.0, 0.0); + DrawUnitCube(3); + glScalef(5.0 / 2.0, 1.0, 5.0 / 2.0); + + // Draw Shin + glPushMatrix(); + + glTranslatef(0, -0.8, 0); + if (t < 0.1) { + glRotatef(90 - 90 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); + } else { + glRotatef(90, 1.0, 0.0, 1.0); + } + glScalef(1.0 / 5.0, 1.0, 1.0 / 5.0); + glTranslatef(0, -1.0, 0); + DrawUnitCube(4); + glScalef(5.0, 1.0, 5.0); + + // Draw Ankle + glPushMatrix(); + glTranslatef(0, -1.0, 0); + if (t < 0.1) { + glRotatef(-100 + 100 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); + } else { + glRotatef(-100, 1.0, 0.0, 1.0); + } + glScalef(1.0 / 2.0, 2.0 / 3.0, 1.0 / 2.0); + glTranslatef(0, -1.0, 0); + DrawSphere(0); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); + glPopMatrix(); } void remove_block(int x, int y, int piece) { - if (board_status[x][y] == piece) { - board_status[x][y] = 0; - std::cout << "Jump from "; std::cout << x; std::cout << y; std::cout << '\n'; - - // rm_queue.push(x); - // rm_queue.push(y); - // rm_queue.push(piece); - - std::vector rm_piece; - rm_piece.push_back(x); - rm_piece.push_back(y); - rm_piece.push_back(piece); - L.push_back(rm_piece); - - remove_block(x - 1, y, piece); - remove_block(x + 1, y, piece); - remove_block(x, y - 1, piece); - remove_block(x, y + 1, piece); - } - + if (board_status[x][y] == piece) { + board_status[x][y] = 0; + std::cout << "Jump from "; + std::cout << x; + std::cout << y; + std::cout << '\n'; + + // rm_queue.push(x); + // rm_queue.push(y); + // rm_queue.push(piece); + + std::vector rm_piece; + rm_piece.push_back(x); + rm_piece.push_back(y); + rm_piece.push_back(piece); + L.push_back(rm_piece); + + remove_block(x - 1, y, piece); + remove_block(x + 1, y, piece); + remove_block(x, y - 1, piece); + remove_block(x, y + 1, piece); + } } int make_move(int x, int y, int piece) { - board_status[x][y] = piece; - clear_liberties(); - int other; - if (piece == 1) { - other = 2; - } - else { - other = 1; - } - int has_liberties = 0; - if (x > 0 && board_status[x - 1][y] != piece) { - if (piece == 0) { - has_liberties = 1; - } - else if (!check_liberties(x - 1, y, x - 1, y, other)) { - has_liberties = 1; - remove_block(x - 1, y, other); - } - } - if (x < 18 && board_status[x + 1][y] != piece) { - if (piece == 0) { - has_liberties = 1; - } - else if (!check_liberties(x + 1, y, x + 1, y, other)) { - has_liberties = 1; - remove_block(x + 1, y, other); - } - } - if (y > 0 && board_status[x][y - 1] != piece) { - if (piece == 0) { - has_liberties = 1; - } - else if (!check_liberties(x, y - 1, x, y - 1, other)) { - has_liberties = 1; - remove_block(x, y - 1, other); - } - } - if (y < 18 && board_status[x][y + 1] != piece) { - if (piece == 0) { - has_liberties = 1; - } - else if (!check_liberties(x, y + 1, x, y + 1, other)) { - has_liberties = 1; - remove_block(x, y + 1, other); - - } - } - if (!has_liberties && !check_liberties(x, y, x, y, piece)) { - remove_block(x, y, piece); - return 0; - } - return 1; + board_status[x][y] = piece; + clear_liberties(); + int other; + if (piece == 1) { + other = 2; + } else { + other = 1; + } + int has_liberties = 0; + if (x > 0 && board_status[x - 1][y] != piece) { + if (piece == 0) { + has_liberties = 1; + } else if (!check_liberties(x - 1, y, x - 1, y, other)) { + has_liberties = 1; + remove_block(x - 1, y, other); + } + } + if (x < 18 && board_status[x + 1][y] != piece) { + if (piece == 0) { + has_liberties = 1; + } else if (!check_liberties(x + 1, y, x + 1, y, other)) { + has_liberties = 1; + remove_block(x + 1, y, other); + } + } + if (y > 0 && board_status[x][y - 1] != piece) { + if (piece == 0) { + has_liberties = 1; + } else if (!check_liberties(x, y - 1, x, y - 1, other)) { + has_liberties = 1; + remove_block(x, y - 1, other); + } + } + if (y < 18 && board_status[x][y + 1] != piece) { + if (piece == 0) { + has_liberties = 1; + } else if (!check_liberties(x, y + 1, x, y + 1, other)) { + has_liberties = 1; + remove_block(x, y + 1, other); + } + } + if (!has_liberties && !check_liberties(x, y, x, y, piece)) { + remove_block(x, y, piece); + return 0; + } + return 1; } -void init() -{ - // select clearing color - glClearColor(0.0, 0.0, 0.0, 0.0); +void init() { + // select clearing color + glClearColor(0.0, 0.0, 0.0, 0.0); - // initialize projection matrix - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + // initialize projection matrix + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - double fovY = 45, aspect = 1.0, zNear = 0.1, zFar = 100; + double fovY = 45, aspect = 1.0, zNear = 0.1, zFar = 100; - gluPerspective(fovY, // Field of view - aspect, // Aspect ratio (width / height) - zNear, // Near plane - zFar); // Far plane + gluPerspective(fovY, // Field of view + aspect, // Aspect ratio (width / height) + zNear, // Near plane + zFar); // Far plane - // initialize modelview matrix - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + // initialize modelview matrix + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); - glEnable(GL_LIGHTING); // enable lighting - glEnable(GL_CULL_FACE); // enable backface culling - glEnable(GL_DEPTH_TEST); // enable depth testing - //glEnable(GL_TEXTURE_2D); // enable textures + glEnable(GL_LIGHTING); // enable lighting + glEnable(GL_CULL_FACE); // enable backface culling + glEnable(GL_DEPTH_TEST); // enable depth testing + // glEnable(GL_TEXTURE_2D); // enable textures - SetImages(); + SetImages(); - init_board(); // Create the "Board" + init_board(); // Create the "Board" } \ No newline at end of file diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index 95bcd95..410fa68 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -20,4 +20,5 @@ run_with_sudo apt-get install -y \ libdevil-dev \ cmake \ clang-tidy \ + clang-format \ cppcheck diff --git a/scripts/run_lint.sh b/scripts/run_lint.sh index bf9723f..077b5ba 100755 --- a/scripts/run_lint.sh +++ b/scripts/run_lint.sh @@ -13,6 +13,9 @@ cmake -S "${REPO_ROOT}" \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic" +# Style check with clang-format; fails if formatting differs from .clang-format. +clang-format --dry-run --Werror "${REPO_ROOT}/main.cpp" + # Static analysis with clang-tidy; uses the compile database for accurate diagnostics. clang-tidy "${REPO_ROOT}/main.cpp" -p "${BUILD_DIR}" From f74edddc42a1a4fb868f1a86dee2829c5311d2c1 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Sun, 2 Nov 2025 23:48:20 -0500 Subject: [PATCH 8/8] chore: addresses more linter warns --- README.md | 4 ++-- main.cpp | 65 ++++++++++++++++++++++++------------------------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 7eb76e4..ebb840d 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ Below are the keyboard explanations: 7 : Toggle between smooth and flat shading 8 : Toggle texture -o,O : Toggle teapot rotation along the y-axis -p,P : Toggle teapot rotation along the x-axis +o,O : Toggle board rotation along the y-axis +p,P : Toggle board rotation along the x-axis r,R : Activate "reset board option" y,Y : Confirm "reset board option" n,N : Cancel "reset board option" diff --git a/main.cpp b/main.cpp index c229421..d3886d9 100644 --- a/main.cpp +++ b/main.cpp @@ -74,19 +74,18 @@ struct Camera { int wireframe = 0; int lighting = 1; int material = 1; -int pauseTeapot_y = 1; -int pauseTeapot_x = 1; +int pauseBoardRotation_y = 1; +int pauseBoardRotation_x = 1; int pauseLighting = 0; int depthTest = 1; int cullFace = 1; int smooth = 1; int enabletexture = 0; -constexpr int INITIAL_TEAPOT_ANGLE_X = 45; -constexpr int INITIAL_TEAPOT_ANGLE_Y = 0; -float angle_x = INITIAL_TEAPOT_ANGLE_X; -float angle_y = INITIAL_TEAPOT_ANGLE_Y; -float angle2 = 0; // Useless +constexpr int INITIAL_BOARD_ANGLE_X = 45; +constexpr int INITIAL_BOARD_ANGLE_Y = 0; +float angle_x = INITIAL_BOARD_ANGLE_X; +float angle_y = INITIAL_BOARD_ANGLE_Y; float translatelight = 0; Camera camera{INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z}; @@ -96,7 +95,8 @@ int placex = 0; int placey = 0; int col = 1; float t = 0; -constexpr float TIME_INCREMENT = 0.002; // Depicts how fast time increments. +constexpr float TIME_INCREMENT = 0.002; // Depicts how fast time increments. +constexpr int DEFAULT_SLEEP_TIME = 3000; // Default sleep time in microseconds. // Behind the Scenes std::array, BOARD_SIZE> board_status{}; @@ -181,8 +181,8 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) 7 : Toggle between smooth and flat shading 8 : Toggle texture - o,O : Toggle teapot rotation along the y-axis - p,P : Toggle teapot rotation along the x-axis + o,O : Toggle board rotation along the y-axis + p,P : Toggle board rotation along the x-axis r,R : Activate "reset board option" y,Y : Confirm "reset board option" n,N : Cancel "reset board option" @@ -264,14 +264,14 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) case 'o': case 'O': std::cout << "PRESSED O\n"; - pauseTeapot_y = !pauseTeapot_y; + pauseBoardRotation_y = !pauseBoardRotation_y; break; case 'p': case 'P': std::cout << "PRESSED P\n"; - pauseTeapot_x = !pauseTeapot_x; + pauseBoardRotation_x = !pauseBoardRotation_x; break; @@ -383,34 +383,28 @@ void mouse(int button, int state, int x, int y) { } void idle() { - if (!pauseTeapot_y) { - angle_y = angle_y + 0.5; - - if (angle_y > 360) { - angle_y = angle_y - 360; + const float BOARD_ROTATION_STEP = 0.5f; + const float ANGLE_LIMIT = 360.0f; + if (!pauseBoardRotation_y) { + angle_y += BOARD_ROTATION_STEP; + if (angle_y > ANGLE_LIMIT) { + angle_y -= ANGLE_LIMIT; } } - if (!pauseTeapot_x) { - angle_x = angle_x + 0.5; - - if (angle_x > 360) { - angle_x = angle_x - 360; + if (!pauseBoardRotation_x) { + angle_x += BOARD_ROTATION_STEP; + if (angle_x > ANGLE_LIMIT) { + angle_x -= ANGLE_LIMIT; } } - angle2 = angle2 + 0.5; - - if (angle2 > 360) { - angle2 = angle2 - 360; - } - /* if (!pauseLighting) { - translatelight = translatelight + 0.5; + translatelight += BOARD_ROTATION_STEP; if (translatelight > 360) { - translatelight = translatelight - 360; + translatelight -= 360; } } */ @@ -441,12 +435,12 @@ void lightingFunc() { } void materialFunc() { - // Add a diffuse component to our teapot. The diffuse reflection constant + // Add a diffuse component to our board. The diffuse reflection constant // is white (white light source produces white reflection). GLfloat materialdiffuse[4] = {0.5, 0.5, 1.0, 1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialdiffuse); - // Add a specular component to our teapot. The specular reflection constant + // Add a specular component to our board. The specular reflection constant // is white (white light source produces white reflection). GLfloat materialspecular[4] = {1.0, 1.0, 1.0, 1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialspecular); @@ -594,10 +588,7 @@ void DrawUnitCube(int color) { glEnd(); - // Windows - // Sleep(3000); - // Linux - usleep(3000); + usleep(DEFAULT_SLEEP_TIME); } void display() { @@ -640,7 +631,7 @@ void display() { glScalef(1.0, 0.05, 1.0); // Flatten the Cube. // It should look like a board now. - // Specify material for the teapot we'll be drawing. + // Specify material for the board we'll be drawing. if (material) { materialFunc(); }