Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice_cfr #194

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -32,13 +32,15 @@ jobs:
# Runs a set of commands using the runners shell
- name: install dependencies
run: |
sudo apt install -y qt5-default qtbase5-dev qt5-qmake build-essential wget
sudo apt install -y qtbase5-dev qt5-qmake qttools5-dev build-essential wget cmake

# Runs a set of commands using the runners shell
- name: make appimage
run: |
ls
./build-AppImage.sh
ls
cmake --version
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
make -C build -j

- uses: actions/upload-artifact@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
134 changes: 134 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
cmake_minimum_required(VERSION 3.20)

option(USE_CUDA "" OFF)
option(QT_GUI "" ON)
option(BUILD_API "" ON)

if(USE_CUDA)
project(TexasSolver LANGUAGES CXX CUDA)
else()
project(TexasSolver LANGUAGES CXX)
endif()

set(CMAKE_CXX_STANDARD 20)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
message("CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(include)

find_package(OpenMP REQUIRED)
message("OpenMP_CXX_FLAGS=${OpenMP_CXX_FLAGS}")

file(GLOB_RECURSE SRC src/*.cpp)
file(GLOB_RECURSE EXC_SRC src/*format.cpp)
file(GLOB GUI_SRC *.cpp src/ui/*.cpp src/runtime/qsolverjob.cpp)
file(GLOB API_SRC src/api.cpp)
file(GLOB EXE_SRC src/console.cpp)
list(REMOVE_ITEM SRC ${EXC_SRC} ${GUI_SRC} ${EXE_SRC} ${API_SRC})
# message("SRC=${SRC}")
# message("EXC_SRC=${EXC_SRC}")
# message("GUI_SRC=${GUI_SRC}")
# message("API_SRC=${API_SRC}")
# message("EXE_SRC=${EXE_SRC}")

if(USE_CUDA)
add_definitions(-DUSE_CUDA)
file(GLOB_RECURSE CUDA_SRC src/*.cu)
message("CUDA_SRC=${CUDA_SRC}")

set(CMAKE_CUDA_STANDARD 20)
# set(CMAKE_CUDA_STANDARD_REQUIRED ON)
message("CMAKE_MINOR_VERSION=${CMAKE_MINOR_VERSION}")
if(${CMAKE_MINOR_VERSION} GREATER_EQUAL 24)
# set(CMAKE_CUDA_ARCHITECTURES all)
set(CMAKE_CUDA_ARCHITECTURES all-major)
# set(CMAKE_CUDA_ARCHITECTURES native)
else()
set(CMAKE_CUDA_ARCHITECTURES OFF)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=all-major")
endif()
message("CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}")

message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
if((DEFINED CMAKE_BUILD_TYPE) AND (CMAKE_BUILD_TYPE STREQUAL Debug))
set(CMAKE_CUDA_FLAGS "-g -G ${CMAKE_CUDA_FLAGS}")
endif()

set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler ${OpenMP_CXX_FLAGS}")
message("CMAKE_CUDA_FLAGS=${CMAKE_CUDA_FLAGS}")
endif()

set(BASE_LIB TexasSolver)
add_library(${BASE_LIB} ${SRC} ${CUDA_SRC})
target_link_libraries(${BASE_LIB} PUBLIC OpenMP::OpenMP_CXX)
if(USE_CUDA)
# set_target_properties(${BASE_LIB} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif()

if(BUILD_API)
set(API_TARGET api)
add_library(${API_TARGET} SHARED ${API_SRC})
target_link_libraries(${API_TARGET} PUBLIC ${BASE_LIB})
endif()

set(EXE console_solver)
add_executable(${EXE} ${EXE_SRC})
target_link_libraries(${EXE} PRIVATE ${BASE_LIB})
if(MSVC)
target_link_options(${EXE} PUBLIC "/NODEFAULTLIB:LIBCMT")
endif()

if(QT_GUI)
file(GLOB FORMS *.ui)
file(GLOB RESOURCES *.qrc)
file(GLOB TS_FILES *.ts)
file(GLOB QM_FILES *.qm)
# message("FORMS=${FORMS}")
# message("RESOURCES=${RESOURCES}")
# message("TS_FILES=${TS_FILES}")
# message("QM_FILES=${QM_FILES}")

# set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
set(QT_MAJOR Qt${QT_VERSION_MAJOR})
message("QT_MAJOR=${QT_MAJOR}")
find_package(${QT_MAJOR} REQUIRED COMPONENTS Core Widgets LinguistTools)

SET(ICON_NAME texassolver_logo)
if(WIN32)
file(GLOB ICON_FILE imgs/${ICON_NAME}.rc)
elseif(APPLE)
set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}.icns)
file(GLOB ICON_FILE imgs/${ICON_NAME}.icns)
set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
endif()
# message("ICON_FILE=${ICON_FILE}")

# set(CMAKE_AUTOMOC ON) doesn't work
# Q_OBJECT header
file(GLOB HEADERS *.h include/ui/*.h include/runtime/qsolverjob.h)
# message("HEADERS=${HEADERS}")
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt6_wrap_cpp(GUI_SRC ${HEADERS})
else()
qt5_wrap_cpp(GUI_SRC ${HEADERS})
endif()
# message("GUI_SRC=${GUI_SRC}")

set(GUI TexasSolverGui)
add_executable(${GUI} ${GUI_SRC} ${EXC_SRC} ${RESOURCES} ${FORMS} ${ICON_FILE})
target_link_libraries(${GUI} PRIVATE ${QT_MAJOR}::Widgets ${QT_MAJOR}::Core ${BASE_LIB})
set_target_properties(${GUI} PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
)
endif()
9 changes: 8 additions & 1 deletion TexasSolverGui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
TRANSLATIONS = lang_cn.ts\
lang_en.ts

CONFIG += c++2a

macx: {
QMAKE_CXXFLAGS += -Xpreprocessor -fopenmp -lomp -I/usr/local/include
Expand Down Expand Up @@ -64,7 +65,8 @@ SOURCES += \
mainwindow.cpp \
src/Deck.cpp \
src/Card.cpp \
src/console.cpp \
src/card_format.cpp \
# src/console.cpp \
src/GameTree.cpp \
src/library.cpp \
src/compairer/Dic5Compairer.cpp \
Expand All @@ -85,6 +87,7 @@ SOURCES += \
src/solver/CfrSolver.cpp \
src/solver/PCfrSolver.cpp \
src/solver/Solver.cpp \
src/solver/slice_cfr.cpp \
src/tools/CommandLineTool.cpp \
src/tools/GameTreeBuildingSettings.cpp \
src/tools/lookup8.cpp \
Expand All @@ -93,6 +96,7 @@ SOURCES += \
src/tools/Rule.cpp \
src/tools/StreetSetting.cpp \
src/tools/utils.cpp \
src/tools/logger.cpp \
src/trainable/CfrPlusTrainable.cpp \
src/trainable/DiscountedCfrTrainable.cpp \
src/trainable/DiscountedCfrTrainableHF.cpp \
Expand Down Expand Up @@ -129,6 +133,7 @@ HEADERS += \
include/trainable/DiscountedCfrTrainableSF.h \
mainwindow.h \
include/Card.h \
include/card_format.h \
include/GameTree.h \
include/Deck.h \
include/json.hpp \
Expand All @@ -137,6 +142,7 @@ HEADERS += \
include/solver/Solver.h \
include/solver/BestResponse.h \
include/solver/CfrSolver.h \
include/solver/slice_cfr.h \
include/tools/argparse.hpp \
include/tools/CommandLineTool.h \
include/tools/utils.h \
Expand Down Expand Up @@ -164,6 +170,7 @@ HEADERS += \
include/ranges/RiverCombs.h \
include/ranges/RiverRangeManager.h \
include/tools/tinyformat.h \
include/tools/logger.h \
include/tools/qdebugstream.h \
include/runtime/qsolverjob.h \
qstextedit.h \
Expand Down
42 changes: 42 additions & 0 deletions benchmark/texassolver.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
set_pot 10
set_effective_stack 95
set_board Qs,Jh,2h,4d
#set_range_oop AA,KK,QQ,JJ
#set_range_ip QQ:0.5,JJ:0.75
#set_board Qs,Jh,2h
set_range_oop AA,KK,QQ,JJ,TT,99:0.75,88:0.75,77:0.5,66:0.25,55:0.25,AK,AQs,AQo:0.75,AJs,AJo:0.5,ATs:0.75,A6s:0.25,A5s:0.75,A4s:0.75,A3s:0.5,A2s:0.5,KQs,KQo:0.5,KJs,KTs:0.75,K5s:0.25,K4s:0.25,QJs:0.75,QTs:0.75,Q9s:0.5,JTs:0.75,J9s:0.75,J8s:0.75,T9s:0.75,T8s:0.75,T7s:0.75,98s:0.75,97s:0.75,96s:0.5,87s:0.75,86s:0.5,85s:0.5,76s:0.75,75s:0.5,65s:0.75,64s:0.5,54s:0.75,53s:0.5,43s:0.5
set_range_ip QQ:0.5,JJ:0.75,TT,99,88,77,66,55,44,33,22,AKo:0.25,AQs,AQo:0.75,AJs,AJo:0.75,ATs,ATo:0.75,A9s,A8s,A7s,A6s,A5s,A4s,A3s,A2s,KQ,KJ,KTs,KTo:0.5,K9s,K8s,K7s,K6s,K5s,K4s:0.5,K3s:0.5,K2s:0.5,QJ,QTs,Q9s,Q8s,Q7s,JTs,JTo:0.5,J9s,J8s,T9s,T8s,T7s,98s,97s,96s,87s,86s,76s,75s,65s,64s,54s,53s,43s
set_bet_sizes oop,flop,bet,100
set_bet_sizes oop,flop,raise,50
set_bet_sizes oop,flop,allin
set_bet_sizes ip,flop,bet,100
set_bet_sizes ip,flop,raise,50
set_bet_sizes ip,flop,allin
set_bet_sizes oop,turn,bet,100
set_bet_sizes oop,turn,donk,100
set_bet_sizes oop,turn,raise,50
set_bet_sizes oop,turn,allin
set_bet_sizes ip,turn,bet,100
set_bet_sizes ip,turn,raise,50
set_bet_sizes oop,river,bet,100
set_bet_sizes oop,river,donk,100
set_bet_sizes oop,river,raise,50
set_bet_sizes oop,river,allin
set_bet_sizes ip,river,bet,100
set_bet_sizes ip,river,raise,50
set_bet_sizes ip,river,allin
set_allin_threshold 1.0
set_raise_limit 2
build_tree
estimate_tree_memory
set_thread_num 6
#set_thread_num 81920
set_slice_cfr 0
set_accuracy 0.3
set_max_iteration 1
set_print_interval 10
set_use_isomorphism 1
start_solve
set_dump_rounds 1
dump_result output_result2.json
#dump_setting output_setting.txt
6 changes: 3 additions & 3 deletions boardselector.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "boardselector.h"
#include "ui_boardselector.h"

boardselector::boardselector(QTextEdit* boardEdit,QSolverJob::Mode mode,QWidget *parent) :
boardselector::boardselector(QTextEdit* boardEdit,PokerMode mode,QWidget *parent) :
QDialog(parent),
ui(new Ui::boardselector)
{
Expand All @@ -11,9 +11,9 @@ boardselector::boardselector(QTextEdit* boardEdit,QSolverJob::Mode mode,QWidget
this->mode = mode;

QString ranks;
if(mode == QSolverJob::Mode::HOLDEM){
if(mode == PokerMode::HOLDEM){
ranks = "A,K,Q,J,T,9,8,7,6,5,4,3,2";
}else if(mode == QSolverJob::Mode::SHORTDECK){
}else if(mode == PokerMode::SHORTDECK){
ranks = "A,K,Q,J,T,9,8,7,6";
}else{
throw runtime_error("mode not found in range selector");
Expand Down
4 changes: 2 additions & 2 deletions boardselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class boardselector : public QDialog
Q_OBJECT

public:
explicit boardselector(QTextEdit* boardEdit,QSolverJob::Mode mode = QSolverJob::Mode::HOLDEM,QWidget *parent = 0);
explicit boardselector(QTextEdit* boardEdit,PokerMode mode = PokerMode::HOLDEM,QWidget *parent = 0);
~boardselector();

private slots:
Expand All @@ -37,7 +37,7 @@ private slots:
private:
Ui::boardselector *ui;
QTextEdit* boardEdit = NULL;
QSolverJob::Mode mode;
PokerMode mode;
QStringList rank_list;
BoardSelectorTableModel * boardSelectorTableModel = NULL;
BoardSelectorTableDelegate * boardSelectorTableDelegate = NULL;
Expand Down
1 change: 1 addition & 0 deletions imgs/texassolver_logo.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON "texassolver_logo.ico"
14 changes: 7 additions & 7 deletions include/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <vector>
#include "include/tools/tinyformat.h"
#include <QString>
// #include <QString>
using namespace std;

class Card {
Expand All @@ -20,17 +20,17 @@ class Card {
Card();
explicit Card(string card,int card_number_in_deck);
Card(string card);
string getCard();
const string& getCard();
int getCardInt();
bool empty();
int getNumberInDeckInt();
static int card2int(Card card);
static int strCard2int(string card);
static int strCard2int(const 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 QString boardCards2html(vector<Card>& cards);
static inline bool boardsHasIntercept(uint64_t board1,uint64_t board2){
return ((board1 & board2) != 0);
};
Expand All @@ -43,9 +43,9 @@ class Card {
static int rankToInt(char rank);
static int suitToInt(char suit);
static vector<string> getSuits();
string toString();
string toFormattedString();
QString toFormattedHtml();
// string toString();
// string toFormattedString();
// QString toFormattedHtml();
};

#endif //TEXASSOLVER_CARD_H
11 changes: 11 additions & 0 deletions include/card_format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if !defined(_CARD_FORMAT_H_)
#define _CARD_FORMAT_H_

#include <QString>
#include "include/Card.h"

string toFormattedString(Card &card);
QString toFormattedHtml(Card &card);
QString boardCards2html(vector<Card>& cards);

#endif // _CARD_FORMAT_H_
2 changes: 1 addition & 1 deletion include/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Combinations<T>::comb(unsigned long long n, unsigned long long k) {
return r;
}

vector<string> string_split(string strin,char split);
vector<string> string_split(string &strin, char split);
uint64_t timeSinceEpochMillisec();
int random(int min, int max);
float normalization_tanh(float stack,float ev,float ratio=7);
Expand Down
4 changes: 4 additions & 0 deletions include/ranges/RiverRangeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class RiverRangeManager {
RiverRangeManager(shared_ptr<Compairer> handEvaluator);
const vector<RiverCombs>& getRiverCombos(int player, const vector<PrivateCards>& riverCombos, const vector<int>& board);
const vector<RiverCombs>& getRiverCombos(int player, const vector<PrivateCards>& riverCombos, uint64_t board_long);
void clear() {
p1RiverRanges.clear();
p2RiverRanges.clear();
}
private:
unordered_map<uint64_t , vector<RiverCombs>> p1RiverRanges;
unordered_map<uint64_t , vector<RiverCombs>> p2RiverRanges;
Expand Down
Loading
Loading