Class SeedSearch
examples/
directory in the repository. In some cases,
the starting hand may not be enough to narrow the search down to a single seed, so multiple
possible AI deck's and permutations will need to be considered, or the search can be rebuilt and
rerun after the player draws another card.
Use the builder to configure the search and then call search()
to perform the search. The search is
parallelized and will use as many threads as the system has available. The search space is
defined by the start and end values, and the initial seed is used as the starting point for the
search. The search space is defined by the number of calls to rand()
to consider. The
default search space is 5,000,000, but this can be changed with the SeedSearch.Builder.withSpace(int, int)
method. The search space is divided evenly among the available threads, so the more threads
available, the faster the search will complete. The search can be cancelled at any time by calling
cancel()
. Note that even with modern processors and parallelization, the search can take
a few seconds to complete with the default search space, and longer with larger search spaces.
This class is NOT thread-safe. The class will parallelize its own search onto a worker pool of threads in a thread-safe manner, but any external parallelization is not safe. Each search should be performed with a new instance of this class and a new builder.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
How manyrand()
calls to consider when searching for a seed. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancels the search.int
Gets the ending value of the seed space to explore, as set by the builder.int
Gets the length of the search space, i.e., the number of seeds that will be explored.int
Gets the starting value of the seed space to explore, as set by the builder.search()
Performs the search.
-
Field Details
-
DEFAULT_SEARCH_SPACE
public static final int DEFAULT_SEARCH_SPACEHow manyrand()
calls to consider when searching for a seed.- See Also:
-
-
Method Details
-
getSpaceStart
public int getSpaceStart()Gets the starting value of the seed space to explore, as set by the builder.- Returns:
- the start of the seed space to explore
-
getSpaceEnd
public int getSpaceEnd()Gets the ending value of the seed space to explore, as set by the builder.- Returns:
- the end of the seed space to explore
-
search
Performs the search.- Returns:
- a set of seeds that produce the drawn cards specified in the builder
-
cancel
public void cancel()Cancels the search. -
getSpaceLength
public int getSpaceLength()Gets the length of the search space, i.e., the number of seeds that will be explored.- Returns:
- the length of the search space
-