Skip to content

Commit

Permalink
Merge pull request #6 from r3w0p/1.1.0
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
r3w0p authored May 29, 2024
2 parents b6c1b4e + 47ab34c commit 19afa00
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 61 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Linux

on:
release:
types: [ created ]

env:
BUILD_TYPE: Release

jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- name: Linux GCC
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install CMake and Ninja
uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.27.0" # use most recent 3.27.x version
ninjaVersion: "^1.0" # use most recent 1.x version

- name: CMake Setup
run: cmake -S . -B ${{github.workspace}}/build -G Ninja -D CMAKE_C_COMPILER=${{matrix.compiler_cc}} CMAKE_CXX_COMPILER=${{matrix.compiler_cpp}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: CMake Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target caravan

- name: Rename Executable
working-directory: ./build
run: mv caravan.exe caravan_linux_x64

- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/caravan_linux_x64
repo-token: ${{ secrets.GITHUB_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Testing

on:
push:
branches: [ main ]

env:
BUILD_TYPE: Debug

jobs:
testing:
name: Testing
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- name: Linux GCC
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install CMake and Ninja
uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.27.0" # use most recent 3.27.x version
ninjaVersion: "^1.0" # use most recent 1.x version

- name: CMake Setup
run: cmake -S . -B ${{github.workspace}}/build -G Ninja -D CMAKE_C_COMPILER=${{matrix.compiler_cc}} CMAKE_CXX_COMPILER=${{matrix.compiler_cpp}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: CMake Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target tests

- name: Run Tests
working-directory: ./build
run: ctest --output-on-failure
39 changes: 13 additions & 26 deletions .github/workflows/build.yml → .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build
name: Windows

on:
push:
branches: [ main ]
release:
types: [ created ]

env:
BUILD_TYPE: Release
Expand All @@ -14,29 +14,6 @@ jobs:
strategy:
matrix:
include:
- name: Linux Clang
os: ubuntu-latest
compiler_cc: clang
compiler_cpp: clang++

- name: Linux GCC
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++

# Commented out due to seemingly unresolvable issue possibly caused by FTXUI:
# "Target "component" links to Threads::Threads but the target was not found."
#
#- name: MacOS Clang
# os: macos-latest
# compiler_c: clang
# compiler_cpp: clang++

- name: Windows Clang
os: windows-latest
compiler_cc: clang
compiler_cpp: clang++

- name: Windows GCC
os: windows-latest
compiler_cc: gcc
Expand All @@ -57,3 +34,13 @@ jobs:

- name: CMake Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target caravan

- name: Rename Executable
working-directory: ./build
run: mv caravan.exe caravan_windows_x64.exe

- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/caravan_windows_x64.exe
repo-token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cmake_minimum_required(VERSION 3.27)

project(caravan LANGUAGES C CXX)
project(Caravan LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(PROJECT_VERSION 1.0.1)
set(PROJECT_COPYRIGHT "Copyright (c) 2022-2024 r3w0p")
set(PROJECT_VERSION 1.1.0)
set(PROJECT_DESCRIPTION "A command-line version of the Caravan card game from Fallout: New Vegas.")
set(PROJECT_COPYRIGHT "Copyright (c) 2022-2024 r3w0p")
set(PROJECT_URL "https://github.com/r3w0p/caravan")

IF (WIN32 OR WIN64)
Expand Down Expand Up @@ -80,9 +80,11 @@ add_library(user
"include/caravan/user/user.h"
"include/caravan/user/bot/factory.h"
"include/caravan/user/bot/normal.h"
"include/caravan/user/bot/friendly.h"

"src/caravan/user/bot/factory.cpp"
"src/caravan/user/bot/normal.cpp"
"src/caravan/user/bot/friendly.cpp"
)

add_library(view
Expand All @@ -105,6 +107,14 @@ add_executable(caravan
"src/caravan/main.cpp"
)

target_compile_definitions(caravan
PRIVATE CARAVAN_NAME="${PROJECT_NAME}"
PRIVATE CARAVAN_VERSION="${PROJECT_VERSION}"
PRIVATE CARAVAN_DESCRIPTION="${PROJECT_DESCRIPTION}"
PRIVATE CARAVAN_COPYRIGHT="${PROJECT_COPYRIGHT}"
PRIVATE CARAVAN_URL="${PROJECT_URL}"
)

target_link_libraries(caravan
PRIVATE core
PRIVATE model
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| (_| (_| | | | (_| |\ \/ / (_| | | | |
\___\__,_|_| \__,_| \__/ \__,_|_| |_|

| v1.0.1 | GPL-3.0 | (c) 2022-2024 r3w0p |
| v1.1.0 | GPL-3.0 | (c) 2022-2024 r3w0p |

A command-line version of the Caravan card game from Fallout: New Vegas.

Expand Down
17 changes: 17 additions & 0 deletions include/caravan/user/bot/friendly.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2022-2024 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

#ifndef CARAVAN_USER_BOT_FRIENDLY_H
#define CARAVAN_USER_BOT_FRIENDLY_H

#include "caravan/user/bot/normal.h"

class UserBotFriendly : public UserBotNormal {
public:
explicit UserBotFriendly(PlayerName pn) : UserBotNormal(pn){};

std::string request_move(Game *game) override;
};

#endif //CARAVAN_USER_BOT_FRIENDLY_H
2 changes: 2 additions & 0 deletions include/caravan/user/bot/normal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "caravan/user/user.h"

class UserBotNormal : public UserBot {
protected:
std::string generate_move(Game *game, bool allow_numeral, bool allow_face, bool allow_clear);
public:
explicit UserBotNormal(PlayerName pn) : UserBot(pn){};

Expand Down
28 changes: 20 additions & 8 deletions src/caravan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
// modified under the terms of the GPL-3.0 License.

#include <iostream>
#include <cxxopts.hpp>
#include "cxxopts.hpp"
#include "caravan/view/view_tui.h"
#include "caravan/user/bot/factory.h"

const std::string OPTS_HELP = "h,help";
const std::string OPTS_VERSION = "v,version";

const std::string KEY_HELP = "help";
const std::string KEY_VERSION = "version";

const uint8_t FIRST_ABC = 1;
const uint8_t FIRST_DEF = 2;
Expand All @@ -19,16 +24,14 @@ int main(int argc, char *argv[]) {
ViewTUI *view;

try {
cxxopts::Options options(
"caravan",
"Caravan: A command-line version of "
"the Caravan card game from Fallout: New Vegas.");
cxxopts::Options options(CARAVAN_NAME);

options.add_options()
("h,help", "Print help instructions.")
(OPTS_HELP, "Print help instructions.")
(OPTS_VERSION, "Print help instructions.")
("pvp", "A Player vs Player game.")
("bvb", "A Bot vs Bot game.")
("b,bot", "Which bot to play with.", cxxopts::value<std::string>()->default_value("normal"))
("b,bot", "Which bot to play with (normal, friendly).", cxxopts::value<std::string>()->default_value("normal"))
("d,delay", "Delay before bot makes its move (in seconds).", cxxopts::value<float>()->default_value("1.0"))
("f,first", "Which player goes first (1 or 2).", cxxopts::value<uint8_t>()->default_value("1"))
("c,cards", "Number of cards for each caravan deck (30-162, inclusive).", cxxopts::value<uint8_t>()->default_value("54"))
Expand All @@ -42,11 +45,20 @@ int main(int argc, char *argv[]) {
auto result = options.parse(argc, argv);

// Print help instructions.
if (result.count("help")) {
if (result.count(KEY_HELP)) {
printf("%s v%s\n\n", CARAVAN_NAME, CARAVAN_VERSION);
printf("%s\n", CARAVAN_DESCRIPTION);
printf("%s\n", CARAVAN_COPYRIGHT);
printf("%s\n", CARAVAN_URL);
printf("%s", options.help().c_str());
exit(EXIT_SUCCESS);
}

if (result.count(KEY_VERSION)) {
printf("%s\n", CARAVAN_VERSION);
exit(EXIT_SUCCESS);
}

bool pvp = result["pvp"].as<bool>();
bool bots = result["bvb"].as<bool>();
std::string bot = result["bot"].as<std::string>();
Expand Down
3 changes: 3 additions & 0 deletions src/caravan/user/bot/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include "caravan/user/user.h"
#include "caravan/user/bot/factory.h"
#include "caravan/user/bot/normal.h"
#include "caravan/user/bot/friendly.h"

const std::string NAME_NORMAL = "normal";
const std::string NAME_FRIENDLY = "friendly";

UserBot* BotFactory::get(std::string name, PlayerName player_name) {
// Set name to lowercase
Expand All @@ -19,6 +21,7 @@ UserBot* BotFactory::get(std::string name, PlayerName player_name) {

// Return bot that matches name, or fail
if(name == NAME_NORMAL) { return new UserBotNormal(player_name); }
if(name == NAME_FRIENDLY) { return new UserBotFriendly(player_name); }
else {
throw CaravanFatalException("Unknown bot name '" + name + "'.");
}
Expand Down
22 changes: 22 additions & 0 deletions src/caravan/user/bot/friendly.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2022-2024 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

#include <random>
#include "caravan/user/bot/friendly.h"

/*
* PUBLIC
*/

std::string UserBotFriendly::request_move(Game *game) {
if (closed) { throw CaravanFatalException("Bot is closed."); }

std::string move = generate_move(game, true, false, true);

// Return move if able to generate one
if (!move.empty()) { return move; }

// If no useful move could be made, discard first card in hand
return "D1";
}
Loading

0 comments on commit 19afa00

Please sign in to comment.