Class SeedSearch

java.lang.Object
moe.maika.ygofm.gamedata.SeedSearch

public class SeedSearch extends Object
A utility to search for seeds that produce a given list of draws from the player's deck. An example application of this class is to find the seed that produces a given starting hand and then use that seed to generate the AI's deck and order of cards in the deck. This example application can be found in the 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
    Modifier and Type
    Class
    Description
    static class 
    A builder for SeedSearch instances.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    How many rand() calls to consider when searching for a seed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
    Performs the search.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_SEARCH_SPACE

      public static final int DEFAULT_SEARCH_SPACE
      How many rand() 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

      public Set<RNG> 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