Skip to content

Commit

Permalink
Merge pull request #1 from r3w0p/develop
Browse files Browse the repository at this point in the history
develop 0.10.0
  • Loading branch information
r3w0p authored Feb 16, 2023
2 parents 0657c93 + 93de76d commit 645e102
Show file tree
Hide file tree
Showing 311 changed files with 116,294 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: r3w0p
Binary file added .github/github_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Windows

on:
push:
branches: [ main ]

env:
BUILD_TYPE: Debug

jobs:
build:
name: Build
runs-on: windows-latest

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

- name: Install CMake and Ninja
uses: lukka/[email protected]
with:
cmakeVersion: 3.23.2
ninjaVersion: 1.11.1

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

- name: CMake Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target caravan
46 changes: 15 additions & 31 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
# Prerequisites
*.d
*
!.gitignore
!CMakeLists.txt
!LICENSE
!README.md

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
!.github/
!.github/**
!include/
!include/**
!lib/
!lib/**
!src/
!src/**
!test/
!test/**
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
enable_testing()

cmake_minimum_required(VERSION 3.23)

set(CMAKE_CXX_STANDARD 20)
add_definitions(-DPDC_WIDE)

project(caravan VERSION 0.9)

set(PROJECT_COPYRIGHT "Copyright (c) 2022-2023 r3w0p")
set(PROJECT_DESCRIPTION "A CLI version of the Caravan card game from Fallout: New Vegas.")
set(PROJECT_URL "https://github.com/r3w0p/caravan")

add_subdirectory(src)
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(test)

set_target_properties(caravan PROPERTIES LINK_SEARCH_START_STATIC ON)
set_target_properties(caravan PROPERTIES LINK_SEARCH_END_STATIC ON)

target_link_options(caravan PRIVATE -static-libgcc -static-libstdc++ -static)
76 changes: 76 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
___ __ _ _ __ __ ___ ____ _ _ __
/ __/ _` | '__/ _` \ \ / / _` | '_ \
| (_| (_| | | | (_| |\ \/ / (_| | | | |
\___\__,_|_| \__,_| \__/ \__,_|_| |_|

| v0.10.0 | GPL-3.0 | (c) 2022-2023 r3w0p |

A CLI version of the Caravan card game from Fallout: New Vegas.


===========
HOW TO PLAY
===========

The game is played in the same way as the original card game, with only a few
changes and restrictions, as follows.

(1) The names of the caravans have been changed to six letters, from A to F,
where caravans A, B, and C are for one player, and D, E, and F are for the
other. Caravan A competes against D, B against E, and C against F.

(2) Deck building has been simplified to create fairer games. A caravan deck
comprises between 30 and 156 cards sampled randomly from between 1 and 3
standard card decks (52 cards + 2 Jokers). The standard decks are shuffled and
may be sampled equally (a "balanced sample") or randomly.

(3) Each caravan has a limit of 10 numeral cards (i.e. ACE to 10). Each numeral
card has a limit of 5 face cards (i.e. JACK, QUEEN, KING, and JOKER) that can be
placed on it.

(4) Bidding has been removed completely.


========
CONTROLS
========

Each card in your hand has a number to the left of it, which indicates the
number you would enter if you wanted to PLAY or DISCARD it. Similarly, each
numeral card in every caravan also has a number to the left of it, which is used
to PLAY a face card onto it and indicates its position in the card stack.

The game is played by entering commands that indicate whether you want to PLAY
a card from your hand, DISCARD a card from your hand, CLEAR all cards from one
of your caravans, or EXIT the game. The commands are not case sensitive.

Pressing the Enter key will submit your command. If there is a problem with your
command, a message will appear below the game table to help you.

---

To PLAY a numeral card, type 'P', then the number for the card in your hand that
you want to play, then the caravan name. For example, to PLAY card 2 from your
hand onto caravan B:

[YOU] > P2B

To PLAY a face card, you must additionally specify the position of the numeral
card in the caravan you are targeting. For example, to PLAY card 4 from your
hand onto the numeral at position 3 in caravan F:

[YOU] > P4F3

To DISCARD a card, type 'D', then the number for the card in your hand that you
want to play. For example, to DISCARD card 3 from your hand:

[YOU] > D3

To CLEAR one of your caravans, type 'C', then the name of the caravan that you
want to clear. For example, to CLEAR caravan A:

[YOU] > CA

To EXIT the game, simply type:

[YOU] > EXIT
1 change: 0 additions & 1 deletion README.md

This file was deleted.

1 change: 1 addition & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_include_directories(caravan PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
18 changes: 18 additions & 0 deletions include/bot_easy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022-2023 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

#ifndef CARAVAN_BOT_EASY_H
#define CARAVAN_BOT_EASY_H


#include "user.h"

class UserBotEasy : public UserBot {
public:
explicit UserBotEasy(PlayerName pn) : UserBot(pn) {};

GameOption generate_option(Engine *e) override;
};

#endif //CARAVAN_BOT_EASY_H
51 changes: 51 additions & 0 deletions include/caravan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2022-2023 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

#ifndef CARAVAN_CARAVAN_H
#define CARAVAN_CARAVAN_H

#include <cstdint>
#include <array>
#include "deck.h"
#include "common.h"


class Caravan {

protected:
CaravanName name;
Track track;
uint8_t i_track;

static uint8_t numeral_rank_to_uint8_t(Rank rank);

void remove_numeral_card(uint8_t index);

public:
explicit Caravan(CaravanName cvname);

void clear();

uint16_t get_bid();

Slot get_slot(uint8_t pos);

Direction get_direction();

CaravanName get_name();

uint8_t get_size();

Suit get_suit();

void put_numeral_card(Card card);

Card put_face_card(Card card, uint8_t pos);

void remove_rank(Rank rank, uint8_t pos_exclude);

void remove_suit(Suit suit, uint8_t pos_exclude);
};

#endif //CARAVAN_CARAVAN_H
125 changes: 125 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright (c) 2022-2023 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

#ifndef CARAVAN_COMMON_H
#define CARAVAN_COMMON_H

#include <cstdint>
#include <array>
#include <vector>
#include <string>

/*
* CONSTANTS
*/

