Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ on:
push:
paths:
- "**.cpp"
- "**.hpp"
- "**.cmake"
- "**/CMakeLists.txt"
- ".github/workflows/ci.yml"
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The push path filter does not include CMakePresets.json, so changes to presets/workflows won't trigger CI on push. Add CMakePresets.json (and any other build config files you rely on) to the on.push.paths list if you want CI to validate those changes.

Suggested change
- ".github/workflows/ci.yml"
- ".github/workflows/ci.yml"
- "CMakePresets.json"

Copilot uses AI. Check for mistakes.
pull_request:
paths:
- "**.cpp"
- "**.cmake"
- "**/CMakeLists.txt"
- ".github/workflows/ci.yml"


jobs:

linux:
core:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- &checkout
uses: actions/checkout@v6

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI uses cmake --workflow ..., which requires a relatively recent CMake with workflow preset support. Ensure the GitHub runners' CMake meets that requirement (or add a setup step to install/pin a suitable CMake version), otherwise the workflow may start failing without any code changes.

Suggested change
- uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.27.0'

Copilot uses AI. Check for mistakes.
- run: ctest -S setup.cmake -VV
- run: cmake --workflow debug
- run: cmake --workflow release
27 changes: 14 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
cmake_minimum_required(VERSION 3.7...3.21)
cmake_minimum_required(VERSION 3.15...4.3)
project(2048 LANGUAGES CXX)
enable_testing()

set(SOURCES src/2048.cpp src/gameboard.cpp src/gameboard-graphics.cpp src/game.cpp src/game-graphics.cpp src/game-input.cpp src/game-pregamemenu.cpp src/global.cpp src/loadresource.cpp src/menu.cpp src/menu-graphics.cpp src/saveresource.cpp src/scores.cpp src/scores-graphics.cpp src/statistics.cpp src/statistics-graphics.cpp src/tile.cpp src/tile-graphics.cpp)

if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
add_compile_options(-Wall)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
add_compile_options(-Wall)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^Intel")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options($<$<CONFIG:Debug,RelWithDebInfo>:-Wall>)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options($<$<CONFIG:Debug,RelWithDebInfo>:-Wall>)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
if(WIN32)
add_compile_options(/W3)
add_compile_options($<$<CONFIG:Debug,RelWithDebInfo>:/W3>)
else()
add_compile_options(-w2)
add_compile_options($<$<CONFIG:Debug,RelWithDebInfo>:-w2>)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL NVHPC)
add_compile_options(-a)
elseif(MSVC)
add_compile_options($<$<CONFIG:Debug,RelWithDebInfo>:/W3>)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
add_compile_options($<$<CONFIG:Debug,RelWithDebInfo>:-a>)
endif()

add_executable(2048 ${SOURCES})
Expand All @@ -33,8 +35,7 @@ endif()

# --- install

install(TARGETS 2048
RUNTIME DESTINATION bin)
install(TARGETS 2048)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install(TARGETS 2048) no longer specifies destinations; CMake will install into the default/current directory under the prefix, which changes the previously explicit RUNTIME DESTINATION bin behavior. Specify destinations (e.g., RUNTIME/BUNDLE/LIBRARY/ARCHIVE) to keep installs predictable across platforms.

Suggested change
install(TARGETS 2048)
install(TARGETS 2048
RUNTIME DESTINATION bin)

Copilot uses AI. Check for mistakes.

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
DESTINATION ${CMAKE_INSTALL_PREFIX})
DESTINATION ${CMAKE_INSTALL_PREFIX}/data)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DESTINATION ${CMAKE_INSTALL_PREFIX}/data bakes the configured install prefix into the install rules and ignores cmake --install --prefix ... (and may attempt to install into a system location). Use a relative destination like DESTINATION data (or DESTINATION .) so the chosen prefix at install time is respected.

Suggested change
DESTINATION ${CMAKE_INSTALL_PREFIX}/data)
DESTINATION data)

Copilot uses AI. Check for mistakes.
66 changes: 66 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"version": 6,

