-
Notifications
You must be signed in to change notification settings - Fork 0
Introduction
This page explains the universal conventions related to creating the agent. Some other essential things are explained in other pages related to different approaches preferred by the user.
The project must be a console application and reference the mazharenko.AoCAgent package
dotnet new console -n aoc
dotnet add aoc package mazharenko.AocAgentDefine day classes named like DayXX. Don't forget the partial keyword. Provide examples and implementation.
partial class Day01
{
internal partial class Part1
{
}
internal partial class Part2
{
}
}A lot of internal staff will be generated now to implement the agent's functionality. Namely, an interface, a base class and a class for examples. At this moment the complier will require to implement the string Solve(string input) methods from the interface.
partial class Day01
{
internal partial class Part1
{
public string Solve(string input)
{
throw new NotImplementedException();
}
}
internal partial class Part2
{
public string Solve(string input)
{
throw new NotImplementedException();
}
}
}Strongly typed inputs and results are supported. The "implemented" Solve method can be changed according to the desired types.
partial class Day01
{
internal partial class Part1
{
public int Solve(int[] input)
{
throw new NotImplementedException();
}
}
internal partial class Part2 { ... }
}A lot of internal staff will be regenerated now to reflect the desired types, so the compiler is going to stop complaining shortly. However, for non-string inputs it will now require to implement the T Parse(string input) method.
partial class Day01
{
internal partial class Part1
{
public int[] Parse(string input)
{
throw new NotImplementedException();
}
public int Solve(int[] input)
{
throw new NotImplementedException();
}
}
internal partial class Part2 { ... }
}For the result's type, there still must be the way to convert it to a string. By default, its ToString method will be called. This can be overridden:
partial class Day01
{
internal partial class Part1
{
...
public override string Format(int res)
{
return base.Format(res);
}
...
}
...
}A few questions must be answered before moving on. Depending on one's preferences, further actions might differ.
-
Do you want the library to generate the Entry point for you?
An agent is a console application. Its entry point is supposed to call all the running logic. The entry point can be generated automatically or written manually.
-
Do you follow the repo-per-year scheme or have a single repository for all the Advent of Code events?
How days are discovered and associated with years needs a bit more attention for the latter.
Follow the link which answers these question best.
Entry point generation, Single year in project
Entry point generation, Multiple years in project