An agent for the game "FightTheLandlord" (a.k.a. Doudizhu) implemented with Recursive Hand Cards Partition algorithm and Reinforcement Learning improvements. This is written by Songchen Tan, Shang Liu and Keer Zhang to participate in the 13th Peking University Game Contest. See an introduction of this game at http://www.botzone.org/games#FightThelandlord2.
- Clone this repository;
- Make sure you have
cmake >= 3.20
installed; - Build with
mkdir build && cd build && cmake .. && cmake --build .
, and depending on your compiler choice, you may need option likecmake .. -D CMAKE_CXX_COMPILER=g++
; - Run tests with
ctest
; - Run main program with
./main
.
base.h
andbase.cpp
contains definitions of basic data structures likeCard
,Counter
andHand
;strategy.h
andstrategy.cpp
contains the core workflow of the RHCP (Recursive Hand Card Partitioning) algorithm, in terms of functionsattack
,defend
andevaluate
;- To make developing and testing convenient, the
attack
(actively playing cards with no prior hands) as well as thedefend
(passively playing cards with prior hands) are divided in to several stages; - In each stage, a selector tries to find an optimal hand that is of some particular category; if it cannot find such a hand, it raises
not_found
and the algorithm moves to the next stage; - For example, in the
defend
function, one may first try to beat the previous hand with a bigger hand of the same category; if not found, then try to beat the previous hand with Bomb or Rocker; if not found, then pass. - The selectors share the same interface, namely
AttackingSelector
andDefendingSelector
, and several possible selectors are implemented in thestrategy
subfolder.
- To make developing and testing convenient, the
environment.h
andenvironment.cpp
contains the game playing environment, and they are mostly copied from BotZone; as a result, they are not advised to be modified;main.cpp
specifies the strategy with global pointers and launch the game.
base.cpp
contains basic tests for definitions insrc/base.h
;main.cpp
serves as the entry point forCatch2
and launch all tests.