From 5ff851caf73f985a6e499126d8bdf7b05340591d Mon Sep 17 00:00:00 2001 From: georgiypetrov Date: Tue, 3 Nov 2020 13:04:18 +0300 Subject: [PATCH 1/5] support req_allow_deposit state --- 3rdparty/sdk | 2 +- contracts/src/blackjack.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/3rdparty/sdk b/3rdparty/sdk index 5a7f489..0679c25 160000 --- a/3rdparty/sdk +++ b/3rdparty/sdk @@ -1 +1 @@ -Subproject commit 5a7f489c2214b50b8881b6b325ae184674fc516c +Subproject commit 0679c25eddff30f09b210fea73230df1bd201591 diff --git a/contracts/src/blackjack.cpp b/contracts/src/blackjack.cpp index 27d3c54..14a985b 100644 --- a/contracts/src/blackjack.cpp +++ b/contracts/src/blackjack.cpp @@ -287,7 +287,7 @@ void blackjack::on_random(uint64_t ses_id, checksum256 rand) { end_game(ses_id, 3 * ante / 2 + side_bets_win, std::move(dealer_cards), std::move(player_cards)); return; } - require_action(action::play); + require_action(action::play, true); update_state(state_itr, game_state::require_play); update_max_win(ses_id, -4 * bet_itr->pair - 25 * bet_itr->first_three + side_bets_win); send_game_message(std::vector{player_cards[0].get_value(), player_cards[1].get_value(), dealer_cards[0].get_value()}); @@ -331,7 +331,7 @@ void blackjack::on_random(uint64_t ses_id, checksum256 rand) { } send_game_message(std::vector{player_card.get_value()}); update_state(state_itr, game_state::require_play); - require_action(action::play); + require_action(action::play, true); break; } case game_state::stand: { @@ -364,7 +364,7 @@ void blackjack::on_random(uint64_t ses_id, checksum256 rand) { ncard2.get_value() }); update_state(state_itr, game_state::require_play); - require_action(action::play); + require_action(action::play, true); } else { // In most casinos the player is only allowed to draw one card on each split ace // As a general rule, a ten on a split ace (or vice versa) is not considered a natural blackjack and does not get any bonus From eb44bab74b27513382de440291b2c8022d02f299 Mon Sep 17 00:00:00 2001 From: georgiypetrov Date: Tue, 3 Nov 2020 15:50:50 +0300 Subject: [PATCH 2/5] add can't deposit after stand test --- tests/blackjack_tests.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/blackjack_tests.cpp b/tests/blackjack_tests.cpp index 9b4a311..47395c9 100644 --- a/tests/blackjack_tests.cpp +++ b/tests/blackjack_tests.cpp @@ -1123,6 +1123,26 @@ BOOST_FIXTURE_TEST_CASE(max_payout_split, blackjack_tester) { check_player_win(STRSYM("100000.0000")); } +BOOST_FIXTURE_TEST_CASE(cant_deposit_after_stand, blackjack_tester) try { + const auto ses_id = new_game_session(game_name, player_name, casino_id, STRSYM("100.0000")); + bet(ses_id, STRSYM("100.0000")); + + // Tc is a hole card + push_cards(ses_id, {"Kd", "Ts", "Td"}); + signidice(game_name, ses_id); + + stand(ses_id); + + BOOST_REQUIRE_EQUAL(transfer(player_name, game_name, STRSYM("100.0000"), std::to_string(ses_id)), + wasm_assert_msg("state should be 'req_allow_deposit'") + ); + + push_cards(ses_id, {"As"}); + signidice(game_name, ses_id); + // dealer has Td As + check_player_win(-STRSYM("100.0000")); +} FC_LOG_AND_RETHROW() + #endif BOOST_AUTO_TEST_SUITE_END() From 152ec2b70292a9846c408677b340a7f5048233c5 Mon Sep 17 00:00:00 2001 From: georgiypetrov Date: Tue, 3 Nov 2020 16:51:48 +0300 Subject: [PATCH 3/5] add can't deposit after hit test --- tests/blackjack_tests.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/blackjack_tests.cpp b/tests/blackjack_tests.cpp index 47395c9..7a8025d 100644 --- a/tests/blackjack_tests.cpp +++ b/tests/blackjack_tests.cpp @@ -1143,6 +1143,25 @@ BOOST_FIXTURE_TEST_CASE(cant_deposit_after_stand, blackjack_tester) try { check_player_win(-STRSYM("100.0000")); } FC_LOG_AND_RETHROW() +BOOST_FIXTURE_TEST_CASE(cant_deposit_after_hit, blackjack_tester) try { + const auto ses_id = new_game_session(game_name, player_name, casino_id, STRSYM("100.0000")); + bet(ses_id, STRSYM("100.0000")); + + push_cards(ses_id, {"Kd", "Ts", "Td"}); + signidice(game_name, ses_id); + + hit(ses_id); + + BOOST_REQUIRE_EQUAL(transfer(player_name, game_name, STRSYM("100.0000"), std::to_string(ses_id)), + wasm_assert_msg("state should be 'req_allow_deposit'") + ); + + push_cards(ses_id, {"3d", "Jh"}); + signidice(game_name, ses_id); + + check_player_win(-STRSYM("100.0000")); +} FC_LOG_AND_RETHROW() + #endif BOOST_AUTO_TEST_SUITE_END() From e3b2003ebdd9f5d7f8bc7690653dfe40381836cd Mon Sep 17 00:00:00 2001 From: georgiypetrov Date: Thu, 5 Nov 2020 18:15:36 +0300 Subject: [PATCH 4/5] allow deposits on game actions --- contracts/src/blackjack.cpp | 4 ++-- tests/blackjack_tests.cpp | 39 ------------------------------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/contracts/src/blackjack.cpp b/contracts/src/blackjack.cpp index 14a985b..6b2bd6e 100644 --- a/contracts/src/blackjack.cpp +++ b/contracts/src/blackjack.cpp @@ -217,7 +217,7 @@ void blackjack::on_action(uint64_t ses_id, uint16_t type, std::vectorhas_split() && !state_itr->second_round) { eosio::print("player stands and swaps active cards\n"); finish_first_round(state_itr); - require_action(action::play); + require_action(action::play, true); return; } update_state(state_itr, game_state::stand); @@ -305,7 +305,7 @@ void blackjack::on_random(uint64_t ses_id, checksum256 rand) { finish_first_round(state_itr); } } - require_action(action::play); + require_action(action::play, true); update_state(state_itr, game_state::require_play); // if player has 2 cards and hasn't split it means it's his first action in the game if (!state_itr->has_split() && state_itr->active_cards.size() == 2) { diff --git a/tests/blackjack_tests.cpp b/tests/blackjack_tests.cpp index 7a8025d..9b4a311 100644 --- a/tests/blackjack_tests.cpp +++ b/tests/blackjack_tests.cpp @@ -1123,45 +1123,6 @@ BOOST_FIXTURE_TEST_CASE(max_payout_split, blackjack_tester) { check_player_win(STRSYM("100000.0000")); } -BOOST_FIXTURE_TEST_CASE(cant_deposit_after_stand, blackjack_tester) try { - const auto ses_id = new_game_session(game_name, player_name, casino_id, STRSYM("100.0000")); - bet(ses_id, STRSYM("100.0000")); - - // Tc is a hole card - push_cards(ses_id, {"Kd", "Ts", "Td"}); - signidice(game_name, ses_id); - - stand(ses_id); - - BOOST_REQUIRE_EQUAL(transfer(player_name, game_name, STRSYM("100.0000"), std::to_string(ses_id)), - wasm_assert_msg("state should be 'req_allow_deposit'") - ); - - push_cards(ses_id, {"As"}); - signidice(game_name, ses_id); - // dealer has Td As - check_player_win(-STRSYM("100.0000")); -} FC_LOG_AND_RETHROW() - -BOOST_FIXTURE_TEST_CASE(cant_deposit_after_hit, blackjack_tester) try { - const auto ses_id = new_game_session(game_name, player_name, casino_id, STRSYM("100.0000")); - bet(ses_id, STRSYM("100.0000")); - - push_cards(ses_id, {"Kd", "Ts", "Td"}); - signidice(game_name, ses_id); - - hit(ses_id); - - BOOST_REQUIRE_EQUAL(transfer(player_name, game_name, STRSYM("100.0000"), std::to_string(ses_id)), - wasm_assert_msg("state should be 'req_allow_deposit'") - ); - - push_cards(ses_id, {"3d", "Jh"}); - signidice(game_name, ses_id); - - check_player_win(-STRSYM("100.0000")); -} FC_LOG_AND_RETHROW() - #endif BOOST_AUTO_TEST_SUITE_END() From 0aaf9a09c0205ad9733b77fe4c8f25fd00548b55 Mon Sep 17 00:00:00 2001 From: georgiypetrov Date: Thu, 5 Nov 2020 18:17:38 +0300 Subject: [PATCH 5/5] support sdk v1.4.0 --- 3rdparty/sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/sdk b/3rdparty/sdk index 0679c25..3f1203d 160000 --- a/3rdparty/sdk +++ b/3rdparty/sdk @@ -1 +1 @@ -Subproject commit 0679c25eddff30f09b210fea73230df1bd201591 +Subproject commit 3f1203d616742d91e00a37e34fb94ad8493df262