Show the boxes N1MM shows for each contest

The entry window had a fixed set of boxes with a Name and Comment box beside
the exchange. N1MM lays out one row of boxes per contest and nothing else, so
this does the same: general logging keeps Name and Comment, and a contest gets
the boxes it exchanges.

Two new members on `Contest` carry the cases where the boxes and the log
columns are not the same list:

- `FromExchange1` spreads what was typed in one box across the log columns.
  Where the other station sends a serial or a district code depending on where
  it is, N1MM gives it one box and sorts the value into the number, section or
  zone column from there, so the score and the Cabrillo file read it from the
  same column N1MM does.
- `LogFieldsFor` gives the log window its own column list. Sweepstakes takes
  the whole exchange in one box and logs it in four columns; `SweepstakesExchange`
  parses `72 A 74 SCV` in any order, reading from the last word back as N1MM
  does.

The sent serial is now marked as not required and space steps over it along
with the two report boxes, because nobody types the number going out.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015NZkFxHde1iifAQemFTHxf
This commit is contained in:
2026-09-09 20:12:37 +00:00
co-authored by Claude Opus 5
parent 6e24e00ec8
commit bae40bb04e
47 changed files with 702 additions and 277 deletions
@@ -0,0 +1,109 @@
using Nonemm.Contests.Multipliers;
namespace Nonemm.Contests.Rules;
/// The four parts of a Sweepstakes exchange, read out of the one box the
/// operator types them into: `72 A 74 SCV`, or `72A 74SCV`, or any other order.
/// N1MM reads the same box the same way, from the last word back, so a part
/// typed again replaces nothing that was already found.
public sealed record SweepstakesExchange(int Number, string Precedence, int Check, string Section)
{
private const int HighestNumber = 10000;
private const int HighestCheck = 99;
private static readonly IReadOnlySet<string> Precedences =
new HashSet<string> { "A", "B", "Q", "U", "M", "S" };
public static SweepstakesExchange Parse(string typed)
{
string rest = typed.Trim().ToUpperInvariant();
string number = "";
string check = "";
string section = "";
string precedence = "";
bool foundSection = false;
bool foundNumber = false;
while (rest.Trim().Length > 0)
{
string word = LastWord(rest);
rest = AllButLastWord(rest);
string before = LastWord(rest);
// "72 A" and "74 SCV" are one part typed with a space in it
if ((word.Length == 1 && char.IsAsciiLetter(word[0]) && IsNumber(before))
|| (word.Length is >= 2 and < 4 && word.All(char.IsAsciiLetter) && IsNumber(before)))
{
word = before + word;
rest = AllButLastWord(rest);
}
if (word.Length > 1 && !IsNumber(word[^1..]) && IsNumber(word[..^1]))
{
if (!foundNumber)
{
number = word[..^1];
foundNumber = true;
}
precedence = precedence.Length == 0 ? PrecedenceFrom(word[^1..]) : precedence;
}
else if (word.Length > 3 && !IsNumber(word) && IsNumber(word[..2]) && word[2..].All(char.IsAsciiLetter))
{
check = check.Length == 0 ? word[..2] : check;
(section, foundSection) = SectionFrom(word[2..], section, foundSection);
}
else if (word.Length > 2 && !IsNumber(word) && IsNumber(word[..1]) && word[1..].All(char.IsAsciiLetter))
{
check = check.Length == 0 ? word[..1] : check;
(section, foundSection) = SectionFrom(word[1..], section, foundSection);
}
else if (IsNumber(word) && ((word.Length == 1 && word != "0") || word.Length > 2))
{
number = foundNumber ? number : word;
foundNumber = true;
}
else if (IsNumber(word) && check.Length > 0 && !foundNumber)
{
number = number.Length == 0 ? word : number;
}
else if (IsNumber(word))
{
check = check.Length == 0 ? word : check;
}
else if (word.Length > 1)
{
(section, foundSection) = SectionFrom(word, section, foundSection);
}
else if (precedence.Length == 0)
{
precedence = PrecedenceFrom(word);
}
}
return new SweepstakesExchange(
Math.Min(Value(number), HighestNumber),
precedence,
Math.Min(Value(check), HighestCheck),
section);
}
private static (string Section, bool Found) SectionFrom(string word, string section, bool found) =>
found || !ArrlSections.IsSection(word) ? (section, found) : (word, true);
private static string PrecedenceFrom(string word) => Precedences.Contains(word) ? word : "";
private static string LastWord(string text)
{
string trimmed = text.Trim();
int space = trimmed.LastIndexOf(' ');
return space < 0 ? trimmed : trimmed[(space + 1)..];
}
private static string AllButLastWord(string text)
{
string trimmed = text.Trim();
int space = trimmed.LastIndexOf(' ');
return space < 0 ? "" : trimmed[..space];
}
private static bool IsNumber(string text) => text.Length > 0 && text.All(char.IsAsciiDigit);
private static int Value(string text) => int.TryParse(text, out int number) ? number : 0;
}