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
15 changes: 4 additions & 11 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/cpp/.devcontainer/base.Dockerfile

# [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/22.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
ARG VARIANT="bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
FROM mcr.microsoft.com/devcontainers/cpp:ubuntu-22.04

# [Optional] Install CMake version different from what base image has already installed.
# CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/
Expand All @@ -15,9 +11,6 @@ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"

# [Optional] Uncomment this section to install additional packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends clang-14 g++-12
RUN apt-get update && apt-get -y install --no-install-recommends \
clang-12 g++-12 \
libx11-dev libxft-dev libxext-dev
32 changes: 12 additions & 20 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/cpp
{
"name": "C++",
"name": "Container for go-cpp project",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
// Use Debian 11, Ubuntu 18.04 or Ubuntu 22.04 on local arm64/Apple Silicon
"args": { "VARIANT": "ubuntu-22.04" }
"dockerfile": "Dockerfile"
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],

"features": {
"github-cli": "latest",
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
Expand All @@ -18,20 +20,10 @@
"extensions": [
"ms-vscode.cpptools-extension-pack",
"eamodio.gitlens",
"ms-azuretools.vscode-docker"
"ms-azuretools.vscode-docker",
"Github.copilot",
"Github.copilot-chat"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"github-cli": "latest"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ jobs:
uses: dorny/[email protected]
if: success() || failure()
with:
name: go-tests - ${{ matrix.os }} - ${{ matrix.cmake_preset }}
name: goimpl-tests - ${{ matrix.os }} - ${{ matrix.cmake_preset }}
path: out/${{ matrix.cmake_preset }}/junit-output/*
reporter: java-junit
40 changes: 25 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,46 @@ cmake_minimum_required(VERSION 3.20)

project(go-cpp CXX)
set(CMAKE_CXX_STANDARD 20)
include_directories(${PROJECT_SOURCE_DIR}/source)

enable_testing()

################################################################################
# Library
################################################################################

file(GLOB SOURCE_FILES ${PROJECT_SOURCE_DIR}/source/*.cpp)
list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/source/main.cpp)
add_library(goimpl ${SOURCE_FILES})
set(GOIMPL_ROOT ${PROJECT_SOURCE_DIR}/goimpl)
file(GLOB GOIMPL_SOURCE_FILES ${GOIMPL_ROOT}/source/*.cpp)
include_directories(${GOIMPL_ROOT}/include)
add_library(goimpl ${GOIMPL_SOURCE_FILES})

################################################################################
# Main executable
# Library test executable
################################################################################

add_executable(go ${PROJECT_SOURCE_DIR}/source/main.cpp)
target_link_libraries(go goimpl)
find_package(Catch2 3 CONFIG REQUIRED)

file(GLOB TEST_GOIMPL_SOURCE_FILES ${GOIMPL_ROOT}/tests/*.cpp)
add_executable(goimpl-tests ${TEST_GOIMPL_SOURCE_FILES})
target_link_libraries(goimpl-tests PUBLIC goimpl PRIVATE Catch2::Catch2WithMain)

include(CTest)
include(Catch)
catch_discover_tests(goimpl-tests REPORTER junit OUTPUT_DIR junit-output)

################################################################################
# Test executable
# Commandline executable
################################################################################

find_package(Catch2 3 CONFIG REQUIRED)
set(GO_COMMANDLINE_ROOT ${PROJECT_SOURCE_DIR}/go)
add_executable(go ${GO_COMMANDLINE_ROOT}/source/main.cpp)
target_link_libraries(go goimpl)

################################################################################
# GUI executable
################################################################################

file(GLOB TEST_SOURCE_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp)
add_executable(go-tests ${TEST_SOURCE_FILES})
target_link_libraries(go-tests PUBLIC goimpl PRIVATE Catch2::Catch2WithMain)
find_package (imgui CONFIG REQUIRED)

include(CTest)
include(Catch)
catch_discover_tests(go-tests REPORTER junit OUTPUT_DIR junit-output)
set(GO_GUI_ROOT ${PROJECT_SOURCE_DIR}/go-gui)
add_executable(go-gui ${GO_GUI_ROOT}/source/main.cpp)
target_link_libraries(go-gui goimpl imgui::imgui)
76 changes: 76 additions & 0 deletions go-gui/source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "SDL2/SDL.h"


namespace /* private */ {

struct MyInit
{
MyInit (const MyInit &) = delete;
MyInit & operator= (const MyInit &) = delete;
MyInit (MyInit &&) = delete;
MyInit & operator= (MyInit &&) = delete;

SDL_Window* window = nullptr;
bool init_error = false;

MyInit ()
{
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
{
init_error = true;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init: %s", SDL_GetError());
return;
}

SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
window = SDL_CreateWindow("Dear ImGui SDL2 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);

if (window == nullptr)
{
init_error = true;
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error: SDL_CreateWindow(): %s\n", SDL_GetError());
return;
}
}

~MyInit ()
{
if (window)
{
window = nullptr;
}
}
};

}

int main(int argc, char* argv[]) {
MyInit init;
if (init.init_error) { return -1;}

bool keepRunning = true;
while (keepRunning)
{
SDL_Event event;
while (SDL_PollEvent(&event) > 0)
{
switch (event.type)
{
case SDL_QUIT:
keepRunning = false;
break;

case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(init.window))
{
keepRunning = false;
}
break;

default:
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Unhandled Event: %d", event.type);
}
}
}
}
8 changes: 4 additions & 4 deletions source/main.cpp → go/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <memory>

#include "ConsoleUI.hpp"
#include "GameController.hpp"
#include "Logger.hpp"
#include "Player.hpp"
#include "goimpl/ConsoleUI.hpp"
#include "goimpl/GameController.hpp"
#include "goimpl/Logger.hpp"
#include "goimpl/Player.hpp"

using namespace Go;

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions source/Board.hpp → goimpl/include/goimpl/Board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <optional>
#include <utility>
#include <vector>
#include "Point.hpp"
#include "Chain.fwd.hpp"
#include "Stone.fwd.hpp"
#include "goimpl/Point.hpp"
#include "goimpl/Chain.fwd.hpp"
#include "goimpl/Stone.fwd.hpp"


namespace Go {
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions source/Chain.hpp → goimpl/include/goimpl/Chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <functional>
#include <optional>
#include <unordered_map>
#include "std.fwd.hpp"
#include "Board.fwd.hpp"
#include "Point.fwd.hpp"
#include "Stone.fwd.hpp"
#include "goimpl/std.fwd.hpp"
#include "goimpl/Board.fwd.hpp"
#include "goimpl/Point.fwd.hpp"
#include "goimpl/Stone.fwd.hpp"


namespace Go {
Expand Down
6 changes: 3 additions & 3 deletions source/ConsoleUI.hpp → goimpl/include/goimpl/ConsoleUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <string>

#include "Player.fwd.hpp"
#include "Point.fwd.hpp"
#include "Stone.fwd.hpp"
#include "goimpl/Player.fwd.hpp"
#include "goimpl/Point.fwd.hpp"
#include "goimpl/Stone.fwd.hpp"

namespace Go
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef INCL_GAMECONTROLLER_HPP__
#define INCL_GAMECONTROLLER_HPP__

#include "Board.hpp"
#include "goimpl/Board.hpp"

#include "Player.fwd.hpp"
#include "goimpl/Player.fwd.hpp"

namespace Go {

Expand Down
4 changes: 2 additions & 2 deletions source/IPlayer.hpp → goimpl/include/goimpl/IPlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <utility>
#include <string>
#include "Point.fwd.hpp"
#include "Stone.fwd.hpp"
#include "goimpl/Point.fwd.hpp"
#include "goimpl/Stone.fwd.hpp"

namespace Go {

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions source/Player.hpp → goimpl/include/goimpl/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <string>
#include <optional>
#include <utility>
#include "IPlayer.hpp"
#include "Board.fwd.hpp"
#include "Point.fwd.hpp"
#include "Stone.fwd.hpp"
#include "goimpl/IPlayer.hpp"
#include "goimpl/Board.fwd.hpp"
#include "goimpl/Point.fwd.hpp"
#include "goimpl/Stone.fwd.hpp"

namespace Go {

Expand Down
10 changes: 5 additions & 5 deletions source/Player.tpp → goimpl/include/goimpl/Player.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <iostream>
#include <memory>
#include <utility>
#include "Board.hpp"
#include "Chain.hpp"
#include "Logger.hpp"
#include "Player.hpp"
#include "Stone.hpp"
#include "goimpl/Board.hpp"
#include "goimpl/Chain.hpp"
#include "goimpl/Logger.hpp"
#include "goimpl/Player.hpp"
#include "goimpl/Stone.hpp"

using namespace std;

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions source/Point.hpp → goimpl/include/goimpl/Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <optional>
#include <unordered_set>

#include "Point.fwd.hpp"
#include "Stone.hpp"
#include "goimpl/Point.fwd.hpp"
#include "goimpl/Stone.hpp"

std::ostream & operator<< (std::ostream & out, const Go::PointCoords & coords);
std::ostream & operator<< (std::ostream & out, const Go::Point & point);
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion source/std.fwd.hpp → goimpl/include/goimpl/std.fwd.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef INCL_STD_FWD_HPP__
#define INCL_STD_FWD_HPP__

#include "Stone.fwd.hpp"
#include "goimpl/Stone.fwd.hpp"

namespace std {

Expand Down
8 changes: 4 additions & 4 deletions source/Board.cpp → goimpl/source/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <memory>
#include <utility>

#include "Board.hpp"
#include "Chain.hpp"
#include "Logger.hpp"
#include "Stone.hpp"
#include "goimpl/Board.hpp"
#include "goimpl/Chain.hpp"
#include "goimpl/Logger.hpp"
#include "goimpl/Stone.hpp"

using namespace std;

Expand Down
10 changes: 5 additions & 5 deletions source/Chain.cpp → goimpl/source/Chain.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Chain.hpp"
#include "goimpl/Chain.hpp"

#include <cassert>
#include <iostream>
#include <iterator>
#include <unordered_set>
#include "Board.hpp"
#include "Logger.hpp"
#include "Point.hpp"
#include "Stone.hpp"
#include "goimpl/Board.hpp"
#include "goimpl/Logger.hpp"
#include "goimpl/Point.hpp"
#include "goimpl/Stone.hpp"

namespace {

Expand Down
Loading