Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scoring #390

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/globalvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ extern char fkey_header[60];
extern SCREEN *mainscreen;

extern bool mult_side;
dl1jbe marked this conversation as resolved.
Show resolved Hide resolved
extern bool countrylist_only;
extern bool mixedmode;
extern bool qso_once;
extern bool leading_zeros_serial;
Expand Down
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions src/parse_logcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand Down
59 changes: 21 additions & 38 deletions src/score.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Tlf - contest logging program for amateur radio operators
* Copyright (C) 2001-2002-2003 Rein Couperus <pa0rct@amsat.org>
* 2013 Ervin Hegedus <airween@gmail.com>
* 2013-2015, 2020
* Thomas Beierlein <tb@forth-ev.de>
* 2013-2023 Thomas Beierlein <tb@forth-ev.de>
*
* 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
Expand Down Expand Up @@ -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;

Expand All @@ -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))
Expand Down Expand Up @@ -148,53 +146,38 @@ int scoreByMode(struct qso_t *qso) {
}
}

/* Overwrite points with x if set */
#define USE_IF_SET(x) do { \

/* return x points if set */
#define RETURN_IF_SET(x) do { \
if (x >= 0) \
points = x; \
return x; \
} while(0);

int scoreByContinentOrCountry(struct qso_t *qso) {

int points = 0;
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);
if (ctyinfo->dxcc_ctynr == my.countrynr) {
RETURN_IF_SET(my_country_points);
}

return points;
if (inCountryList) {
RETURN_IF_SET(countrylist_points);
}

/* 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;
if (strcmp(ctyinfo->continent, my.continent) == 0) {
RETURN_IF_SET(my_cont_points);
}

// 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);
if (is_in_continentlist(ctyinfo->continent)) {
RETURN_IF_SET(continentlist_points);
}

return points;
if (strcmp(ctyinfo->continent, my.continent) != 0) {
RETURN_IF_SET(dx_cont_points);
}
return 0;
}


Expand Down
1 change: 0 additions & 1 deletion test/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions test/test_addcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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], "");
Expand Down
13 changes: 0 additions & 13 deletions test/test_parse_logcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
138 changes: 45 additions & 93 deletions test/test_score.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -71,11 +64,9 @@ int setup_default(void **state) {
my_cont_points = -1;
dx_cont_points = -1;

countrylist_only = false;
countrylist_points = -1;
strcpy(countrylist[0], "");

continentlist_only = false;
continentlist_points = -1;
strcpy(continent_multiplier_list[0], "");

Expand Down Expand Up @@ -153,7 +144,6 @@ void test_wpx(void **state) {

qso.bandindex = BANDINDEX_40;
check_call_points("VE3ABC",4);

}


Expand Down Expand Up @@ -183,7 +173,6 @@ void test_arrl_fd(void **state) {

qso.mode = SSBMODE;
check_points(1);

}


Expand Down Expand Up @@ -306,111 +295,74 @@ void test_in_continentlist(void **state) {
assert_int_equal(is_in_continentlist("NA"), true);
}


void test_scoreByCorC_countrylistOnly(void **state) {
countrylist_only = true;
void test_scoreByCorC_no_points_set(void **state) {
/* empty_lists */
check_call_points("LZ1AB", 0);
check_call_points("DL3XYZ", 0);
check_call_points("XE2AAA", 0);
check_call_points("JA4BB", 0);

/* lists initialized */
init_countrylist();
init_continentlist();
check_call_points("LZ1AB", 0);
check_call_points("DL3XYZ", 0);

countrylist_points = 4;
check_call_points("LZ1AB", 0);
check_call_points("DL3XYZ", 4);
check_call_points("XE2AAA", 0);
check_call_points("JA4BB", 0);
}

void test_scoreByCorC_continentlistOnly(void **state) {
continentlist_only = true;
/* empty list */
void test_scoreByCorC_dxPoints(void **state) {
dx_cont_points = 3;
check_call_points("LZ1AB", 0);
check_call_points("JA4BB", 3);
}

void test_scoreByCorC_continentlistPoints(void **state) {
init_continentlist();
continentlist_points = 4;

/* 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("LZ1AB", 4);
check_call_points("XE2AAA", 4);
check_call_points("JA4BB", 0);
}

void test_scoreByCorC_myContinentPoints(void **state) {
my_cont_points = 2;

void test_scoreByCorC_continentlistOnly_ignoreDxContPoints(void **state) {
continentlist_only = true;
check_call_points("LZ1AB", 0);

dx_cont_points = 2;
init_continentlist();
check_call_points("LZ1AB", 0);
check_call_points("LZ1AB", 2);
check_call_points("XE2AAA", 0);
check_call_points("JA4BB", 0);
}

void test_scoreByCorC_countrylistPoints(void **state) {
init_countrylist();
countrylist_points = 3;

void test_scoreByCorC_notInList(void **state) {

/* 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);

dx_cont_points = 4;
check_call_points("DL3XYZ", 0);
check_call_points("LZ1AB", 0);
check_call_points("K3XX", 4);

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", 0);
check_call_points("K3XX", 3);

my_cont_points = 2;
check_call_points("OE2BL", 3);
check_call_points("DL3XYZ", 2);
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 */
}

4 changes: 0 additions & 4 deletions tlf.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -2682,10 +2682,6 @@ instead.
Points for countries in country list.
.
.TP
Copy link
Member

@zcsahok zcsahok Apr 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth spending an own chapter to scoring. At least to have the basic logic documented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Points and multiplier scoring needs to be documented. I was undecided if we do it in man page or should use a separate document. As a start the keywords in man page should be sorted and grouped together.

\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.
.
Expand Down