Skip to content

Commit

Permalink
Add illegal moves gametest
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzzuti committed Mar 5, 2024
1 parent 70e8673 commit c7bfc4d
Show file tree
Hide file tree
Showing 7 changed files with 681 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ void Game::run(const bool initPlayers) {
this->deck.reset();
this->data.roundData.result = OutEnum::ROUND_CONTINUE;
this->data.roundData.numActivePlayers = this->data.gameData.numNonOutPlayers;

PLOG_DEBUG << "Starting round " << round;
this->startRound(round == 0);
// PREFLOP
Expand All @@ -78,6 +77,7 @@ void Game::run(const bool initPlayers) {
} else if (this->data.roundData.result == OutEnum::GAME_WON) {
// switch to the winner
this->data.nextActivePlayer();
this->data.gameData.playerChips[this->data.betRoundData.playerPos] += this->data.roundData.pot;
this->players[this->data.betRoundData.playerPos]->gameWon();
PLOG_INFO << "Game " << game << " ended in round " << round << "\nWINNER IS " << this->getPlayerInfo() << "\n\n";
break;
Expand Down Expand Up @@ -163,7 +163,7 @@ OutEnum Game::setBlinds() noexcept {
if (this->data.gameData.numNonOutPlayers == 2) {
// heads up rule (small blind is the dealer)
// adjust button if the big blind would be the same player again
if (this->data.roundData.bigBlindPos != this->data.roundData.dealerPos) this->data.roundData.dealerPos = this->data.roundData.bigBlindPos;
this->data.roundData.dealerPos = this->data.roundData.bigBlindPos;
this->data.betRoundData.playerPos = this->data.roundData.dealerPos;
}
OutEnum res = OutEnum::ROUND_CONTINUE;
Expand Down Expand Up @@ -230,8 +230,8 @@ void Game::startRound(const bool firstRound) {
if (this->data.gameData.playerOut[i]) continue;
this->players[i]->setHand(this->deck.draw(), this->deck.draw());
}

// first action is setting the blinds
if (firstRound) this->data.roundData.bigBlindPos = 0; // fix first round heads up
this->data.roundData.result = this->setBlinds();
}

Expand Down
5 changes: 5 additions & 0 deletions tests/gametests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ add_executable(gtestc_test main_test.cpp test_gametest.cpp ${SRC_DIR}/game.cpp $
target_link_libraries(gtestc_test gtest_main)
target_include_directories(gtestc_test PUBLIC ${INCLUDE_DIR} ${PLAYER_DIR} ${TEST_DIR})

add_executable(gtestc_illegal_moves main_test.cpp illegal_moves_gametest.cpp ${SRC_DIR}/game.cpp ${COMMON_SRC} ${TEST_PLAYER} ${RAND_PLAYER} ${CHECK_PLAYER})
target_link_libraries(gtestc_illegal_moves gtest_main)
target_include_directories(gtestc_illegal_moves PUBLIC ${INCLUDE_DIR} ${PLAYER_DIR} ${TEST_DIR})

add_test(GTEST_TEST gtestc_test)
add_test(GTEST_ILLEGAL_MOVES gtestc_illegal_moves)
409 changes: 409 additions & 0 deletions tests/gametests/illegal_moves_gametest.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/gametests/test_gametest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TEST(ClassName, TestName) {
EXPECT_EQ(testConfig.smallBlind, data.roundData.smallBlind);
EXPECT_EQ(testConfig.numPlayers == 2 ? 1 : 2, data.roundData.bigBlindPos);
EXPECT_EQ(testConfig.numPlayers == 2 ? 0 : 1, data.roundData.smallBlindPos);
EXPECT_EQ(testConfig.numPlayers == 2 ? 1 : 0, data.roundData.dealerPos);
EXPECT_EQ(0, data.roundData.dealerPos);
u_int8_t communityCardsCount = data.roundData.betRoundState == BetRoundState::PREFLOP ? 0
: data.roundData.betRoundState == BetRoundState::FLOP ? 3
: data.roundData.betRoundState == BetRoundState::TURN ? 4
Expand Down
2 changes: 1 addition & 1 deletion tests/testc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool checkFileConfigs(const std::vector<FileConfig>& fileConfigs) {
// check for empty player actions
for (u_int8_t i = 0; i < testConfig.numPlayers; i++) {
if (testConfig.playerActions[i].empty()) {
std::cerr << "No moves found for player " << i << errorLocation << std::endl;
std::cerr << "No moves found for player " << +i << errorLocation << std::endl;
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testc/testc_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void compileResultDataCheck(std::ofstream& outputFile) noexcept {
outputFile << "\tEXPECT_EQ(testConfig.smallBlind, data.roundData.smallBlind);" << std::endl;
outputFile << "\tEXPECT_EQ(testConfig.numPlayers == 2 ? 1 : 2, data.roundData.bigBlindPos);" << std::endl;
outputFile << "\tEXPECT_EQ(testConfig.numPlayers == 2 ? 0 : 1, data.roundData.smallBlindPos);" << std::endl;
outputFile << "\tEXPECT_EQ(testConfig.numPlayers == 2 ? 1 : 0, data.roundData.dealerPos);" << std::endl;
outputFile << "\tEXPECT_EQ(0, data.roundData.dealerPos);" << std::endl;
outputFile << "\tu_int8_t communityCardsCount = data.roundData.betRoundState == BetRoundState::PREFLOP ? 0" << std::endl;
outputFile << "\t\t\t\t\t\t\t\t\t: data.roundData.betRoundState == BetRoundState::FLOP ? 3" << std::endl;
outputFile << "\t\t\t\t\t\t\t\t\t: data.roundData.betRoundState == BetRoundState::TURN ? 4" << std::endl;
Expand Down
261 changes: 261 additions & 0 deletions tests/testscripts/illegal_moves.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
//************************ ILLEGAL CHECK GAME TESTS ************************//
FILE_NAME: illegal_moves_gametest.cpp // file name, should be unique, stored in gametests folder
CMAKE_TEST_NAME: illegal_moves // cmake test name, should be unique, used in cmake add_test

TEST: IllegalMoves Check // googletest class name and test name
// these can be in any order until SMALL_BLIND
PLAYER_NUM: 6 // number of players
PLAYER_CHIPS: 1000 1000 1000 1000 1000 1000 // chips for each player separated by space
PLAYER_CARDS: RR RR RR RR RR RR // cards for each player separated by space (H3SA: Heart 3, Spade Ace, etc., R for random card)
COMMUNITY_CARDS: RRRRR // community cards (flop: first 3 cards, turn: 4th card, river: 5th card, R for random card)
SMALL_BLIND: 10 // small blind (big blind is 2 * small blind)

// the following are the action taken by each player
// the player is identified with P0, P1, P2, etc. until Pn-1
// please note that you have to TODO

// actions are in the format of: P<n>: <action>[<amount>]
// actions are: c (call), r<bet> (raise), f (fold), chk (check), b<bet> (bet)
// small blind and big blind are set, first-to-act player is P0 (for 2 or 3 players) or P3 (for 4 or more players)

// preflop
P3: chk
P4: c
P5: c
P0: c
P1: c
P2: chk
// flop (first-to-act player is P1)
P1: chk
P4: b20
P5: c
P0: c
P1: chk
// turn (first-to-act player is P1)
P4: b40
P5: c
P0: c
// river (first-to-act player is P1)
P4: b80
P5: r160
P0: chk
P4: chk
END_MOVES // indicates the end of moves
// showdown
// player 5 should win

// result data
// how many chips are in the pot at the end of the game, in format of: POT: <pot>
POT: 520
// chips for each player after the game, in format of: PLAYER_CHIPS: <P0 chips> <P1 chips>...<Pn-1 chips>
PLAYER_CHIPS: 920 980 980 1000 840 1280
// which player is out, "t" and "f" for true and false, in format of: PLAYER_OUT: <P0 out?><P1 out?>...<Pn-1 out?>
PLAYER_OUT: tttttf
// which player folded, "t" and "f" for true and false, in format of: PLAYER_FOLD: <P0 fold?><P1 fold?>...<Pn-1 fold?>
PLAYER_FOLD: ffffff
// which players are the winner, "t" and "f" for true and false, in format of: WINNER: <P0 win?><P1 win?>...<Pn-1 win?>
// there can be a tie which is considered as win for all tie players
WINNER: ffffft
// on which stage did the game end (preflop/flop/turn/river), in format of: GAME_STAGE: <p|f|t|r>
GAME_STAGE: r

// ************************ ILLEGAL CALL GAME TESTS ************************//

TEST: IllegalMoves Call // googletest class name and test name
// these can be in any order until SMALL_BLIND
PLAYER_NUM: 3 // number of players
PLAYER_CHIPS: 1000 1000 100 // chips for each player separated by space
PLAYER_CARDS: RR RR RR // cards for each player separated by space (H3SA: Heart 3, Spade Ace, etc., R for random card)
COMMUNITY_CARDS: RRRRR // community cards (flop: first 3 cards, turn: 4th card, river: 5th card, R for random card)
SMALL_BLIND: 10 // small blind (big blind is 2 * small blind)

// the following are the action taken by each player
// the player is identified with P0, P1, P2, etc. until Pn-1
// please note that you have to TODO

// actions are in the format of: P<n>: <action>[<amount>]
// actions are: c (call), r<bet> (raise), f (fold), chk (check), b<bet> (bet)
// small blind and big blind are set, first-to-act player is P0 (for 2 or 3 players) or P3 (for 4 or more players)

// preflop
P0: c
P1: c
P2: c
// flop (first-to-act player is P1)
P1: chk
P2: b20
P0: r91
P1: c
P2: c // illegal
// turn (first-to-act player is P1)
P1: chk
P0: c // illegal
// river (first-to-act player is P1)
END_MOVES // indicates the end of moves
// showdown

// result data
// how many chips are in the pot at the end of the game, in format of: POT: <pot>
POT: 262
// chips for each player after the game, in format of: PLAYER_CHIPS: <P0 chips> <P1 chips>...<Pn-1 chips>
PLAYER_CHIPS: 889 1151 60
// which player is out, "t" and "f" for true and false, in format of: PLAYER_OUT: <P0 out?><P1 out?>...<Pn-1 out?>
PLAYER_OUT: tft
// which player folded, "t" and "f" for true and false, in format of: PLAYER_FOLD: <P0 fold?><P1 fold?>...<Pn-1 fold?>
PLAYER_FOLD: fff
// which players are the winner, "t" and "f" for true and false, in format of: WINNER: <P0 win?><P1 win?>...<Pn-1 win?>
// there can be a tie which is considered as win for all tie players
WINNER: ftf
// on which stage did the game end (preflop/flop/turn/river), in format of: GAME_STAGE: <p|f|t|r>
GAME_STAGE: t

// ************************ ILLEGAL RAISE GAME TESTS ************************//

TEST: IllegalMoves Raise // googletest class name and test name
// these can be in any order until SMALL_BLIND
PLAYER_NUM: 6 // number of players
PLAYER_CHIPS: 100 1000 1000 1000 1000 1000 // chips for each player separated by space
PLAYER_CARDS: RR RR RR RR RR RR // cards for each player separated by space (H3SA: Heart 3, Spade Ace, etc., R for random card)
COMMUNITY_CARDS: RRRRR // community cards (flop: first 3 cards, turn: 4th card, river: 5th card, R for random card)
SMALL_BLIND: 10 // small blind (big blind is 2 * small blind)

// the following are the action taken by each player
// the player is identified with P0, P1, P2, etc. until Pn-1
// please note that you have to TODO

// actions are in the format of: P<n>: <action>[<amount>]
// actions are: c (call), r<bet> (raise), f (fold), chk (check), b<bet> (bet)
// small blind and big blind are set, first-to-act player is P0 (for 2 or 3 players) or P3 (for 4 or more players)

// preflop
P3: r30 // illegal
P4: c
P5: c
P0: c
P1: c
P2: r40
P3: c
P4: c
P5: c
P0: c
P1: c
// flop (first-to-act player is P1)
P1: chk
P2: chk
P4: r40 // illegal
P5: b20
P0: r70 // illegal
P1: r60
P2: r100
P5: r130 // illegal
P1: c
// turn (first-to-act player is P1)
P1: chk
P2: b40
P1: r60 // illegal
// river (first-to-act player is P1)
END_MOVES // indicates the end of moves
// showdown

// result data
// how many chips are in the pot at the end of the game, in format of: POT: <pot>
POT: 460
// chips for each player after the game, in format of: PLAYER_CHIPS: <P0 chips> <P1 chips>...<Pn-1 chips>
PLAYER_CHIPS: 60 860 1280 1000 960 940
// which player is out, "t" and "f" for true and false, in format of: PLAYER_OUT: <P0 out?><P1 out?>...<Pn-1 out?>
PLAYER_OUT: ttfttt
// which player folded, "t" and "f" for true and false, in format of: PLAYER_FOLD: <P0 fold?><P1 fold?>...<Pn-1 fold?>
PLAYER_FOLD: ffffff
// which players are the winner, "t" and "f" for true and false, in format of: WINNER: <P0 win?><P1 win?>...<Pn-1 win?>
// there can be a tie which is considered as win for all tie players
WINNER: fftfff
// on which stage did the game end (preflop/flop/turn/river), in format of: GAME_STAGE: <p|f|t|r>
GAME_STAGE: t

// ************************ ILLEGAL BET GAME TESTS ************************//

TEST: IllegalMoves Bet // googletest class name and test name
// these can be in any order until SMALL_BLIND
PLAYER_NUM: 4 // number of players
PLAYER_CHIPS: 100 1000 1000 1000 // chips for each player separated by space
PLAYER_CARDS: RR RR RR RR // cards for each player separated by space (H3SA: Heart 3, Spade Ace, etc., R for random card)
COMMUNITY_CARDS: RRRRR // community cards (flop: first 3 cards, turn: 4th card, river: 5th card, R for random card)
SMALL_BLIND: 10 // small blind (big blind is 2 * small blind)

// the following are the action taken by each player
// the player is identified with P0, P1, P2, etc. until Pn-1
// please note that you have to TODO

// actions are in the format of: P<n>: <action>[<amount>]
// actions are: c (call), r<bet> (raise), f (fold), chk (check), b<bet> (bet)
// small blind and big blind are set, first-to-act player is P0 (for 2 or 3 players) or P3 (for 4 or more players)

// preflop
P3: b100 // illegal
P0: c
P1: c
P2: b20 // illegal
// flop (first-to-act player is P1)
P1: chk
P0: b100 // illegal
// turn (first-to-act player is P1)
// river (first-to-act player is P1)
END_MOVES // indicates the end of moves
// showdown

// result data
// how many chips are in the pot at the end of the game, in format of: POT: <pot>
POT: 60
// chips for each player after the game, in format of: PLAYER_CHIPS: <P0 chips> <P1 chips>...<Pn-1 chips>
PLAYER_CHIPS: 80 1040 980 1000
// which player is out, "t" and "f" for true and false, in format of: PLAYER_OUT: <P0 out?><P1 out?>...<Pn-1 out?>
PLAYER_OUT: tftt
// which player folded, "t" and "f" for true and false, in format of: PLAYER_FOLD: <P0 fold?><P1 fold?>...<Pn-1 fold?>
PLAYER_FOLD: ffff
// which players are the winner, "t" and "f" for true and false, in format of: WINNER: <P0 win?><P1 win?>...<Pn-1 win?>
// there can be a tie which is considered as win for all tie players
WINNER: ftff
// on which stage did the game end (preflop/flop/turn/river), in format of: GAME_STAGE: <p|f|t|r>
GAME_STAGE: f

// ************************ ILLEGAL FOLD GAME TESTS ************************//

TEST: IllegalMoves Fold // googletest class name and test name
// these can be in any order until SMALL_BLIND
PLAYER_NUM: 2 // number of players
PLAYER_CHIPS: 100 1000 // chips for each player separated by space
PLAYER_CARDS: RR RR // cards for each player separated by space (H3SA: Heart 3, Spade Ace, etc., R for random card)
COMMUNITY_CARDS: RRRRR // community cards (flop: first 3 cards, turn: 4th card, river: 5th card, R for random card)
SMALL_BLIND: 10 // small blind (big blind is 2 * small blind)

// the following are the action taken by each player
// the player is identified with P0, P1, P2, etc. until Pn-1
// please note that you have to TODO

// actions are in the format of: P<n>: <action>[<amount>]
// actions are: c (call), r<bet> (raise), f (fold), chk (check), b<bet> (bet)
// small blind and big blind are set, first-to-act player is P0 (for 2 or 3 players) or P3 (for 4 or more players)

// preflop
P0: c
P1: f // illegal
// flop (first-to-act player is P1)
// turn (first-to-act player is P1)
// river (first-to-act player is P1)
END_MOVES // indicates the end of moves
// showdown

// result data
// how many chips are in the pot at the end of the game, in format of: POT: <pot>
POT: 40
// chips for each player after the game, in format of: PLAYER_CHIPS: <P0 chips> <P1 chips>...<Pn-1 chips>
PLAYER_CHIPS: 120 980
// which player is out, "t" and "f" for true and false, in format of: PLAYER_OUT: <P0 out?><P1 out?>...<Pn-1 out?>
PLAYER_OUT: ft
// which player folded, "t" and "f" for true and false, in format of: PLAYER_FOLD: <P0 fold?><P1 fold?>...<Pn-1 fold?>
PLAYER_FOLD: ff
// which players are the winner, "t" and "f" for true and false, in format of: WINNER: <P0 win?><P1 win?>...<Pn-1 win?>
// there can be a tie which is considered as win for all tie players
WINNER: tf
// on which stage did the game end (preflop/flop/turn/river), in format of: GAME_STAGE: <p|f|t|r>
GAME_STAGE: p

0 comments on commit c7bfc4d

Please sign in to comment.