Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions base/ModeManagerDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ void ModeManagerDlg::on_comboBox_mode_currentIndexChanged(int i)
m_pUi->lineEdit_timeOverrides->setText(QString());
}

if (!mode.scorePointsOverrides.empty())
{
m_pUi->checkBox_scorePointsOverrides->setChecked(true);
m_pUi->lineEdit_scorePointsOverrides->setText(mode.GetScorePointsOverridesString());
}
else
{
m_pUi->checkBox_scorePointsOverrides->setChecked(false);
m_pUi->lineEdit_scorePointsOverrides->setText(QString());
}

auto rulesIndex = m_pUi->comboBox_rules->findText(mode.rules);

if (rulesIndex != -1)
Expand Down Expand Up @@ -130,6 +141,16 @@ void ModeManagerDlg::on_checkBox_timeOverrides_toggled(bool checked)
m_pUi->lineEdit_timeOverrides->setEnabled(checked);
}

void ModeManagerDlg::on_checkBox_scorePointsOverrides_toggled(bool checked)
{
if (!has_Mode())
{
return;
}

m_pUi->lineEdit_scorePointsOverrides->setEnabled(checked);
}

void ModeManagerDlg::on_checkBox_doubleWeights_toggled(bool checked)
{
if (!has_Mode())
Expand Down Expand Up @@ -282,6 +303,25 @@ void ModeManagerDlg::on_lineEdit_timeOverrides_textChanged(const QString& s)
}
}

void ModeManagerDlg::on_lineEdit_scorePointsOverrides_textChanged(const QString& s)
{
if (!has_Mode())
{
return;
}

auto& mode = GetCurrentMode();

if (s.isEmpty() || TournamentMode::ExtractScorePointsOverrides(s, mode.scorePointsOverrides))
{
m_pUi->lineEdit_scorePointsOverrides->setStyleSheet("color : black;");
}
else
{
m_pUi->lineEdit_scorePointsOverrides->setStyleSheet("color : red;");
}
}

