Skip to content

Commit

Permalink
Merge pull request #8 from r3w0p/1.2.0
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
r3w0p authored May 30, 2024
2 parents 7d3b609 + 92da01d commit b2bccec
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 87 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
strategy:
matrix:
include:
- name: Linux GCC
- name: Linux GCC x64
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++
asset: caravan_linux_x64

steps:
- name: Checkout
Expand All @@ -37,10 +38,10 @@ jobs:

- name: Rename Executable
working-directory: ./build
run: mv caravan caravan_linux_x64
run: mv caravan ${{matrix.asset}}

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

on:
release:
types: [ created ]

env:
BUILD_TYPE: Release

jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- name: MacOS Clang x64
os: macos-latest
compiler_cc: clang
compiler_cpp: clang++
asset: caravan_macos_x64

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 ${{matrix.asset}}

- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/${{matrix.asset}}
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
include:
- name: Linux GCC
- name: Linux GCC x64
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
strategy:
matrix:
include:
- name: Windows GCC
- name: Windows GCC x64
os: windows-latest
compiler_cc: gcc
compiler_cpp: g++
asset: caravan_windows_x64.exe

steps:
- name: Checkout
Expand All @@ -37,10 +38,10 @@ jobs:

- name: Rename Executable
working-directory: ./build
run: mv caravan.exe caravan_windows_x64.exe
run: mv caravan.exe ${{matrix.asset}}

- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/caravan_windows_x64.exe
files: ./build/${{matrix.asset}}
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(PROJECT_VERSION 1.1.0)
set(PROJECT_VERSION 1.2.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")
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.1.0 | GPL-3.0 | (c) 2022-2024 r3w0p |
| v1.2.0 | GPL-3.0 | (c) 2022-2024 r3w0p |

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

Expand Down
3 changes: 3 additions & 0 deletions include/caravan/view/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ typedef struct ViewConfig {
// Most recent command
GameCommand command;

// Board highlight
GameCommand highlight;

// Colour support
bool colour{};

Expand Down
68 changes: 42 additions & 26 deletions src/caravan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@

const std::string OPTS_HELP = "h,help";
const std::string OPTS_VERSION = "v,version";
const std::string OPTS_PVP = "pvp";
const std::string OPTS_BVB = "bvb";
const std::string OPTS_BOT = "b,bot";
const std::string OPTS_DELAY = "d,delay";
const std::string OPTS_FIRST = "f,first";
const std::string OPTS_CARDS = "c,cards";
const std::string OPTS_SAMPLES = "s,samples";
const std::string OPTS_IMBALANCED = "i,imbalanced";

const std::string KEY_HELP = "help";
const std::string KEY_VERSION = "version";
const std::string KEY_PVP = "pvp";
const std::string KEY_BVB = "bvb";
const std::string KEY_BOT = "bot";
const std::string KEY_DELAY = "delay";
const std::string KEY_FIRST = "first";
const std::string KEY_CARDS = "cards";
const std::string KEY_SAMPLES = "samples";
const std::string KEY_IMBALANCED = "imbalanced";

const uint8_t FIRST_ABC = 1;
const uint8_t FIRST_DEF = 2;
Expand All @@ -29,14 +45,14 @@ int main(int argc, char *argv[]) {
options.add_options()
(OPTS_HELP, "Print help instructions.")
(OPTS_VERSION, "Print software version.")
("pvp", "A Player vs Player game.")
("bvb", "A Bot vs Bot game.")
("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"))
("s,samples", "Number of traditional decks to sample when building caravan decks (1-3, inclusive).", cxxopts::value<uint8_t>()->default_value("1"))
("i,imbalanced",
(OPTS_PVP, "A Player vs Player game.")
(OPTS_BVB, "A Bot vs Bot game.")
(OPTS_BOT, "Which bot to play with (normal, friendly).", cxxopts::value<std::string>()->default_value("normal"))
(OPTS_DELAY, "Delay before bot makes its move (in seconds).", cxxopts::value<float>()->default_value("1.0"))
(OPTS_FIRST, "Which player goes first (1 or 2).", cxxopts::value<uint8_t>()->default_value("1"))
(OPTS_CARDS, "Number of cards for each caravan deck (30-162, inclusive).", cxxopts::value<uint8_t>()->default_value("54"))
(OPTS_SAMPLES, "Number of traditional decks to sample when building caravan decks (1-3, inclusive).", cxxopts::value<uint8_t>()->default_value("1"))
(OPTS_IMBALANCED,
"An imbalanced caravan deck is built by taking as many "
"cards from one shuffled sample deck before moving to the next. "
"A balanced deck randomly samples cards across all sample decks.")
Expand All @@ -59,45 +75,45 @@ int main(int argc, char *argv[]) {
exit(EXIT_SUCCESS);
}

bool pvp = result["pvp"].as<bool>();
bool bots = result["bvb"].as<bool>();
std::string bot = result["bot"].as<std::string>();
float delay = result["delay"].as<float>();
uint8_t first = result["first"].as<uint8_t>();
uint8_t cards = result["cards"].as<uint8_t>();
uint8_t samples = result["samples"].as<uint8_t>();
bool imbalanced = result["imbalanced"].as<bool>();

if (pvp && bots) {
printf("Game cannot be both Player vs Player and Bot vs Bot.");
bool pvp = result[KEY_PVP].as<bool>();
bool bvb = result[KEY_BVB].as<bool>();
std::string bot = result[KEY_BOT].as<std::string>();
float delay = result[KEY_DELAY].as<float>();
uint8_t first = result[KEY_FIRST].as<uint8_t>();
uint8_t cards = result[KEY_CARDS].as<uint8_t>();
uint8_t samples = result[KEY_SAMPLES].as<uint8_t>();
bool imbalanced = result[KEY_IMBALANCED].as<bool>();

if (pvp && bvb) {
printf("Game cannot be both Player vs Player and Bot vs Bot.\n");
exit(EXIT_FAILURE);
}

if(first < FIRST_ABC || first > FIRST_DEF) {
printf("First player must be either %d or %d.", FIRST_ABC, FIRST_DEF);
printf("First player must be either %d or %d.\n", FIRST_ABC, FIRST_DEF);
exit(EXIT_FAILURE);
}

if (cards < DECK_CARAVAN_MIN || cards > DECK_CARAVAN_MAX) {
printf("Caravan decks must have between %d and %d cards (inclusive).", DECK_CARAVAN_MIN, DECK_CARAVAN_MAX);
printf("Caravan decks must have between %d and %d cards (inclusive).\n", DECK_CARAVAN_MIN, DECK_CARAVAN_MAX);
exit(EXIT_FAILURE);
}

if (samples < SAMPLE_DECKS_MIN || samples > SAMPLE_DECKS_MAX) {
printf("Number of caravan deck samples must be between %d and %d (inclusive).", SAMPLE_DECKS_MIN, SAMPLE_DECKS_MIN);
printf("Number of caravan deck samples must be between %d and %d (inclusive).\n", SAMPLE_DECKS_MIN, SAMPLE_DECKS_MIN);
exit(EXIT_FAILURE);
}

if(delay < 0) {
printf("Bot delay cannot be a negative number.");
printf("Bot delay cannot be a negative number.\n");
exit(EXIT_FAILURE);
}

if(pvp) { // human vs human
user_abc = new UserHuman(PLAYER_ABC);
user_def = new UserHuman(PLAYER_DEF);

} else if (bots) { // bot vs bot
} else if (bvb) { // bot vs bot
user_abc = BotFactory::get(bot, PLAYER_ABC);
user_def = BotFactory::get(bot, PLAYER_DEF);

Expand All @@ -122,11 +138,11 @@ int main(int argc, char *argv[]) {
view = new ViewTUI(&vc, game);

} catch (CaravanException &e) {
printf("%s", e.what().c_str());
printf("%s\n", e.what().c_str());
exit(EXIT_FAILURE);

} catch (std::exception &e) {
printf("%s", e.what());
printf("%s\n", e.what());
exit(EXIT_FAILURE);
}

Expand Down
Loading

0 comments on commit b2bccec

Please sign in to comment.