From b2702d1417c9b89ad48e7fe78711f46d03a61162 Mon Sep 17 00:00:00 2001 From: Thomas Beierlein Date: Wed, 12 Apr 2023 12:16:28 +0200 Subject: [PATCH 1/4] rework scoring rules (see issue #178) --- src/score.c | 34 ++++++++++++++++++++++++---------- test/test_score.c | 4 ++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/score.c b/src/score.c index eedc7fa79..6bb6e69a5 100644 --- a/src/score.c +++ b/src/score.c @@ -154,6 +154,12 @@ int scoreByMode(struct qso_t *qso) { points = x; \ } while(0); +/* return x points if set */ +#define RETURN_IF_SET(x) do { \ + if (x >= 0) \ + return x; \ + } while(0); + int scoreByContinentOrCountry(struct qso_t *qso) { int points = 0; @@ -184,17 +190,25 @@ int scoreByContinentOrCountry(struct qso_t *qso) { // default if (ctyinfo->dxcc_ctynr == my.countrynr) { - points = 0; - USE_IF_SET(my_cont_points); - USE_IF_SET(my_country_points); - } else if (inCountryList) { - USE_IF_SET(countrylist_points); - } else if (strcmp(ctyinfo->continent, my.continent) == 0) { - USE_IF_SET(my_cont_points); - } else - USE_IF_SET(dx_cont_points); + RETURN_IF_SET(my_country_points); + } - return points; + if (inCountryList) { + RETURN_IF_SET(countrylist_points); + } + + if (strcmp(ctyinfo->continent, my.continent) == 0) { + RETURN_IF_SET(my_cont_points); + } + + if (is_in_continentlist(ctyinfo->continent)) { + RETURN_IF_SET(continentlist_points); + } + + if (strcmp(ctyinfo->continent, my.continent) != 0) { + RETURN_IF_SET(dx_cont_points); + } + return 0; } diff --git a/test/test_score.c b/test/test_score.c index 2131a7f80..8876ee37b 100644 --- a/test/test_score.c +++ b/test/test_score.c @@ -400,12 +400,12 @@ void test_scoreByCorC_InList(void **state) { * my own country , otherwise 0 ??? */ countrylist_points = 3; check_call_points("OE2BL", 3); - check_call_points("DL3XYZ", 0); + check_call_points("DL3XYZ", 3); check_call_points("K3XX", 3); my_cont_points = 2; check_call_points("OE2BL", 3); - check_call_points("DL3XYZ", 2); + check_call_points("DL3XYZ", 3); check_call_points("K3XX", 3); my_country_points = 1; From 2e896a8bd8336d5e67f31d1c1887b9258308d4f4 Mon Sep 17 00:00:00 2001 From: Thomas Beierlein Date: Fri, 14 Apr 2023 07:44:27 +0200 Subject: [PATCH 2/4] Drop USE_COUNTRYLIST_ONLY keyword Was used for control of point scoring. By leaving all point controlling keywords (besides COUNTRYLIST_POINTS) undefined the same result can be achieved. --- src/globalvars.h | 1 - src/main.c | 1 - src/parse_logcfg.c | 9 --------- src/score.c | 8 -------- test/data.c | 1 - test/test_addcall.c | 2 -- test/test_parse_logcfg.c | 13 ------------- test/test_score.c | 17 ----------------- tlf.1.in | 4 ---- 9 files changed, 56 deletions(-) diff --git a/src/globalvars.h b/src/globalvars.h index b033e5a33..c8b5ea75e 100644 --- a/src/globalvars.h +++ b/src/globalvars.h @@ -241,7 +241,6 @@ extern char fkey_header[60]; extern SCREEN *mainscreen; extern bool mult_side; -extern bool countrylist_only; extern bool mixedmode; extern bool qso_once; extern bool leading_zeros_serial; diff --git a/src/main.c b/src/main.c index 84ae17113..26e49f614 100644 --- a/src/main.c +++ b/src/main.c @@ -121,7 +121,6 @@ int my_country_points = -1; int my_cont_points = -1; int dx_cont_points = -1; char countrylist[255][6]; -bool countrylist_only = false; int countrylist_points = -1; char continent_multiplier_list[7][3]; // SA, NA, EU, AF, AS and OC int continentlist_points = -1; diff --git a/src/parse_logcfg.c b/src/parse_logcfg.c index 9481a01c6..96156d1c9 100644 --- a/src/parse_logcfg.c +++ b/src/parse_logcfg.c @@ -741,14 +741,6 @@ static int cfg_continentlist(const cfg_arg_t arg) { return PARSE_OK; } -static int cfg_country_list_only(const cfg_arg_t arg) { - countrylist_only = true; - if (mult_side) { - countrylist_only = false; - } - return PARSE_OK; -} - static int cfg_bandweight_points(const cfg_arg_t arg) { static char bwp_params_list[50] = ""; int bandindex = -1; @@ -1280,7 +1272,6 @@ static config_t logcfg_configs[] = { {"DX_&_SECTIONS", NO_PARAM, cfg_dx_n_sections}, {"COUNTRYLIST", NEED_PARAM, cfg_countrylist}, {"CONTINENTLIST", NEED_PARAM, cfg_continentlist}, - {"USE_COUNTRYLIST_ONLY", NO_PARAM, cfg_country_list_only}, {"SIDETONE_VOLUME", NEED_PARAM, cfg_sc_volume}, {"MFJ1278_KEYER", NEED_PARAM, cfg_mfj1278_keyer}, {"CHANGE_RST", OPTIONAL_PARAM, cfg_change_rst}, diff --git a/src/score.c b/src/score.c index 6bb6e69a5..8f8c4f640 100644 --- a/src/score.c +++ b/src/score.c @@ -166,14 +166,6 @@ int scoreByContinentOrCountry(struct qso_t *qso) { prefix_data *ctyinfo = getctyinfo(qso->call); bool inCountryList = is_in_countrylist(ctyinfo->dxcc_ctynr); - if (countrylist_only) { - points = 0; - if (inCountryList) - USE_IF_SET(countrylist_points); - - return points; - } - /* HA2OS mods */ if (continentlist_only) { points = 0; diff --git a/test/data.c b/test/data.c index 28a0c9761..b23b801ad 100644 --- a/test/data.c +++ b/test/data.c @@ -81,7 +81,6 @@ int my_country_points = -1; int my_cont_points = -1; int dx_cont_points = -1; char countrylist[255][6]; -bool countrylist_only = false; int countrylist_points = -1; char continent_multiplier_list[7][3]; // SA, NA, EU, AF, AS and OC int continentlist_points = -1; diff --git a/test/test_addcall.c b/test/test_addcall.c index 7187dc31d..2504ff076 100644 --- a/test/test_addcall.c +++ b/test/test_addcall.c @@ -59,8 +59,6 @@ int setup_default(void **state) { strcpy(countrylist[1], "CE"); strcpy(countrylist[2], ""); - countrylist_only = false; - strcpy(continent_multiplier_list[0], "EU"); strcpy(continent_multiplier_list[1], "NA"); strcpy(continent_multiplier_list[2], ""); diff --git a/test/test_parse_logcfg.c b/test/test_parse_logcfg.c index 871bb66b7..da2e8d97c 100644 --- a/test/test_parse_logcfg.c +++ b/test/test_parse_logcfg.c @@ -1151,19 +1151,6 @@ void test_countrylist_points(void **state) { assert_int_equal(countrylist_points, 4); } -void test_countrylist_only(void **state) { - int rc = call_parse_logcfg("USE_COUNTRYLIST_ONLY\n"); - assert_int_equal(rc, PARSE_OK); - assert_true(countrylist_only); -} - -void test_countrylist_only_mult_side(void **state) { - mult_side = true; - int rc = call_parse_logcfg("USE_COUNTRYLIST_ONLY\n"); - assert_int_equal(rc, PARSE_OK); - assert_false(countrylist_only); -} - void test_my_country_points(void **state) { int rc = call_parse_logcfg("MY_COUNTRY_POINTS=4\n"); assert_int_equal(rc, PARSE_OK); diff --git a/test/test_score.c b/test/test_score.c index 8876ee37b..eac32416f 100644 --- a/test/test_score.c +++ b/test/test_score.c @@ -71,7 +71,6 @@ int setup_default(void **state) { my_cont_points = -1; dx_cont_points = -1; - countrylist_only = false; countrylist_points = -1; strcpy(countrylist[0], ""); @@ -153,7 +152,6 @@ void test_wpx(void **state) { qso.bandindex = BANDINDEX_40; check_call_points("VE3ABC",4); - } @@ -183,7 +181,6 @@ void test_arrl_fd(void **state) { qso.mode = SSBMODE; check_points(1); - } @@ -307,20 +304,6 @@ void test_in_continentlist(void **state) { } -void test_scoreByCorC_countrylistOnly(void **state) { - countrylist_only = true; - check_call_points("LZ1AB", 0); - check_call_points("DL3XYZ", 0); - - init_countrylist(); - check_call_points("LZ1AB", 0); - check_call_points("DL3XYZ", 0); - - countrylist_points = 4; - check_call_points("LZ1AB", 0); - check_call_points("DL3XYZ", 4); -} - void test_scoreByCorC_continentlistOnly(void **state) { continentlist_only = true; /* empty list */ diff --git a/tlf.1.in b/tlf.1.in index f50b0b3c5..b3435c7af 100644 --- a/tlf.1.in +++ b/tlf.1.in @@ -2682,10 +2682,6 @@ instead. Points for countries in country list. . .TP -\fBUSE_COUNTRYLIST_ONLY\fR[=<\fION\fR|\fIOFF\fR>] -Score zero points for countries not in the list. -. -.TP \fBCOUNTRYLIST\fR=\fI"comma separated list of prefixes"\fR e.g. SM,LA,OZ,OH. . From 44458efe4d18feb4a8c2e956efd8b5241ab3de03 Mon Sep 17 00:00:00 2001 From: Thomas Beierlein Date: Fri, 14 Apr 2023 18:25:54 +0200 Subject: [PATCH 3/4] Drop continentlist_only from scoring * Do some further cleanup and * adapt test code --- src/score.c | 29 ++--------- test/test_score.c | 125 +++++++++++++++++----------------------------- 2 files changed, 50 insertions(+), 104 deletions(-) diff --git a/src/score.c b/src/score.c index 8f8c4f640..9c9278073 100644 --- a/src/score.c +++ b/src/score.c @@ -2,8 +2,7 @@ * Tlf - contest logging program for amateur radio operators * Copyright (C) 2001-2002-2003 Rein Couperus * 2013 Ervin Hegedus - * 2013-2015, 2020 - * Thomas Beierlein + * 2013-2023 Thomas Beierlein * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -98,7 +97,7 @@ bool exist_in_country_list() { } -/* HA2OS - check if continent is in CONTINENT_LIST from logcfg.dat */ +/* check if continent is in CONTINENT_LIST */ bool is_in_continentlist(char *continent) { int i = 0; @@ -112,8 +111,7 @@ bool is_in_continentlist(char *continent) { } -/* apply bandweight scoring * - * at the moment only LOWBAND_DOUBLES (<30m) can be active */ +/* apply bandweight scoring */ int apply_bandweight(int points, int bandindex) { if (lowband_point_mult && (bandindex < BANDINDEX_30)) @@ -148,11 +146,6 @@ int scoreByMode(struct qso_t *qso) { } } -/* Overwrite points with x if set */ -#define USE_IF_SET(x) do { \ - if (x >= 0) \ - points = x; \ - } while(0); /* return x points if set */ #define RETURN_IF_SET(x) do { \ @@ -162,25 +155,9 @@ int scoreByMode(struct qso_t *qso) { int scoreByContinentOrCountry(struct qso_t *qso) { - int points = 0; prefix_data *ctyinfo = getctyinfo(qso->call); bool inCountryList = is_in_countrylist(ctyinfo->dxcc_ctynr); - /* HA2OS mods */ - if (continentlist_only) { - points = 0; - // only continent list allowed - if (is_in_continentlist(ctyinfo->continent)) { - USE_IF_SET(continentlist_points); - // overwrite if own continent and my_cont_points set - if (strcmp(ctyinfo->continent, my.continent) == 0) { - USE_IF_SET(my_cont_points); - } - } - return points; - } - - // default if (ctyinfo->dxcc_ctynr == my.countrynr) { RETURN_IF_SET(my_country_points); } diff --git a/test/test_score.c b/test/test_score.c index eac32416f..f8a305fb6 100644 --- a/test/test_score.c +++ b/test/test_score.c @@ -22,7 +22,10 @@ // OBJECT ../src/setcontest.o // OBJECT ../src/utils.o +/* dummy functions */ void checkexchange(struct qso_t *qso, bool interactive) {} +void clear_display() {} + char *calc_continent(int zone); @@ -37,16 +40,6 @@ struct qso_t qso = { }; g_free(qso.call); \ qso.call = NULL; }while(0) -void clear_display() {} - -#if 0 -void __wrap_qrb(char *x, char *y, char *u, char *v, double *a, double *b) { -} - -int __wrap_foc_score() { - return 0; -} -#endif int setup_default(void **state) { @@ -74,7 +67,6 @@ int setup_default(void **state) { countrylist_points = -1; strcpy(countrylist[0], ""); - continentlist_only = false; continentlist_points = -1; strcpy(continent_multiplier_list[0], ""); @@ -303,97 +295,74 @@ void test_in_continentlist(void **state) { assert_int_equal(is_in_continentlist("NA"), true); } - -void test_scoreByCorC_continentlistOnly(void **state) { - continentlist_only = true; - /* empty list */ +void test_scoreByCorC_no_points_set(void **state) { + /* empty_lists */ check_call_points("LZ1AB", 0); + check_call_points("XE2AAA", 0); + check_call_points("JA4BB", 0); + /* lists initialized */ + init_countrylist(); init_continentlist(); - - /* no list points given */ check_call_points("LZ1AB", 0); - check_call_points("JA4BB", 0); - - /* same, but my_cont_points set */ - my_cont_points = 1; - check_call_points("LZ1AB", 1); check_call_points("XE2AAA", 0); check_call_points("JA4BB", 0); - - /* my_cont_points, cont_list_points given */ - continentlist_points = 2; - check_call_points("LZ1AB", 1); - check_call_points("XE2AAA", 2); - check_call_points("JA4BB", 0); - - /* only cont_list_points given */ - my_cont_points = -1; - check_call_points("LZ1AB", 2); - check_call_points("XE2AAA", 2); - check_call_points("JA4BB", 0); } - -void test_scoreByCorC_continentlistOnly_ignoreDxContPoints(void **state) { - continentlist_only = true; +void test_scoreByCorC_dxPoints(void **state) { + dx_cont_points = 3; check_call_points("LZ1AB", 0); + check_call_points("JA4BB", 3); +} - dx_cont_points = 2; +void test_scoreByCorC_continentlistPoints(void **state) { init_continentlist(); - check_call_points("LZ1AB", 0); - check_call_points("XE2AAA", 0); -} + continentlist_points = 4; + check_call_points("LZ1AB", 4); + check_call_points("XE2AAA", 4); + check_call_points("JA4BB", 0); +} -void test_scoreByCorC_notInList(void **state) { +void test_scoreByCorC_myContinentPoints(void **state) { + my_cont_points = 2; - /* my_country/cont_points and dx_cont_points not set */ - check_call_points("DL3XYZ", 0); - check_call_points("LZ1AB", 0); - check_call_points("K3XX", 0); + check_call_points("LZ1AB", 2); + check_call_points("XE2AAA", 0); + check_call_points("JA4BB", 0); +} - dx_cont_points = 4; - check_call_points("DL3XYZ", 0); - check_call_points("LZ1AB", 0); - check_call_points("K3XX", 4); +void test_scoreByCorC_countrylistPoints(void **state) { + init_countrylist(); + countrylist_points = 3; - my_cont_points = 3; + check_call_points("OE2ABC", 3); check_call_points("DL3XYZ", 3); - check_call_points("LZ1AB", 3); - check_call_points("K3XX", 4); + check_call_points("JA4BB", 0); +} +void test_scoreByCorC_myCountryPoints(void **state) { my_country_points = 1; + + check_call_points("OE2ABC", 0); check_call_points("DL3XYZ", 1); - check_call_points("LZ1AB", 3); - check_call_points("K3XX", 4); } -void test_scoreByCorC_InList(void **state) { +void test_scoreByCorC_precedence(void **state) { init_countrylist(); - - /* countrylist_points, my_country_points and my_cont_points - * not set -> 0 points for all */ - check_call_points("OE2BL", 0); - check_call_points("DL3XYZ", 0); - check_call_points("K3XX", 0); - - /* only countrylist_points set -> use my_country/cont_points for - * my own country , otherwise 0 ??? */ - countrylist_points = 3; - check_call_points("OE2BL", 3); - check_call_points("DL3XYZ", 3); - check_call_points("K3XX", 3); - - my_cont_points = 2; - check_call_points("OE2BL", 3); - check_call_points("DL3XYZ", 3); - check_call_points("K3XX", 3); + init_continentlist(); my_country_points = 1; - check_call_points("OE2BL", 3); - check_call_points("DL3XYZ", 1); - check_call_points("K3XX", 3); + countrylist_points = 2; + my_cont_points = 3; + continentlist_points = 4; + dx_cont_points = 5; + + check_call_points("DL3XYZ", 1); /* my country */ + check_call_points("OE2ABC", 2); /* in countrylist */ + check_call_points("K3XX", 2); /* same as above */ + check_call_points("LZ1AB", 3); /* own continent */ + check_call_points("XE2AAA", 4); /* in continentlist */ + check_call_points("JA4BB", 5); /* other continent */ } - From 54fc1a7dc053292f4bb6ba636c3fef4490d13a5b Mon Sep 17 00:00:00 2001 From: Thomas Beierlein Date: Sun, 16 Apr 2023 18:31:17 +0200 Subject: [PATCH 4/4] Drop superfluous variable --- src/globalvars.h | 1 - src/main.c | 1 - src/parse_logcfg.c | 3 --- test/data.c | 1 - test/test_parse_logcfg.c | 5 ----- 5 files changed, 11 deletions(-) diff --git a/src/globalvars.h b/src/globalvars.h index c8b5ea75e..7928acb44 100644 --- a/src/globalvars.h +++ b/src/globalvars.h @@ -240,7 +240,6 @@ extern char fkey_header[60]; extern SCREEN *mainscreen; -extern bool mult_side; extern bool mixedmode; extern bool qso_once; extern bool leading_zeros_serial; diff --git a/src/main.c b/src/main.c index 26e49f614..b603c5cba 100644 --- a/src/main.c +++ b/src/main.c @@ -126,7 +126,6 @@ char continent_multiplier_list[7][3]; // SA, NA, EU, AF, AS and OC int continentlist_points = -1; bool continentlist_only = false; int exclude_multilist_type = EXCLUDE_NONE; -bool mult_side = false; /* end LZ3NY mods */ bool portable_x2 = false; diff --git a/src/parse_logcfg.c b/src/parse_logcfg.c index 96156d1c9..b64823401 100644 --- a/src/parse_logcfg.c +++ b/src/parse_logcfg.c @@ -648,9 +648,6 @@ static int cfg_countrylist(const cfg_arg_t arg) { } } - /* on which multiplier side of the rules we are */ - getpx(my.call); - mult_side = exist_in_country_list(); setcontest(whichcontest); return PARSE_OK; diff --git a/test/data.c b/test/data.c index b23b801ad..818c426b7 100644 --- a/test/data.c +++ b/test/data.c @@ -86,7 +86,6 @@ char continent_multiplier_list[7][3]; // SA, NA, EU, AF, AS and OC int continentlist_points = -1; bool continentlist_only = false; int exclude_multilist_type = EXCLUDE_NONE; -bool mult_side = false; /* end LZ3NY mods */ bool portable_x2 = false; diff --git a/test/test_parse_logcfg.c b/test/test_parse_logcfg.c index da2e8d97c..744e158ee 100644 --- a/test/test_parse_logcfg.c +++ b/test/test_parse_logcfg.c @@ -178,7 +178,6 @@ int setup_default(void **state) { nodes = 0; xplanet = MARKER_NONE; dx_arrlsections = false; - mult_side = false; countrylist_points = -1; my_country_points = -1; my_cont_points = -1; @@ -1091,7 +1090,6 @@ void test_countrylist(void **state) { assert_string_equal(countrylist[1], "GM"); assert_string_equal(countrylist[2], "F"); assert_string_equal(countrylist[3], ""); - assert_true(mult_side); assert_int_equal(CONTEST_IS(UNKNOWN), 1); } @@ -1109,7 +1107,6 @@ void test_countrylist_long(void **state) { assert_string_equal(countrylist[128], "VU"); assert_string_equal(countrylist[160], "ZS8"); assert_string_equal(countrylist[161], ""); - assert_false(mult_side); assert_int_equal(CONTEST_IS(UNKNOWN), 1); } @@ -1121,7 +1118,6 @@ void test_countrylist_from_file(void **state) { assert_string_equal(countrylist[0], "EA"); assert_string_equal(countrylist[1], "CT"); assert_string_equal(countrylist[2], ""); - assert_true(mult_side); assert_int_equal(CONTEST_IS(UNKNOWN), 1); } @@ -1141,7 +1137,6 @@ void test_countrylist_from_file_long(void **state) { assert_string_equal(countrylist[128], "VU"); assert_string_equal(countrylist[160], "ZS8"); assert_string_equal(countrylist[161], ""); - assert_true(mult_side); assert_int_equal(CONTEST_IS(UNKNOWN), 1); }