Package engine

Examples of engine.Board


   * @param pbb - probability of moving a block
   * @param originalScheme - the scheme, which contains the board
   * @return scheme with the new board and the moves
   */
  public static Scheme generateEquivalent(double pbb, Scheme originalScheme) {
    Scheme s = new Scheme(new Board(originalScheme.start));
   
    int width = s.start.width, height = s.start.height;
    int[] rows = MixGenerator.randomPermutation(height);
    for (int y : rows) {
      int[] columns = MixGenerator.randomPermutation(width);
View Full Code Here


   * @param pbb - probability of moving a block
   * @param originalScheme - the given scheme
   * @return scheme with the new board and the moves
   */
  public static Scheme generatePrevious(double pbb, Scheme originalScheme) {
    Scheme s = new Scheme(new Board(originalScheme.start));
    int width = s.start.width, height = s.start.height;
   
    for (int y = 0; y < height; y++) {
      int[] columns = MixGenerator.randomPermutation(width);
      boolean[] row = new boolean[width];
View Full Code Here

   * @param height - new height
   * @param shiftx - shift x of original content
   * @param shifty - shift y of original content
   */
  public static Board getResized(Board board,int width,int height,int shiftx,int shifty) {
    Board newBoard = new Board(width,height);
    int x1 = 0,x2 = width,y1 = 0,y2 = height;
    if (x1 < shiftx) x1 = shiftx;
    if (x2 > board.width+shiftx) x2 = board.width+shiftx;
    if (y1 < shifty) y1 = shifty;
    if (y2 > board.height+shifty) y2 = board.height+shifty;
    for (int y=y1;y<y2;y++)
      for (int x=x1;x<x2;x++) {
        newBoard.setElement(x,y,
            board.getType(x-shiftx,y-shifty),
            board.getColor(x-shiftx,y-shifty),
            board.getAction(x-shiftx,y-shifty));
      }
    return newBoard;
View Full Code Here

   
    assert (pbbSolid>=0 && pbbSolid<=1 && pbbIce>=0 && pbbIce<=1 &&
        pbbElevator>=0 && pbbElevator<=1 && pbbLava>=0 && pbbLava<=1 &&
        pbbSolidConcrete>=0 && pbbSolidConcrete<=1);
   
    Board board = new Board(width,height);
    Random rand = new Random();
    if (width < 1 || height < 1) return board;

    int[] types = new int[] {Board.SOLID, Board.CONCRETE, Board.ELEVATOR,
        Board.PAINTER, Board.LAVA, Board.ICE};
    double[] pbbs = new double[] {pbbSolid, pbbSolidConcrete, pbbElevator,
        pbbPainter, pbbLava, pbbIce};
    int[] factors = new int[] {8, 8, 1, 1, 8, 8};
   
    for (int k = 0; k < types.length; k++) {
      int[][] goodPositions = new int[width][height];
      double total = getAllPositions(types[k], board, goodPositions);
      double left = (int)(pbbs[k]*total+0.5);
      int[] perm = MixGenerator.randomPermutation(width*height);
      for (int i = 0; i < width*height; i++) {
        int x = perm[i] % width;
        int y = perm[i] / width;
        if (goodPositions[x][y] > 0) {
          double pbb = ((double)left*goodPositions[x][y]/total);
          if (board.getType(x-1, y) == types[k]) pbb*=factors[k];
          if (board.getType(x+1, y) == types[k]) pbb*=factors[k];
          if (board.getType(x, y+1) == types[k]) pbb*=factors[k]/2;
         
          if (rand.nextDouble() < pbb) {
            if (types[k] == Board.CONCRETE) {
              int color;
              if (board.getType(x-1,y) == Board.CONCRETE)
                color = board.getColor(x-1,y); else
              if (board.getType(x+1,y) == Board.CONCRETE)
                color = board.getColor(x+1,y); else
              if (board.getType(x,y+1) == Board.CONCRETE)
                color = board.getColor(x,y+1); else
                color = rand.nextInt(Board.NUM_COLORS);
              board.setElement(x,y,Board.CONCRETE,color);
            } else
            if (types[k] == Board.PAINTER) {
              int color = rand.nextInt(Board.NUM_COLORS);
              board.setElement(x, y, types[k], color);
            } else
              board.setElement(x,y,types[k]);
           
            // Increment total weight
            if (x > 0 && goodPositions[x-1][y] > 0) {
              int inc = goodPositions[x-1][y]*(factors[k]-1);
              left += pbbs[k]*inc;
              total += inc;
              goodPositions[x-1][y] += inc;
            }
            if (x < width-1 && goodPositions[x+1][y] > 0) {
              int inc = goodPositions[x+1][y]*(factors[k]-1);
              left += pbbs[k]*inc;
              total += inc;
              goodPositions[x+1][y] += inc;
            }
           
            left -= goodPositions[x][y];
          }
         
          total -= goodPositions[x][y];
          goodPositions[x][y] = 0;
        }
      }
    }
   
    // Repairing lava
    for (int i = 0; i < width; i++)
      for (int j = 0; j < height; j++)
        if (board.getType(i, j) == Board.LAVA) {
          if (board.getType(i-1, j) != Board.LAVA)
            board.setElement(i-1, j, Board.SOLID);
          if (board.getType(i+1, j) != Board.LAVA)
            board.setElement(i+1, j, Board.SOLID);
        }
   
    return board;
  }
View Full Code Here

   *
   * @param destinationBoard
   * @return the scheme with generated blocks
   */
  public static Scheme generateBlocks(Board destinationBoard) {
    Scheme s = new Scheme(new Board(destinationBoard));
    int mix = rand.nextInt(NUM_COMBINATIONS);
    mix = COMBINATION_2H;
    generateBlock(mix, s);
    return s;
  }
View Full Code Here

   * @param y - coordinate of the field
   * @param color - the color of the blocks
   * @param s - scheme, it is returned with new blocks
   */
  private static void addMix(int mix, int x, int y, int color, Scheme s) {
    Board board = s.start;
   
    switch (mix) {
    case COMBINATION_2H:
      insertBlock(x, y, color, board);
      insertBlock(x+1, y, color, board);
View Full Code Here

   * @param s - scheme
   * @return the color of blocks which can be add in the fixed fields or -1 if
   * the blocks can't be inserted.
   */
  private static int goodPosition(int mix, int x, int y, Scheme s) {
    Board board = s.start; int color=-1;
   
    switch (mix) {
    case COMBINATION_2H: {      
      if (board.getType(x, y)   == Board.CONCRETE) color = board.getColor(x, y);
      if (board.getType(x+1, y) == Board.CONCRETE)
        if (color==-1 || board.getColor(x+1, y)==color) color = board.getColor(x+1, y);
        else return -1;
      if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
     
      boolean canMove = false;
      boolean block1 = canInsertBlock(x,y,color, true, board, new int[]{0,0,0,0});
      if (block1) insertBlock(x, y, color, board);
      boolean block2 = canInsertBlock(x+1,y,color, true, board, new int[]{0,0,0,1});
      if (block2) insertBlock(x+1, y, color, board);
      if (block1 && block2)
        canMove = MixGenerator.canMoveBlock(x, y, true, s) ||
          MixGenerator.canMoveBlock(x+1, y, true, s);
      if (block2) deleteBlock(x+1,y, board);
      if (block1) deleteBlock(x,y, board);
     
      if (canMove) return color;
      else return -1;
    }
   
    case COMBINATION_2V: {
      if (board.getType(x, y)   == Board.CONCRETE) color = board.getColor(x, y);
      if (board.getType(x, y-1) == Board.CONCRETE)
        if (color==-1 || board.getColor(x, y-1)==color) color = board.getColor(x, y-1);
        else return -1;
      if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
     
      boolean canMove = false;
      boolean block1 = canInsertBlock(x,y,color, false, board, new int[]{0,0,0,0});
      if (block1) insertBlock(x, y, color, board);
      boolean block2 = canInsertBlock(x,y-1,color, false, board, new int[]{0,0,1,0});
      if (block2) insertBlock(x, y-1, color, board);
      if (block1 && block2)
        canMove = MixGenerator.canMoveBlock(x, y-1, true, s);
      if (block2) deleteBlock(x,y-1, board);
      if (block1) deleteBlock(x,y, board);
     
      if (canMove) return color;
      else return -1;
    }
   
    case COMBINATION_3LV:
      if (board.getType(x, y)   == Board.CONCRETE) color = board.getColor(x, y);
      if (board.getType(x, y-1) == Board.CONCRETE)
        if (color==-1 || board.getColor(x, y-1)==color) color = board.getColor(x, y-1);
        else return -1;
      if (board.getType(x-1, y-1) == Board.CONCRETE)
        if (color==-1 || board.getColor(x-1, y-1)==color) color = board.getColor(x-1, y-1);
        else return -1;
      if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
     
      boolean canMove = false;
      boolean block1 = canInsertBlock(x,y,color, false, board, new int[]{0,0,0,0});
      if (block1) insertBlock(x, y, color, board);
      boolean block2 = canInsertBlock(x,y-1,color, false, board, new int[]{0,0,1,0});
      if (block2) insertBlock(x, y-1, color, board);
      boolean block3 = canInsertBlock(x-1,y-1,color, true, board, new int[]{0,1,0,0});
      if (block3) insertBlock(x-1, y-1, color, board);
      if (block1 && block2 && block3)
        canMove = MixGenerator.canMoveBlock(x, y-1, true, s);
      if (block3) deleteBlock(x-1,y-1, board);
      if (block2) deleteBlock(x,y-1, board);
      if (block1) deleteBlock(x,y, board);
     
      if (canMove) return color;
      return -1;
    }
   
    case COMBINATION_3RV: {    
      if (board.getType(x, y)   == Board.CONCRETE) color = board.getColor(x, y);
      if (board.getType(x, y-1) == Board.CONCRETE)
        if (color==-1 || board.getColor(x, y-1)==color) color = board.getColor(x, y-1);
        else return -1;
      if (board.getType(x+1, y-1) == Board.CONCRETE)
        if (color==-1 || board.getColor(x+1, y-1)==color) color = board.getColor(x+1, y-1);
        else return -1;
      if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
    
      boolean canMove = false;
      boolean block1 = canInsertBlock(x,y,color, false, board, new int[]{0,0,0,0});
      if (block1) insertBlock(x, y, color, board);
      boolean block2 = canInsertBlock(x,y-1,color, false, board, new int[]{0,0,1,0});
      if (block2) insertBlock(x, y-1, color, board);
      boolean block3 = canInsertBlock(x+1,y-1,color, true, board, new int[]{0,0,0,1});
      if (block3) insertBlock(x+1, y-1, color, board);
      if (block1 && block2 && block3)
        canMove = MixGenerator.canMoveBlock(x, y-1, true, s);
      if (block3) deleteBlock(x+1,y-1, board);
      if (block2) deleteBlock(x,y-1, board);
      if (block1) deleteBlock(x,y, board);
     
      if (canMove) return color;
      else return -1;
    }
   
    case COMBINATION_3H: {  
      if (board.getType(x, y)   == Board.CONCRETE) color = board.getColor(x, y);
      if (board.getType(x+1, y) == Board.CONCRETE)
        if (color==-1 || board.getColor(x+1, y)==color) color = board.getColor(x+1, y);
        else return -1;
      if (board.getType(x+2, y) == Board.CONCRETE)
        if (color==-1 || board.getColor(x+2, y)==color) color = board.getColor(x+2, y);
        else return -1;
      if (color==-1) color = rand.nextInt(Board.NUM_COLORS);
   
     
      boolean canMove = false;
View Full Code Here

  @Override
  public Object getElementAt(int index) {
    if (index >= 0 && index < cache.length) {
      if (cache[index] == null) {
        // Icon construction       
        Board board = schemeSet.get(index).start;
        int boardSize;
        if (board.width >= board.height) boardSize = board.width+2; else boardSize = board.height+2;
        int fieldSize = (iconSize+boardSize-1)/boardSize;
        BufferedImage imgBoard = new BufferedImage(boardSize*fieldSize,boardSize*fieldSize,BufferedImage.TYPE_INT_ARGB);
        Graphics2D gBoard = imgBoard.createGraphics();
View Full Code Here

  private void performResize() {
    // Construct new board
    int shiftx = (Integer)spShiftX.getValue();
    int shifty = (Integer)spShiftY.getValue();
    Board newBoard = BoardManager.getResized(originalScheme.start,
        (Integer)spWidth.getValue(),(Integer)spHeight.getValue(),
        shiftx,shifty);
    newBoard.doFramesToStability();
    // Construct new scheme
    Scheme newScheme = new Scheme(originalScheme);
    ListIterator<Move> iterator = newScheme.moves.listIterator();
    while (iterator.hasNext()) {
      Move move = iterator.next();
View Full Code Here

    this.setBounds(100,50,345,345);
    this.setResizable(false);
  }

  private void generate() {
    Board newBoard = OutlineGenerator.generateOutline(
        (Integer)spWidth.getValue(), (Integer)spHeight.getValue(),
        (Double)spSolid.getValue(), (Double)spIce.getValue(),
        (Double)spLava.getValue(), (Double)spElevator.getValue(),
        (Double)spPainter.getValue(), (Double) spSolidConcrete.getValue());
    if (chRemoveSurroundedSolids.isSelected()) BoardManager.removeSurroundedSolids(newBoard);
View Full Code Here

TOP

Related Classes of engine.Board

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.