const uint8_t TRACK_NUMERIC_MIN = 1;
const uint8_t TRACK_NUMERIC_MAX = 10;
const uint8_t TRACK_FACE_MAX = 5;
const uint8_t CARAVAN_SOLD_MIN = 21;
const uint8_t CARAVAN_SOLD_MAX = 26;
const uint8_t DECK_STANDARD_MAX = 52;
const uint8_t DECK_CARAVAN_MIN = 30;
const uint8_t DECK_CARAVAN_MAX = 156;
const uint8_t SAMPLE_DECKS_MIN = 1;
const uint8_t SAMPLE_DECKS_MAX = 3;
const uint8_t MOVES_START_ROUND = 3;
const uint8_t HAND_SIZE_MAX_START = 8;
const uint8_t HAND_SIZE_MAX_POST_START = 5;
const uint8_t HAND_POS_MIN = 1;
const uint8_t TABLE_CARAVANS_MAX = 6;
const uint8_t PLAYER_CARAVANS_MAX = 3;
const uint8_t VIEW_Y_MIN = 68;
const uint8_t VIEW_X_MIN = 106;

const uint8_t VIEW_STDSCR_ROW_OPTION = 68;

/*
* ENUMS
*/

enum PlayerName {
NO_PLAYER, PLAYER_BOTTOM, PLAYER_TOP
};
enum Direction {
ANY, ASCENDING, DESCENDING
};
enum CaravanName {
NO_CARAVAN, CARAVAN_A, CARAVAN_B, CARAVAN_C, CARAVAN_D, CARAVAN_E, CARAVAN_F
};
enum OptionType {
NO_OPTION, OPTION_EXIT, OPTION_PLAY, OPTION_DISCARD, OPTION_CLEAR
};
enum Suit {
NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES
};
enum Rank {
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
JOKER
};

/*
* TYPES
*/

typedef struct Card {
Suit suit{};
Rank rank{};
} Card;

typedef std::array<Card, HAND_SIZE_MAX_START> Hand;
typedef std::vector<Card> Deck;
typedef std::array<Card, TRACK_FACE_MAX> Faces;
typedef std::array<CaravanName, 3> PlayerCaravanNames;


typedef struct Slot {
Card card {};
Faces faces {};
uint8_t i_faces = 0;
} Slot;

typedef std::array<Slot, TRACK_NUMERIC_MAX> Track;

typedef struct GameConfig {
uint8_t pa_num_cards;
uint8_t pa_num_sample_decks;
bool pa_balanced_sample;

uint8_t pb_num_cards;
uint8_t pb_num_sample_decks;
bool pb_balanced_sample;

PlayerName pn_first;
} GameConfig;

typedef struct GameOption {
OptionType type {};
uint8_t pos_hand {};
CaravanName caravan_name {};
uint8_t pos_caravan {};
Card card {};
} GameOption;

/*
* FUNCTIONS
*/

bool is_numeral_card(Card c);

bool is_face_card(Card c);

#endif //CARAVAN_COMMON_H
Loading

0 comments on commit 645e102

Please sign in to comment.