Skip to content

Commit

Permalink
what to do with model/game?
Browse files Browse the repository at this point in the history
  • Loading branch information
r3w0p committed May 23, 2024
1 parent 993fbca commit e979d4b
Show file tree
Hide file tree
Showing 18 changed files with 566 additions and 347 deletions.
2 changes: 1 addition & 1 deletion include/caravan/controller/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Controller : public ViewSubscriber, public Publisher<ControllerSubscriber>
explicit Controller() : closed(false) {};

void subscribe(ControllerSubscriber *sub) override;
void close() { closed = true; };
virtual void close() = 0;
};

#endif //CARAVAN_CONTROLLER_H
1 change: 1 addition & 0 deletions include/caravan/controller/controller_tui.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ControllerTUI : public Controller {
explicit ControllerTUI() = default;

void on_view_user_input(std::string input, bool confirmed) override; // from ViewSubscriber
void close() override;
};

#endif //CARAVAN_CONTROLLER_TUI_H
4 changes: 2 additions & 2 deletions include/caravan/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

const uint8_t TRACK_NUMERIC_MIN = 1;
const uint8_t TRACK_NUMERIC_MAX = 10;
const uint8_t TRACK_FACE_MAX = 5;
const uint8_t TRACK_NUMERIC_MAX = 8;
const uint8_t TRACK_FACE_MAX = 3;
const uint8_t CARAVAN_SOLD_MIN = 21;
const uint8_t CARAVAN_SOLD_MAX = 26;
const uint8_t DECK_STANDARD_MAX = 52;
Expand Down
17 changes: 17 additions & 0 deletions include/caravan/core/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include <string>

/*
* BASE
*/

class CaravanException : public std::exception {
private:
std::string message;
Expand All @@ -16,6 +20,10 @@ class CaravanException : public std::exception {
std::string what();
};

/*
* GENERAL
*/

class CaravanFatalException : public CaravanException {
public:
explicit CaravanFatalException(std::string msg) : CaravanException(msg) {}
Expand All @@ -26,4 +34,13 @@ class CaravanGameException : public CaravanException {
explicit CaravanGameException(std::string msg) : CaravanException(msg) {}
};

/*
* CONTROLLER
*/

class CaravanInputException : public CaravanException {
public:
explicit CaravanInputException(std::string msg) : CaravanException(msg) {}
};

#endif //CARAVAN_CORE_EXCEPTIONS_H
14 changes: 12 additions & 2 deletions include/caravan/model/caravan.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ class Caravan {
CaravanName name;
Track track;
uint8_t i_track;
bool closed;

static uint8_t numeral_rank_to_uint8_t(Rank rank);

void remove_numeral_card(uint8_t index);

public:
explicit Caravan(CaravanName cvname);
/**
* A caravan that contains all of the information for a given track of numeral
* cards and any face cards attached to them, including: the total caravan bid,
* its direction, and its suit.
*
* @param cvname The caravan name.
*/
explicit Caravan(CaravanName cvname) :
name(cvname), track({}), i_track(0), closed(false) {};

void clear();

Expand All @@ -46,6 +54,8 @@ class Caravan {
void remove_rank(Rank rank, uint8_t pos_exclude);

void remove_suit(Suit suit, uint8_t pos_exclude);

void close();
};

#endif //CARAVAN_MODEL_CARAVAN_H
32 changes: 2 additions & 30 deletions include/caravan/model/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,19 @@
class Game {
protected:
Table *table_ptr{};
Deck *deck_pa_ptr{};
Deck *deck_pb_ptr{};
Player *pa_ptr{};
Player *pb_ptr{};
bool closed;
Player *p_turn;
bool closed;

int8_t compare_bids(CaravanName cvname1, CaravanName cvname2);

bool has_sold(CaravanName cvname);

void option_clear(Player *pptr, GameOption* go);

void option_discard(Player *pptr, GameOption* go);

void option_play(Player *pptr, GameOption* go);

public:
explicit Game(GameConfig gc) {
if (gc.pn_first == NO_PLAYER)
throw CaravanFatalException(
"Invalid player name for first player in "
"game configuration.");

deck_pa_ptr = DeckBuilder::build_caravan_deck(
gc.pa_num_cards,
gc.pa_num_sample_decks,
gc.pa_balanced_sample);

deck_pb_ptr = DeckBuilder::build_caravan_deck(
gc.pb_num_cards,
gc.pb_num_sample_decks,
gc.pb_balanced_sample);

table_ptr = new Table();
pa_ptr = new Player(PLAYER_BOTTOM, deck_pa_ptr);
pb_ptr = new Player(PLAYER_TOP, deck_pb_ptr);

closed = false;
p_turn = gc.pn_first == pa_ptr->get_name() ? pa_ptr : pb_ptr;
}
explicit Game(GameConfig gc);

void close();

Expand Down
17 changes: 4 additions & 13 deletions include/caravan/model/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ class Player {
Hand hand;
uint8_t i_hand;
uint16_t moves;
bool closed;

public:
explicit Player(PlayerName pn, Deck *d) {
name = pn;
deck = d;
hand = {};
i_hand = 0;
moves = 0;

while (i_hand < HAND_SIZE_MAX_START) {
hand[i_hand] = deck->back();
deck->pop_back();
i_hand += 1;
}
}
explicit Player(PlayerName pn, Deck *d);

void close();

Card get_from_hand_at(uint8_t pos);

Expand Down
3 changes: 3 additions & 0 deletions include/caravan/model/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ class Table {
Caravan* f = new Caravan(CARAVAN_F);

std::array<Caravan*, TABLE_CARAVANS_MAX> caravans = { a, b, c, d, e, f };
bool closed;

uint8_t caravan_name_to_uint8_t_index(CaravanName cvname);

public:
explicit Table();

void close();

void clear_caravan(CaravanName cvname);

uint16_t get_caravan_bid(CaravanName cvname);
Expand Down
Loading

0 comments on commit e979d4b

Please sign in to comment.