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)
8 changes: 4 additions & 4 deletions include/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class Card {
explicit Card(string card,int card_number_in_deck);
Card(string card);
string getCard();
int getCardInt();
int getCardInt() const;
bool empty();
int getNumberInDeckInt();
int getNumberInDeckInt() const;
static int card2int(Card card);
static int strCard2int(string card);
static string intCard2Str(int card);
Expand All @@ -43,8 +43,8 @@ class Card {
static int rankToInt(char rank);
static int suitToInt(char suit);
static vector<string> getSuits();
string toString();
string toFormattedString();
string toString() const;
string toFormattedString() const;
QString toFormattedHtml();
};

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
6 changes: 4 additions & 2 deletions include/runtime/PokerSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class PokerSolver {
float accuracy,
bool use_isomorphism,
int use_halffloats,
int threads
int threads,
const vector<LockedNode>& locked_nodes,
const std::optional<FullBoardSituation>& full_board_situation
);
void stop();
long long estimate_tree_memory(QString range1,QString range2,QString board);
vector<PrivateCards> player1Range;
vector<PrivateCards> player2Range;
void dump_strategy(QString dump_file,int dump_rounds);
void dump_strategy(QString dump_file,int dump_rounds = 2);
shared_ptr<GameTree> get_game_tree(){return this->game_tree;};
Deck* get_deck(){return &this->deck;}
shared_ptr<Solver> get_solver(){return this->solver;}
Expand Down
7 changes: 6 additions & 1 deletion include/runtime/qsolverjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <QTextEdit>
#include <QPlainTextEdit>
#include "qstextedit.h"
#include "include/solver/solver_options.h"
#include <optional>
#include <QDebug>
#include <QSettings>

Expand Down Expand Up @@ -39,7 +41,7 @@ class QSolverJob : public QThread
float small_blind=0.5;
float big_blind=1;
float stack=20 + 5;
float allin_threshold = 0.67;
float allin_threshold = 0.67f;
string range_ip;
string range_oop;
string board;
Expand All @@ -49,6 +51,9 @@ class QSolverJob : public QThread
int use_halffloats=0;
int print_interval=10;
int dump_rounds = 2;
// Add these new members for analysis features
std::vector<LockedNode> locked_nodes;
std::optional<FullBoardSituation> full_board_situation;
shared_ptr<GameTreeBuildingSettings> gtbs;

PokerSolver* get_solver();
Expand Down
32 changes: 22 additions & 10 deletions include/solver/PCfrSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#include <include/trainable/DiscountedCfrTrainable.h>
#include "include/solver/Solver.h"
#include <omp.h>
#include "include/solver/solver_options.h"
#include "include/tools/lookup8.h"
#include "include/tools/utils.h"
#include <queue>
#include <optional>
/*
#include <unordered_map>
/*
template<typename T>
class ThreadsafeQueue {
std::queue<T> queue_;
Expand Down Expand Up @@ -93,12 +95,22 @@ class PCfrSolver:public Solver {
int num_threads
);
~PCfrSolver();
void train() override;
void train(const vector<LockedNode>& locked_nodes, const std::optional<FullBoardSituation>& full_board) override;
void stop() override;
json dumps(bool with_status,int depth) override;
vector<vector<vector<float>>> get_strategy(shared_ptr<ActionNode> node,vector<Card> chance_cards) override;
vector<vector<vector<float>>> get_evs(shared_ptr<ActionNode> node,vector<Card> chance_cards) override;
json dumps(bool with_status, int depth) override;
ActionStrategy get_strategy(shared_ptr<ActionNode> node, vector<Card> chance_cards, const std::string& path) override;
ActionEVs get_evs(shared_ptr<ActionNode> node, vector<Card> chance_cards, const std::string& path) override;
private:
struct AnalysisState {
bool enabled = false;
std::unordered_map<std::string, const LockedNode*> locked_nodes_map;
std::optional<FullBoardSituation> full_board;

bool isNodeLocked(const std::string& path, int player) const;
const Strategy* getLockedStrategy(const std::string& path, int player) const;
};
AnalysisState m_analysis;

vector<vector<PrivateCards>> ranges;
vector<PrivateCards> range1;
vector<PrivateCards> range2;
Expand Down Expand Up @@ -134,12 +146,12 @@ class PCfrSolver:public Solver {
vector<vector<float>> getReachProbs();
static vector<PrivateCards> noDuplicateRange(const vector<PrivateCards>& private_range,uint64_t board_long);
void setTrainable(shared_ptr<GameTreeNode> root);
vector<float> cfr(int player, shared_ptr<GameTreeNode> node, const vector<float>& reach_probs, int iter, uint64_t current_board,int deal);
vector<float> cfr(int player, shared_ptr<GameTreeNode> node, const vector<float>& reach_probs, int iter, uint64_t current_board,int deal, const string& path);
vector<int> getAllAbstractionDeal(int deal);
vector<float> chanceUtility(int player,shared_ptr<ChanceNode> node,const vector<float>& reach_probs,int iter,uint64_t current_boardi,int deal);
vector<float> showdownUtility(int player,shared_ptr<ShowdownNode> node,const vector<float>& reach_probs,int iter,uint64_t current_board,int deal);
vector<float> actionUtility(int player,shared_ptr<ActionNode> node,const vector<float>& reach_probs,int iter,uint64_t current_board,int deal);
vector<float> terminalUtility(int player,shared_ptr<TerminalNode> node,const vector<float>& reach_prob,int iter,uint64_t current_board,int deal);
vector<float> chanceUtility(int player,shared_ptr<ChanceNode> node,const vector<float>& reach_probs,int iter,uint64_t current_board,int deal, const string& path);
vector<float> showdownUtility(int player,shared_ptr<ShowdownNode> node,const vector<float>& reach_probs,int iter,uint64_t current_board,int deal, const string& path);
vector<float> actionUtility(int player,shared_ptr<ActionNode> node,const vector<float>& reach_probs,int iter,uint64_t current_board,int deal, const string& path);
vector<float> terminalUtility(int player,shared_ptr<TerminalNode> node,const vector<float>& reach_prob,int iter,uint64_t current_board,int deal, const string& path);
void findGameSpecificIsomorphisms();
void purnTree();
void exchangeRange(json& strategy,int rank1,int rank2,shared_ptr<ActionNode> one_node);
Expand Down
Loading