"configurePresets": [
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_COMPILE_WARNING_AS_ERROR": true,
"CMAKE_LINK_WARNING_AS_ERROR": true
}
},
{
"name": "multi", "inherits": "default",
"generator": "Ninja Multi-Config"
}
],
"buildPresets": [
{ "name": "default", "configurePreset": "default" },
{ "name": "debug", "configurePreset": "multi", "configuration": "Debug" },
{ "name": "release", "configurePreset": "multi", "configuration": "Release" }
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {
"outputOnFailure": true,
"verbosity": "verbose"
},
"execution": {
"noTestsAction": "error",
"scheduleRandom": true,
"stopOnFailure": false,
"timeout": 60
}
},
{ "name": "debug", "inherits": "default", "configurePreset": "multi", "configuration": "Debug" },
{ "name": "release", "inherits": "default", "configurePreset": "multi", "configuration": "Release" }
],
"workflowPresets": [
{
"name": "default",
"steps": [
{ "type": "configure", "name": "default" },
{ "type": "build", "name": "default" },
{ "type": "test", "name": "default" }
]
},
{ "name": "debug",
"steps": [
{ "type": "configure", "name": "multi" },
{ "type": "build", "name": "debug" },
{ "type": "test", "name": "debug" }
]
},
{
"name": "release",
"steps": [
{ "type": "configure", "name": "multi" },
{ "type": "build", "name": "release" },
{ "type": "test", "name": "release" }
]
}
]
}
14 changes: 0 additions & 14 deletions meson.build

This file was deleted.

69 changes: 0 additions & 69 deletions setup.cmake

This file was deleted.

10 changes: 8 additions & 2 deletions src/global.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "global.hpp"
#include "color.hpp"

#include <iostream>
#include <sstream>
#include <cstdlib> // for system
#include <system_error>
#include <cerrno>

#ifdef _WIN32

Expand Down Expand Up @@ -51,10 +55,12 @@ void wait_for_any_letter_input(std::istream &is) {

void clearScreen() {
#ifdef _WIN32
system("cls");
if(system("cls")) {
#else
system("clear");
if(system("clear")) {
#endif
std::cerr << "Failed to clear screen: " << std::error_code(errno, std::generic_category()).message() << "\n";
}
Comment on lines +58 to +63
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

system() failure reporting here is misleading: a non-zero return value usually indicates the command exited with an error status and does not necessarily set errno. Capture the return code from system() and report it (and only consult errno when system() returns -1).

Copilot uses AI. Check for mistakes.
};

std::string secondsFormat(double sec) {
Expand Down
2 changes: 1 addition & 1 deletion src/headers/gameboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <tuple>
#include <vector>

struct point2D_t;
class point2D_t;

namespace Game {

Expand Down
16 changes: 8 additions & 8 deletions src/loadresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace {
/**
* @brief Counts the number of lines in a file until a line containing '[' is found.
*
* This function opens a file specified by the given filename and counts the number
* of lines until it encounters a line that contains the character '['. If the file
* This function opens a file specified by the given filename and counts the number
* of lines until it encounters a line that contains the character '['. If the file
* cannot be opened, it prints an error message and returns -1.
*
* @param filename The name of the file to be read.
* @return The number of lines read before encountering a line with '['. Returns -1 if the file cannot be opened.
*/
int GetLines(std::string filename)
int GetLines(std::string filename)
{
std::ifstream stateFile(filename);
if (!stateFile) {
Expand All @@ -48,10 +48,10 @@ int GetLines(std::string filename)
/**
* @brief Extracts tile data from a given input stream until a line containing '[' is encountered.
*
* This function reads lines from the provided input stream and extracts tile data
* formatted as comma-separated values. The process continues until either the maximum
* width (10 lines) is reached or a line containing the character '[' is found. When
* a line with '[' is encountered, the function stops reading further and processes
* This function reads lines from the provided input stream and extracts tile data
* formatted as comma-separated values. The process continues until either the maximum
* width (10 lines) is reached or a line containing the character '[' is found. When
* a line with '[' is encountered, the function stops reading further and processes
* the line up to, but not including, the '[' character.
*
* @param buf The input stream from which to read the tile data.
Expand Down Expand Up @@ -181,7 +181,7 @@ load_game_stats_from_file(std::string filename) {
* @brief Loads game data from a specified file into a GameBoard object.
*
* This function opens a file specified by the given filename, reads the game board data,
* and initializes a GameBoard object with the read data. It first counts the number of lines
* and initializes a GameBoard object with the read data. It first counts the number of lines
* until a line containing '[' is found to determine the size of the game board. Then, it reads
* the tile data from the file, processes it, and updates the GameBoard object. Finally, it reads
* the score and move count from the last relevant line containing these values.
Expand Down
Loading
Loading