From 39b6bfd85e88eb0cee58f34b4018425a00c3c7c1 Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Mon, 14 Nov 2016 20:18:44 +0100 Subject: [PATCH] fixing problem : tournament never ends if "bye" matches present adding tournaments' prize_pool to total balances --- libraries/chain/tournament_object.cpp | 97 ++++++++++++++++++++++++++- tests/common/database_fixture.cpp | 7 ++ 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index ef4252fb..bc7130c1 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -179,6 +179,35 @@ namespace graphene { namespace chain { event.db.modify(tournament_details_obj, [&](tournament_details_object& tournament_details_obj){ tournament_details_obj.matches = matches; }); + + // OLEK + for (unsigned i = 0; i < num_matches_in_first_round; ++i) + { + const match_object& match = matches[i](event.db); + if (match.players.size() == 1) // is bye + { + unsigned tournament_num_matches = tournament_details_obj.matches.size(); + unsigned next_round_match_index = (i + tournament_num_matches + 1) / 2; + assert(next_round_match_index < tournament_num_matches); + const match_object& next_round_match = tournament_details_obj.matches[next_round_match_index](event.db); + event.db.modify(next_round_match, [&](match_object& next_match) { + next_match.players.emplace_back(match.players[0]); + if (next_match.players.size() > 1) // bye + bye + next_match.on_initiate_match(event.db); + + }); + } + } + + // OLEK + wdump((tournament_details_obj.matches[tournament_details_obj.matches.size() - 1])); + + for( match_id_type mid : tournament_details_obj.matches ) + { + wdump((mid(event.db))); + } + + } void on_entry(const match_completed& event, tournament_state_machine_& fsm) { @@ -213,15 +242,40 @@ namespace graphene { namespace chain { assert(event.match.match_winners.size() <= 1); event.db.modify(next_round_match, [&](match_object& next_match_obj) { - if (!event.match.match_winners.empty()) // if there is a winner + + // OLEK + wdump((event.match.get_state())); + wdump((event.match)); + wdump((other_match.get_state())); + wdump((other_match)); + + if (!event.match.match_winners.empty()) // if there is a winner { if (winner_index_in_next_match == 0) next_match_obj.players.insert(next_match_obj.players.begin(), *event.match.match_winners.begin()); else next_match_obj.players.push_back(*event.match.match_winners.begin()); } - if (other_match.get_state() == match_state::match_complete) + + //if (other_match.get_state() == match_state::match_complete) + // OLEK + if (!other_match.match_winners.empty()) + { +// // if other match was buy +// if (other_match.games.size() == 0 /*&& next_match_obj.players.size() < 2*/) +// { +// if (winner_index_in_next_match != 0) +// next_match_obj.players.insert(next_match_obj.players.begin(), *other_match.match_winners.begin()); +// else +// next_match_obj.players.push_back(*other_match.match_winners.begin()); +// } + // OLEK + wdump((next_match_obj.get_state())); + wdump((next_match_obj)); + next_match_obj.on_initiate_match(event.db); + } + }); } }; @@ -296,9 +350,45 @@ namespace graphene { namespace chain { fc_ilog(fc::logger::get("tournament"), "In was_final_match guard, returning ${value}", ("value", event.match.id == tournament_details_obj.matches[tournament_details_obj.matches.size()])); + + // OLEK + wdump((event.match.id)); + wdump((tournament_details_obj.matches[tournament_details_obj.matches.size() - 1])); + + for( match_id_type mid : tournament_details_obj.matches ) + { + wdump((mid(event.db))); + } + return event.match.id == tournament_details_obj.matches[tournament_details_obj.matches.size() - 1]; } - + +#if 0 + // OLEK + bool was_buy_match(const match_completed& event) + { + const tournament_details_object& tournament_details_obj = tournament_obj->tournament_details_id(event.db); + fc_ilog(fc::logger::get("tournament"), + "In was_buy_match guard, returning ${value}", + ("value", event.match.id == tournament_details_obj.matches[tournament_details_obj.matches.size()])); + + // OLEK + wdump((event.match.id)); + wdump((event.match)); + + /* + wdump((tournament_details_obj.matches[tournament_details_obj.matches.size() - 1])); + + for( match_id_type mid : tournament_details_obj.matches ) + { + wdump((mid(event.db))); + } + + return event.match.id == tournament_details_obj.matches[tournament_details_obj.matches.size() - 1]; + */ + return true; + } +#endif void register_player(const player_registered& event) { fc_ilog(fc::logger::get("tournament"), @@ -326,6 +416,7 @@ namespace graphene { namespace chain { _row < awaiting_start, start_time_arrived, in_progress >, // +---------------------------+-----------------------------+----------------------------+---------------------+----------------------+ _row < in_progress, match_completed, in_progress >, + //g_row < in_progress, match_completed, in_progress, &x::was_buy_match >, g_row < in_progress, match_completed, concluded, &x::was_final_match > // +---------------------------+-----------------------------+----------------------------+---------------------+----------------------+ > {}; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 0f717ecd..1bd48bc6 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -154,11 +155,17 @@ void database_fixture::verify_asset_supplies( const database& db ) const simple_index& statistics_index = db.get_index_type>(); const auto& balance_index = db.get_index_type().indices(); const auto& settle_index = db.get_index_type().indices(); + const auto& tournaments_index = db.get_index_type().indices(); + map total_balances; map total_debts; share_type core_in_orders; share_type reported_core_in_orders; + for( const tournament_object& t : tournaments_index ) + if (t.get_state() != tournament_state::concluded) + total_balances[t.options.buy_in.asset_id] += t.prize_pool; + for( const account_balance_object& b : balance_index ) total_balances[b.asset_type] += b.balance; for( const force_settlement_object& s : settle_index )