Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 251 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
cmake_minimum_required(VERSION 3.14)

project(TexasSolver LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp:llvm")

# Automatically run Qt's MOC, UIC, and RCC pre-processors
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# Find Qt5 and its required components
find_package(Qt5 COMPONENTS Core Gui Widgets LinguistTools REQUIRED)

# Find OpenMP for multi-threading support, matching the .pro file's configuration
find_package(OpenMP REQUIRED)
# --- Source File Definitions ---

# Core library sources (shared between GUI and CLI)
set(CORE_SOURCES
src/Deck.cpp
src/Card.cpp
src/GameTree.cpp
src/library.cpp
src/compairer/Dic5Compairer.cpp
src/experimental/TCfrSolver.cpp
src/nodes/ActionNode.cpp
src/nodes/ChanceNode.cpp
src/nodes/GameActions.cpp
src/nodes/GameTreeNode.cpp
src/nodes/ShowdownNode.cpp
src/nodes/TerminalNode.cpp
src/pybind/bindSolver.cpp
src/ranges/PrivateCards.cpp
src/ranges/PrivateCardsManager.cpp
src/ranges/RiverCombs.cpp
src/ranges/RiverRangeManager.cpp
src/runtime/PokerSolver.cpp
src/solver/BestResponse.cpp
src/solver/CfrSolver.cpp
src/solver/PCfrSolver.cpp
src/solver/Solver.cpp
src/tools/GameTreeBuildingSettings.cpp
src/tools/lookup8.cpp
src/tools/PrivateRangeConverter.cpp
src/tools/progressbar.cpp
src/tools/Rule.cpp
src/tools/StreetSetting.cpp
src/tools/utils.cpp
src/trainable/CfrPlusTrainable.cpp
src/trainable/DiscountedCfrTrainable.cpp
src/trainable/DiscountedCfrTrainableHF.cpp
src/trainable/DiscountedCfrTrainableSF.cpp
src/trainable/Trainable.cpp
)

# GUI-specific sources
set(GUI_SOURCES
main.cpp
mainwindow.cpp
src/runtime/qsolverjob.cpp
qstextedit.cpp
strategyexplorer.cpp
qstreeview.cpp
src/ui/treeitem.cpp
src/ui/treemodel.cpp
htmltableview.cpp
src/ui/worditemdelegate.cpp
src/ui/tablestrategymodel.cpp
src/ui/strategyitemdelegate.cpp
src/ui/detailwindowsetting.cpp
src/ui/detailviewermodel.cpp
src/ui/detailitemdelegate.cpp
src/ui/roughstrategyviewermodel.cpp
src/ui/roughstrategyitemdelegate.cpp
src/ui/droptextedit.cpp
src/ui/htmltablerangeview.cpp
rangeselector.cpp
src/ui/rangeselectortablemodel.cpp
src/ui/rangeselectortabledelegate.cpp
boardselector.cpp
src/ui/boardselectortablemodel.cpp
src/ui/boardselectortabledelegate.cpp
settingeditor.cpp
)

# Define the list of header files (useful for IDEs)
set(HEADERS
include/tools/half-1-12-0.h
include/trainable/DiscountedCfrTrainableHF.h
include/trainable/DiscountedCfrTrainableSF.h
mainwindow.h
include/Card.h
include/GameTree.h
include/Deck.h
include/json.hpp
include/library.h
include/solver/PCfrSolver.h
include/solver/Solver.h
include/solver/BestResponse.h
include/solver/CfrSolver.h
include/tools/argparse.hpp
include/tools/CommandLineTool.h
include/tools/utils.h
include/tools/GameTreeBuildingSettings.h
include/tools/Rule.h
include/tools/StreetSetting.h
include/tools/lookup8.h
include/tools/PrivateRangeConverter.h
include/tools/progressbar.h
include/runtime/PokerSolver.h
include/trainable/CfrPlusTrainable.h
include/trainable/DiscountedCfrTrainable.h
include/trainable/Trainable.h
include/compairer/Compairer.h
include/compairer/Dic5Compairer.h
include/experimental/TCfrSolver.h
include/nodes/ActionNode.h
include/nodes/ChanceNode.h
include/nodes/GameActions.h
include/nodes/GameTreeNode.h
include/nodes/ShowdownNode.h
include/nodes/TerminalNode.h
include/ranges/PrivateCards.h
include/ranges/PrivateCardsManager.h
include/ranges/RiverCombs.h
include/ranges/RiverRangeManager.h
include/tools/tinyformat.h
include/tools/qdebugstream.h
include/runtime/qsolverjob.h
qstextedit.h
strategyexplorer.h
qstreeview.h
include/ui/treeitem.h
include/ui/treemodel.h
htmltableview.h
include/ui/worditemdelegate.h
include/ui/tablestrategymodel.h
include/ui/strategyitemdelegate.h
include/ui/detailwindowsetting.h
include/ui/detailviewermodel.h
include/ui/detailitemdelegate.h
include/ui/roughstrategyviewermodel.h
include/ui/roughstrategyitemdelegate.h
include/ui/droptextedit.h
include/ui/htmltablerangeview.h
rangeselector.h
include/ui/rangeselectortablemodel.h
include/ui/rangeselectortabledelegate.h
boardselector.h
include/ui/boardselectortablemodel.h
include/ui/boardselectortabledelegate.h
settingeditor.h
)

# Define UI forms to be processed by UIC
set(FORMS
mainwindow.ui
strategyexplorer.ui
rangeselector.ui
boardselector.ui
settingeditor.ui
)

# Define Qt resource files to be processed by RCC
set(GUI_RESOURCES
translations.qrc
)
set(COMMON_RESOURCES
compairer.qrc
)

# Handle translation files (.ts -> .qm)
set(TS_FILES
lang_cn.ts
lang_en.ts
)
qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES})

