Skip to content

Commit

Permalink
going to just make normal better instead..............
Browse files Browse the repository at this point in the history
  • Loading branch information
r3w0p committed Jan 10, 2025
1 parent 111aba3 commit e1b07a8
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 211 deletions.
27 changes: 1 addition & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set(PROJECT_VERSION 2.0.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_COPYRIGHT "Copyright (c) 2022-2025 r3w0p")
set(PROJECT_URL "https://github.com/r3w0p/caravan")

IF (WIN32 OR WIN64)
Expand Down Expand Up @@ -80,12 +80,10 @@ target_link_libraries(model core)

add_library(user
"include/caravan/user/user.h"
"include/caravan/user/bot/ai.h"
"include/caravan/user/bot/factory.h"
"include/caravan/user/bot/friendly.h"
"include/caravan/user/bot/normal.h"

"src/caravan/user/bot/ai.cpp"
"src/caravan/user/bot/factory.cpp"
"src/caravan/user/bot/friendly.cpp"
"src/caravan/user/bot/normal.cpp"
Expand Down Expand Up @@ -129,29 +127,6 @@ target_link_libraries(caravan
# ---


# --- train.exe
add_executable(train
"src/caravan/train.cpp"
)

target_compile_definitions(train
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(train
PRIVATE core
PRIVATE model
PRIVATE user
PRIVATE view
PRIVATE cxxopts
)
# ---


# --- test.exe
enable_testing()

Expand Down
2 changes: 1 addition & 1 deletion include/caravan/model/player.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand Down
17 changes: 0 additions & 17 deletions include/caravan/user/bot/ai.h

This file was deleted.

55 changes: 28 additions & 27 deletions src/caravan/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

#include <iostream>
#include <memory>
#include "cxxopts.hpp"
#include "caravan/view/view_tui.h"
#include "caravan/user/bot/factory.h"
Expand Down Expand Up @@ -35,10 +36,10 @@ const uint8_t FIRST_DEF = 2;
// TODO docstrings in .h for all files

int main(int argc, char *argv[]) {
User *user_abc;
User *user_def;
Game *game;
ViewTUI *view;
std::unique_ptr<User> user_abc = nullptr;
std::unique_ptr<User> user_def = nullptr;
std::unique_ptr<Game> game;
std::unique_ptr<ViewTUI> view;

try {
cxxopts::Options options(CARAVAN_NAME);
Expand All @@ -61,7 +62,7 @@ int main(int argc, char *argv[]) {

auto result = options.parse(argc, argv);

// Print help instructions.
// Print help instructions
if (result.count(KEY_HELP)) {
printf("%s v%s\n\n", CARAVAN_NAME, CARAVAN_VERSION);
printf("%s\n", CARAVAN_DESCRIPTION);
Expand Down Expand Up @@ -111,32 +112,40 @@ int main(int argc, char *argv[]) {
}

if(pvp) { // human vs human
user_abc = new UserHuman(PLAYER_ABC);
user_def = new UserHuman(PLAYER_DEF);
user_abc = std::make_unique<UserHuman>(PLAYER_ABC);
user_def = std::make_unique<UserHuman>(PLAYER_DEF);

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

} else { // humans vs bot
user_abc = new UserHuman(PLAYER_ABC);
user_def = BotFactory::get(bot, PLAYER_DEF);
user_abc = std::make_unique<UserHuman>(PLAYER_ABC);
user_def.reset(BotFactory::get(bot, PLAYER_DEF));
}

GameConfig gc = {
cards, samples, !imbalanced,
cards, samples, !imbalanced,
first == FIRST_ABC ? PLAYER_ABC : PLAYER_DEF
.player_abc_cards = cards,
.player_abc_samples = samples,
.player_abc_balanced = !imbalanced,

.player_def_cards = cards,
.player_def_samples = samples,
.player_def_balanced = !imbalanced,

.player_first = first == FIRST_ABC ? PLAYER_ABC : PLAYER_DEF
};

ViewConfig vc = {
.user_abc=user_abc,
.user_def=user_def,
.user_abc=user_abc.get(),
.user_def=user_def.get(),
.bot_delay_sec=delay
};

game = new Game(&gc);
view = new ViewTUI(&vc, game);
game = std::make_unique<Game>(&gc);
view = std::make_unique<ViewTUI>(&vc, game.get());

view->run();

} catch (CaravanException &e) {
printf("%s\n", e.what().c_str());
Expand All @@ -146,12 +155,4 @@ int main(int argc, char *argv[]) {
printf("%s\n", e.what());
exit(EXIT_FAILURE);
}

view->run();

// TODO smart pointers
delete view;
delete user_abc;
delete user_def;
delete game;
}
114 changes: 0 additions & 114 deletions src/caravan/train.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/caravan/user/bot/ai.cpp

This file was deleted.

13 changes: 5 additions & 8 deletions src/caravan/user/bot/factory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand All @@ -9,7 +9,6 @@
#include "caravan/user/bot/factory.h"
#include "caravan/user/bot/normal.h"
#include "caravan/user/bot/friendly.h"
#include "caravan/user/bot/ai.h"

const std::string NAME_NORMAL = "normal";
const std::string NAME_FRIENDLY = "friendly";
Expand All @@ -22,10 +21,8 @@ UserBot* BotFactory::get(std::string name, PlayerName player_name) {
[](unsigned char c) { return std::tolower(c); });

// 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); }
if(name == NAME_AI) { return new UserBotAI(player_name); }
else {
throw CaravanFatalException("Unknown bot name '" + name + "'.");
}
if(name == NAME_NORMAL) return new UserBotNormal(player_name);
if(name == NAME_FRIENDLY) return new UserBotFriendly(player_name);

throw CaravanFatalException("Unknown bot name '" + name + "'.");
}
2 changes: 1 addition & 1 deletion test/caravan/model/test_caravan.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand Down
2 changes: 1 addition & 1 deletion test/caravan/model/test_deck.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand Down
2 changes: 1 addition & 1 deletion test/caravan/model/test_game.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand Down
2 changes: 1 addition & 1 deletion test/caravan/model/test_player.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand Down
2 changes: 1 addition & 1 deletion test/caravan/model/test_table.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2024 r3w0p
// Copyright (c) 2022-2025 r3w0p
// The following code can be redistributed and/or
// modified under the terms of the GPL-3.0 License.

Expand Down

0 comments on commit e1b07a8

Please sign in to comment.