void ModeManagerDlg::update_fights_per_round(const TournamentMode& mode)
{
auto text = mode.nRounds > 1 ? QString("%1 fights total, %2 per round")
Expand Down
2 changes: 2 additions & 0 deletions base/ModeManagerDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private slots:
void on_comboBox_rules_currentIndexChanged(int);
// checkBoxes
void on_checkBox_timeOverrides_toggled(bool checked);
void on_checkBox_scorePointsOverrides_toggled(bool checked);
void on_checkBox_doubleWeights_toggled(bool checked);
void on_checkBox_allSubscoresCount_toggled(bool checked);
// buttons
Expand All @@ -50,6 +51,7 @@ private slots:
void on_lineEdit_title_textChanged(QString const& s);
void on_lineEdit_subtitle_textChanged(QString const& s);
void on_lineEdit_timeOverrides_textChanged(QString const& s);
void on_lineEdit_scorePointsOverrides_textChanged(QString const& s);

private:
void update_fights_per_round(Ipponboard::TournamentMode const& mode);
Expand Down
40 changes: 40 additions & 0 deletions base/ModeManagerDlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,45 @@ Note: the time must be specified in seconds alone</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_12">
<property name="toolTip">
<string></string>
</property>
<property name="text">
<string>Score Points</string>
</property>
</widget>
</item>
<item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="checkBox_scorePointsOverrides">
<property name="toolTip">
<string>Sub-scores have an override</string>
</property>
<property name="text">
<string>Sub-scores have an override</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_scorePointsOverrides">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>The overrides should be something like this:
"I:100;W:10;Y:1;Ha:1;S:1;Hi:0;L:0"
(&lt;identifier&gt;:&lt;points&gt;;&lt;identifier&gt;...)</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -330,6 +369,7 @@ Note: the time must be specified in seconds alone</string>
<tabstop>spinBox_rounds</tabstop>
<tabstop>spinBox_fightTimeSeconds</tabstop>
<tabstop>lineEdit_timeOverrides</tabstop>
<tabstop>lineEdit_scorePointsOverrides</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
Expand Down
19 changes: 8 additions & 11 deletions core/Fight.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ struct SimpleFighter

class Fight
{
private:
enum
{
eScore_Ippon = 10,
eScore_Wazaari = 7,
eScore_Yuko = 5,
eScore_Hantai = 1,
eScore_Shido = 1,
eScore_Hikewake = 0,
eScore_Lost = 0
};
public:
static constexpr int eScore_Ippon = 10;
static constexpr int eScore_Wazaari = 7;
static constexpr int eScore_Yuko = 5;
static constexpr int eScore_Hantai = 1;
static constexpr int eScore_Shido = 1;
static constexpr int eScore_Hikewake = 0;
static constexpr int eScore_Lost = 0;

bool _isGoldenScore { false };

Expand Down
1 change: 1 addition & 0 deletions test/TestData/IpponboardAutosaveJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ inline constexpr const char* IpponboardAutosaveJson = R"IPPON(
"TournamentMode": {
"FightTimeInSeconds": 240,
"FightTimeOverrides": "",
"ScorePointsOverrides": "",
"ID": "fd2a6412-dd1a-4e4c-b257-197feb8799b1",
"Options": "",
"Rounds": 2,
Expand Down
8 changes: 8 additions & 0 deletions test/TestData/TournamentModes-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ Rounds=1
Template=TournamentModes-test.ini
FightTimeInSeconds=120
FightTimeOverrides="U12:120;U15:180;U18:240"

[with_scorepoints_overrides]
Title=With scorepoints overrides
Weights="U12 -28;U12 -32;U12 -36;U12 -40;U12 -44;U15 -37;U15 -43;U15 -50;U15 -60;U15 +60;U18 -50;U18 -60;U18 -73;U18 +73"
Rounds=1
Template=TournamentModes-test.ini
FightTimeInSeconds=120
ScorePointsOverrides=I:100;W:10;Y:1;Ha:1;S:1;Hi:0;L:0
34 changes: 17 additions & 17 deletions test/TestFight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,29 @@ TEST_CASE("[Fight] Validate score points (subscore)")

Fight f1 { emptyScore, shidoScore };
f1.rules = std::make_shared<Ipponboard::Rules2013>();
REQUIRE(f1.GetScorePoints(first) == 1);
REQUIRE(f1.GetScorePoints(second) == 0);
REQUIRE(f1.GetScorePoints(first) == Ipponboard::Fight::eScore_Shido);
REQUIRE(f1.GetScorePoints(second) == Ipponboard::Fight::eScore_Lost);

Fight f2 { yukoScore, yukoWithShidoScore };
f2.rules = std::make_shared<Ipponboard::Rules2013>();
REQUIRE(f2.GetScorePoints(first) == 1);
REQUIRE(f2.GetScorePoints(second) == 0);
REQUIRE(f2.GetScorePoints(first) == Ipponboard::Fight::eScore_Shido);
REQUIRE(f2.GetScorePoints(second) == Ipponboard::Fight::eScore_Lost);

// Hikewake
Fight f3 { twoYukoScore, twoYukoScore };
f3.rules = std::make_shared<Ipponboard::Rules2013>();
REQUIRE(f3.GetScorePoints(first) == 0);
REQUIRE(f3.GetScorePoints(second) == 0);
REQUIRE(f3.GetScorePoints(first) == Ipponboard::Fight::eScore_Hikewake);
REQUIRE(f3.GetScorePoints(second) == Ipponboard::Fight::eScore_Hikewake);

Fight f4 { yukoScore, twoYukoScore };
f4.rules = std::make_shared<Ipponboard::Rules2013>();
REQUIRE(f4.GetScorePoints(first) == 0);
REQUIRE(f4.GetScorePoints(second) == 5);
REQUIRE(f4.GetScorePoints(first) == Ipponboard::Fight::eScore_Lost);
REQUIRE(f4.GetScorePoints(second) == 1);

Fight f5 { twoYukoWithShidoScore, twoYukoWithTwoShidoScore };
f5.rules = std::make_shared<Ipponboard::Rules2013>();
REQUIRE(f5.GetScorePoints(first) == 1);
REQUIRE(f5.GetScorePoints(second) == 0);
REQUIRE(f5.GetScorePoints(first) == Ipponboard::Fight::eScore_Shido);
REQUIRE(f5.GetScorePoints(second) == Ipponboard::Fight::eScore_Lost);
}

TEST_CASE("[Fight] TimeRemaining accounts for golden score")
Expand Down Expand Up @@ -130,19 +130,19 @@ TEST_CASE("[Fight] rules2017: score points will return 1 for shido won in golden
Fight f;
f.rules = std::make_shared<Ipponboard::Rules2017>();

REQUIRE(f.GetScorePoints(FighterEnum::First) == 0);
REQUIRE(f.GetScorePoints(FighterEnum::First) == Ipponboard::Fight::eScore_Hikewake);

f.GetScore(FighterEnum::First).Add(Point::Shido);
REQUIRE(f.GetScorePoints(FighterEnum::First) == 0);
REQUIRE(f.GetScorePoints(FighterEnum::Second) == 0);
REQUIRE(f.GetScorePoints(FighterEnum::First) == Ipponboard::Fight::eScore_Hikewake);
REQUIRE(f.GetScorePoints(FighterEnum::Second) == Ipponboard::Fight::eScore_Hikewake);

f.GetScore(FighterEnum::First).Add(Point::Shido);
REQUIRE(f.GetScorePoints(FighterEnum::First) == 0);
REQUIRE(f.GetScorePoints(FighterEnum::Second) == 0);
REQUIRE(f.GetScorePoints(FighterEnum::First) == Ipponboard::Fight::eScore_Hikewake);
REQUIRE(f.GetScorePoints(FighterEnum::Second) == Ipponboard::Fight::eScore_Hikewake);

f.SetGoldenScore(true);
REQUIRE(f.GetScorePoints(FighterEnum::First) == 0);
REQUIRE(f.GetScorePoints(FighterEnum::Second) == 1);
REQUIRE(f.GetScorePoints(FighterEnum::First) == Ipponboard::Fight::eScore_Lost);
REQUIRE(f.GetScorePoints(FighterEnum::Second) == Ipponboard::Fight::eScore_Shido);
}

TEST_CASE("[Fight] rules2017: no one has won if points are equal and shidos aren't in golden score")
Expand Down
5 changes: 5 additions & 0 deletions test/TestTournamentMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ TEST_CASE("[TournamentMode] Test_parse_current_group")
<< "basic"
<< "with_weights_doubled"
<< "with_time_overrides"
<< "with_scorepoints_overrides"
<< "template_not_found"
<< "no_title"
<< "no_weights"
Expand All @@ -60,6 +61,10 @@ TEST_CASE("[TournamentMode] Test_parse_current_group")
INFO(errorMsg.toStdString());
REQUIRE(success);

success = IpponboardTest::parse_group(config, "with_scorepoints_overrides", errorMsg);
INFO(errorMsg.toStdString());
REQUIRE(success);

success = IpponboardTest::parse_group(config, "template_not_found", errorMsg);
INFO(errorMsg.toStdString());
REQUIRE_FALSE(success);
Expand Down
50 changes: 49 additions & 1 deletion test/TestTournamentSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QJsonObject>
#include <QString>
#include <QTemporaryDir>
#include <iostream>

using namespace Ipponboard;
using namespace Ipponboard::TournamentSerialization;
Expand Down Expand Up @@ -45,6 +46,7 @@ TournamentSaveData MakeSampleData()
mode.nRounds = 2;
mode.fightTimeInSeconds = 180;
mode.fightTimeOverrides = { { "73", 120 } };
mode.scorePointsOverrides = { { "73", 100 } };// WAS MUSS DA HIN???
mode.rules = "Default";
mode.options = "SubscoreEnabled";
data.mode = mode;
Expand Down Expand Up @@ -129,7 +131,53 @@ TEST_CASE("Conversion to and from json results in same data")
outJson.remove('\n');
outJson.remove(' ');
REQUIRE_FALSE(outJson.isEmpty());
REQUIRE(jsonStr == outJson);


// 🔍 DEBUG OUTPUT
if (jsonStr != outJson)
{
std::cout << "=== INPUT JSON ===\n";
std::cout << jsonStr.toStdString() << "\n";

std::cout << "\n=== OUTPUT JSON ===\n";
std::cout << outJson.toStdString() << "\n";

// 🔍 erste Abweichung finden
std::string a = jsonStr.toStdString();
std::string b = outJson.toStdString();

size_t minLen = std::min(a.size(), b.size());
for (size_t i = 0; i < minLen; ++i)
{
if (a[i] != b[i])
{
std::cout << "\n=== FIRST DIFF ===\n";
std::cout << "Index: " << i << "\n";
std::cout << "Input: '" << a[i] << "'\n";
std::cout << "Output: '" << b[i] << "'\n";

// Kontext anzeigen
size_t start = (i > 20) ? i - 20 : 0;
size_t len = 40;

std::cout << "\nContext INPUT : "
<< a.substr(start, len) << "\n";
std::cout << "Context OUTPUT: "
<< b.substr(start, len) << "\n";

break;
}
}

std::cout << "\nLength INPUT : " << a.size() << "\n";
std::cout << "Length OUTPUT: " << b.size() << "\n";
}


QJsonDocument doc1 = QJsonDocument::fromJson(jsonStr.toUtf8());
QJsonDocument doc2 = QJsonDocument::fromJson(outJson.toUtf8());

REQUIRE(doc1 == doc2);
}

TEST_CASE("CreateFromJson round-trips tournament data")
Expand Down