# --- GUI Application Target ---
add_executable(TexasSolverGui WIN32 MACOSX_BUNDLE
${CORE_SOURCES}
${GUI_SOURCES}
${HEADERS}
${FORMS}
${GUI_RESOURCES}
${COMMON_RESOURCES}
)

# Add include directories for headers and generated files
target_include_directories(TexasSolverGui PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)

# Link to required libraries
target_link_libraries(TexasSolverGui PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets)

# Add compile definitions from the .pro file
target_compile_definitions(TexasSolverGui PRIVATE QT_DEPRECATED_WARNINGS)

# Set optimization level for release builds
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")

# Platform-specific settings for OpenMP and icons
if(OpenMP_FOUND)
target_link_libraries(TexasSolverGui PRIVATE OpenMP::OpenMP_CXX)
endif()

if(WIN32)
# Set the application icon for Windows by creating a resource file
set(RC_FILE ${CMAKE_CURRENT_BINARY_DIR}/TexasSolverGui.rc)
file(WRITE ${RC_FILE} "IDI_ICON1 ICON \"imgs/texassolver_logo.ico\"\n")
target_sources(TexasSolverGui PRIVATE ${RC_FILE})
elseif(APPLE)
# Set the application icon for macOS
set_target_properties(TexasSolverGui PROPERTIES
MACOSX_BUNDLE_ICON_FILE imgs/texassolver_logo.icns
)
endif()

# --- Command-Line Tool Target ---
set(CLI_SOURCES
src/console.cpp
src/tools/CommandLineTool.cpp
)

add_executable(TexasSolverCli
${CORE_SOURCES}
${CLI_SOURCES}
${COMMON_RESOURCES}
)

# Add include directories
target_include_directories(TexasSolverCli PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)

# Link to required libraries (note: only Qt Core is needed for the CLI)
target_link_libraries(TexasSolverCli PRIVATE Qt5::Core)

# Link OpenMP if found
if(OpenMP_FOUND)
target_link_libraries(TexasSolverCli PRIVATE OpenMP::OpenMP_CXX)
endif()

# Add compile definitions
target_compile_definitions(TexasSolverCli PRIVATE QT_DEPRECATED_WARNINGS)
1 change: 1 addition & 0 deletions TexasSolverGui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ SOURCES += \
src/tools/lookup8.cpp \
src/tools/PrivateRangeConverter.cpp \
src/tools/progressbar.cpp \
src/tools/CommandLineTool.cpp \
src/tools/Rule.cpp \
src/tools/StreetSetting.cpp \
src/tools/utils.cpp \
Expand Down
26 changes: 14 additions & 12 deletions include/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <vector>
#include "include/tools/tinyformat.h"
#include <QString>

class Deck; // Forward declaration
using namespace std;

