Android Open Source - Airplanes Grid Randomizer






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.axnsan.airplanes;
/* w ww.ja va 2  s.c  o m*/
import com.axnsan.airplanes.Plane.Model;
import com.axnsan.airplanes.Plane.Orientation;


public class GridRandomizer extends BaseGrid {
  private Model[] model;
  
  public int tryToFill() {
    model = new Model[4];
    model[0] = Plane.calculateGridModel(Orientation.UP);
    model[1] = Plane.calculateGridModel(Orientation.LEFT);
    model[2] = Plane.calculateGridModel(Orientation.DOWN);
    model[3] = Plane.calculateGridModel(Orientation.RIGHT);
    try_placement: while (true) 
    {
      int x, y, o;
      int attempts = 0;
      double range = size;
      do {
        x = (int) (Math.random() * range);
        y = (int) (Math.random() * range);
        o = (int) (Math.random() * 4);
        
        attempts++;
      } while (addPlane(x, y, model[o]) <= 0 && attempts <= 500);
      if (attempts > 500) {
        for (o = 0;o < 4;++o) {
          for (x = 0;x < size;++x)
            for (y = 0;y < size;++y)
              {
                if (addPlane(x, y, model[o]) > 0) {
                  continue try_placement;
                }
              }
        }
        break;
      }
    }
    return planeLocations.size();
  }
  public GridRandomizer(int size) {
    super(size);
  }
    
  public static class thread1 implements Runnable {

      public void run() {
        for (int numPlanes = 4;numPlanes <= 41;++numPlanes) {
          int avg = 0;
        int samplesize = 10000;
        for (int i = 1;i <= samplesize;++i) {
          avg += new GridRandomizer(numPlanes).tryToFill();
        }
        System.out.println(numPlanes + " " + (double)avg/samplesize);
        }
      }
  }
  public static class thread2 implements Runnable {

      public void run() {
        for (int numPlanes = 42;numPlanes <= 50;++numPlanes) {
          int avg = 0;
        int samplesize = 10000;
        for (int i = 1;i <= samplesize;++i) {
          avg += new GridRandomizer(numPlanes).tryToFill();
        }
        System.out.println(numPlanes + " " + (double)avg/samplesize);
        }
      }
  }
  public static void main(String[] args) {
    for (int i = 4;i <= 50;++i) {
      Airplanes game = Airplanes.game;
      game.config.gridSize = i;
      System.out.println(i + " " + Airplanes.game.maxNumPlanes());
    }
    /*new Thread(new thread1()).start();
    new Thread(new thread2()).start();*/
    /*for (int numPlanes = 4;numPlanes <= 50;++numPlanes) {
      //new Thread(new thread(numPlanes)).start();
      int avg = 0;
      int samplesize = 10000;
      for (int i = 1;i <= samplesize;++i) {
        avg += new GridRandomizer(numPlanes).tryToFill();
      }
      System.out.println(numPlanes + ": " + (double)avg/samplesize);
    }*/
  }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java