Author Topic: Finding colonizable planets  (Read 1807 times)

Offline LordMike

  • **
  • Posts: 7
    • View Profile
Finding colonizable planets
« on: 16 June 2013, 17:01:58 »
Hi again,

Context: http://bugs.galaxytool.eu/view.php?id=590

While thinking about importing the Universe data and checking age without using too much memory, I realized the same solution could apply in this case.
Basically, do a query on all colonized planets in the search range, and then iterate them while checking coordinates. As the coordinates are in order, any gaps will indicate a possible empty spot.

This is some working code I have for a seperate project, written in Groovy (Java functional programming language).
Code: [Select]
def galaxy = 2
def systemFrom = 1
def systemTo = 499
def planetFrom = 6
def planetTo = 10

  result = statement.executeQuery("SELECT System, Planet FROM PLANET WHERE IsMoon = 0 AND Galaxy = " + galaxy + " AND System BETWEEN " + systemFrom + " AND " + systemTo + " AND Planet BETWEEN " + planetFrom + " AND " + planetTo + " ORDER BY System, Planet");

  // Prepare our coordinates
  Coordinates expected = new Coordinates((byte)galaxy, (short)systemFrom, (byte)planetFrom, Coordinates.PLANET_TYPE);
  Coordinates actual = new Coordinates(galaxy, 1, 1, Coordinates.PLANET_TYPE);

  def count = 0
 
  while(result.next())
  {
    // Extract the current coordinate
    actual.system = result.getShort("System");
    actual.planet = result.getByte("Planet");

    while (!actual.equals(expected))
    {
      // We didn't expect this planet. This means it's colonizable.
      printOut "Colonizable: " + expected
      count++

      // Increment the expected coordinate, wrap around if needed
      expected.planet += 1;
      if (expected.planet > planetTo)
      {
        expected.planet = planetFrom
        expected.system += 1;
      }

      // Repeat.
    }

    // Increment the expected coordinate, wrap around if needed
    expected.planet += 1;
    if (expected.planet > planetTo)
    {
      expected.planet = planetFrom
      expected.system += 1;
    }
  }

  printOut "Search completed, found " + count + " colonizable planets"

Offline crusy

  • **
  • Posts: 6
    • View Profile
Re: Finding colonizable planets
« Reply #1 on: 20 September 2013, 14:14:18 »
+1
One of the things I missed first when V5 came on.

Greenberg

  • Guest
Re: Finding colonizable planets
« Reply #2 on: 08 January 2014, 23:36:03 »
+1

very practicable and supportive.
I would appreciate an integration with one of the next versions.

Regards