class Card {
Expand All @@ -20,32 +22,32 @@ class Card {
Card();
explicit Card(string card,int card_number_in_deck);
Card(string card);
string getCard();
int getCardInt();
bool empty();
int getNumberInDeckInt();
static int card2int(Card card);
string getCard() const;
int getCardInt() const;
bool empty() const;
int getNumberInDeckInt() const;
static int card2int(const Card& card);
static int strCard2int(string card);
static string intCard2Str(int card);
static uint64_t boardCards2long(vector<string> cards);
static uint64_t boardCard2long(Card& card);
static uint64_t boardCards2long(vector<Card>& cards);
static QString boardCards2html(vector<Card>& cards);
static uint64_t boardCard2long(const Card& card);
static uint64_t boardCards2long(const vector<Card>& cards);
static QString boardCards2html(const vector<Card>& cards);
static inline bool boardsHasIntercept(uint64_t board1,uint64_t board2){
return ((board1 & board2) != 0);
};
static uint64_t boardInts2long(const vector<int>& board);
static uint64_t boardInt2long(int board);
static vector<int> long2board(uint64_t board_long);
static vector<Card> long2boardCards(uint64_t board_long);
static vector<Card> long2boardCards(uint64_t board_long, const Deck& deck);
static string suitToString(int suit);
static string rankToString(int rank);
static int rankToInt(char rank);
static int suitToInt(char suit);
static vector<string> getSuits();
string toString();
string toFormattedString();
QString toFormattedHtml();
string toString() const;
string toFormattedString() const;
QString toFormattedHtml() const;
};

#endif //TEXASSOLVER_CARD_H
4 changes: 2 additions & 2 deletions include/Deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Deck {
public:
Deck();
Deck(const vector<string>& ranks, const vector<string>& suits);
vector<Card>& getCards();
vector<string>& getRanks(){return this->ranks;};
const vector<Card>& getCards() const { return this->cards; }
const vector<string>& getRanks() const { return this->ranks; }
private:
vector<string> ranks;
vector<string> suits;
Expand Down
2 changes: 2 additions & 0 deletions include/compairer/Dic5Compairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Dic5Compairer:public Compairer{
int getRank(vector<Card> cards);
int getRank(vector<int> cards);
static CompairResult compairRanks(int rank_former,int rank_latter);
template<typename T>
Compairer::CompairResult compair_template(const vector<T>& private_former, const vector<T>& private_latter, const vector<T>& public_board);

};

Expand Down
8 changes: 4 additions & 4 deletions include/nodes/GameActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
class GameActions {
public:
GameActions();
GameTreeNode::PokerActions getAction();
double getAmount();
GameTreeNode::PokerActions getAction() const;
double getAmount() const;
GameActions(GameTreeNode::PokerActions action, double amount);
string toString();
string pokerActionToString(GameTreeNode::PokerActions pokerActions);
string toString() const;
string pokerActionToString(GameTreeNode::PokerActions pokerActions) const;
private:
GameTreeNode::PokerActions action;
double amount{};
Expand Down
23 changes: 20 additions & 3 deletions include/ranges/PrivateCards.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ class PrivateCards {
float relative_prob{};
PrivateCards();
PrivateCards(int card1, int card2, float weight);
uint64_t toBoardLong();
int hashCode();
string toString();
uint64_t toBoardLong() const;
int hashCode() const;
string toString() const;
const vector<int> & get_hands() const;
PrivateCards exchange_color(int rank1, int rank2) const {
int new_card1 = this->card1;
int new_card2 = this->card2;

if (this->card1 % 4 == rank1) {
new_card1 = this->card1 - rank1 + rank2;
} else if (this->card1 % 4 == rank2) {
new_card1 = this->card1 - rank2 + rank1;
}

if (this->card2 % 4 == rank1) {
new_card2 = this->card2 - rank1 + rank2;
} else if (this->card2 % 4 == rank2) {
new_card2 = this->card2 - rank2 + rank1;
}
return PrivateCards(new_card1, new_card2, this->weight);
}
private:
vector<int> card_vec;
int hash_code{};
Expand Down
3 changes: 3 additions & 0 deletions include/runtime/PokerSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "include/compairer/Dic5Compairer.h"
#include "include/solver/Solver.h"
#include "include/tools/PrivateRangeConverter.h"
#include "include/solver/CfrSolver.h"
#include "include/solver/PCfrSolver.h"
Expand Down Expand Up @@ -52,6 +53,8 @@ class PokerSolver {
vector<PrivateCards> player2Range;
void dump_strategy(QString dump_file,int dump_rounds);
shared_ptr<GameTree> get_game_tree(){return this->game_tree;};
Solver::AnalysisMode analysis_mode = Solver::AnalysisMode::STANDARD;
string full_board;
Deck* get_deck(){return &this->deck;}
shared_ptr<Solver> get_solver(){return this->solver;}
private:
Expand Down
Loading