1.1 Binary file bin/ru/bosony/icfpc/Mine.class has changed
2.1 Binary file bin/ru/bosony/icfpc/cells/Cell.class has changed
3.1 --- a/src/ru/bosony/icfpc/Mine.java Fri Jul 13 18:13:05 2012 +0400
3.2 +++ b/src/ru/bosony/icfpc/Mine.java Fri Jul 13 18:45:38 2012 +0400
3.3 @@ -1,10 +1,10 @@
3.4 package ru.bosony.icfpc;
3.5
3.6 +import java.nio.file.FileVisitOption;
3.7 import java.util.LinkedHashMap;
3.8 import java.util.Map;
3.9
3.10 import ru.bosony.icfpc.cells.Cell;
3.11 -import ru.bosony.icfpc.cells.CellTypes;
3.12
3.13 /**
3.14 * Шахта
3.15 @@ -16,44 +16,82 @@
3.16 {
3.17 private Map<Character, Cell> cellPrototypes = new LinkedHashMap<Character, Cell>();
3.18
3.19 - private Cell cells[][];
3.20 + private Cell cells[][][];
3.21 + private int index = 0;
3.22
3.23 public Mine(int n, int m, String content)
3.24 {
3.25 initCellPrototypes();
3.26
3.27 - cells = new Cell[n][m];
3.28 + cells = new Cell[2][n][m];
3.29
3.30 int index = 0;
3.31
3.32 for(int i=0; i<n; ++i)
3.33 for(int j=0; j<m; ++j)
3.34 {
3.35 - cells[i][j] = new Cell( cellPrototypes.get(content.charAt(index++)) );
3.36 + cells[index][i][j] = cellPrototypes.get(content.charAt(index++));
3.37 }
3.38 }
3.39
3.40 + private Cell[][] firstBuffer()
3.41 + {
3.42 + return cells[index];
3.43 + }
3.44 +
3.45 + private Cell[][] secondBuffer()
3.46 + {
3.47 + return cells[index==0 ? 1 : 0];
3.48 + }
3.49 +
3.50 + private void swapBuffers()
3.51 + {
3.52 + index = index==0 ? 1 : 0;
3.53 + }
3.54 +
3.55 private void initCellPrototypes()
3.56 {
3.57 - cellPrototypes.put('*', new Cell(CellTypes.ROCK, '*'));
3.58 - cellPrototypes.put('\\', new Cell(CellTypes.LAMBDA, '\\'));
3.59 - cellPrototypes.put('#', new Cell(CellTypes.WALL, '#'));
3.60 - cellPrototypes.put('R', new Cell(CellTypes.ROBOT, 'R'));
3.61 - cellPrototypes.put('L', new Cell(CellTypes.CLOSED_LAMBDA_LIFT, 'L'));
3.62 - cellPrototypes.put('O', new Cell(CellTypes.OPEN_LAMBDA_LIFT, 'O'));
3.63 - cellPrototypes.put(' ', new Cell(CellTypes.SPACE, ' '));
3.64 - cellPrototypes.put('.', new Cell(CellTypes.EARTH, '.'));
3.65 + for(Cell c : Cell.values())
3.66 + {
3.67 + cellPrototypes.put(c.getASCII(), c);
3.68 + }
3.69 }
3.70
3.71 - void print()
3.72 + public void print()
3.73 {
3.74 for(int i=0; i<cells.length; ++i)
3.75 {
3.76 for(int j=0; j<cells[i].length; ++j)
3.77 {
3.78 - System.out.print(cells[i][j].getASCII());
3.79 + System.out.print(firstBuffer()[i][j]);
3.80 }
3.81 System.out.println();
3.82 }
3.83 }
3.84 +
3.85 + public void updateAfterMove()
3.86 + {
3.87 + for(int i=0; i<cells.length; ++i)
3.88 + for(int j=0; j<cells[i].length; ++j)
3.89 + {
3.90 + secondBuffer()[i][j] = firstBuffer()[i][j];
3.91 + }
3.92 +
3.93 + for(int i=1; i<cells.length-1; ++i)
3.94 + for(int j=cells[i].length-1; j>1; --j)
3.95 + {
3.96 + switch(firstBuffer()[i][j])
3.97 + {
3.98 + case ROCK:
3.99 + {
3.100 + if(firstBuffer()[i][j-1] == Cell.EMPTY)
3.101 + {
3.102 + secondBuffer()[i][j] = Cell.EMPTY;
3.103 + }
3.104 + }
3.105 + break;
3.106 + }
3.107 + }
3.108 + }
3.109 +
3.110 }
4.1 --- a/src/ru/bosony/icfpc/cells/Cell.java Fri Jul 13 18:13:05 2012 +0400
4.2 +++ b/src/ru/bosony/icfpc/cells/Cell.java Fri Jul 13 18:45:38 2012 +0400
4.3 @@ -1,32 +1,24 @@
4.4 package ru.bosony.icfpc.cells;
4.5
4.6 -public class Cell
4.7 +public enum Cell
4.8 {
4.9 + ROBOT('R'),
4.10 + ROCK('*'),
4.11 + EAGHT('.'),
4.12 + WALL('#'),
4.13 + LAMBDA('\\'),
4.14 + CLOSED_LAMBDA_LIFT('L'),
4.15 + OPEN_LAMBDA_LIFT('O'),
4.16 + EMPTY(' '),
4.17 + EARTH('.');
4.18
4.19 - private CellTypes type;
4.20 private char ASCII;
4.21
4.22 - public Cell(CellTypes type, char ASCII)
4.23 + private Cell(char ASCII)
4.24 {
4.25 - this.type = type;
4.26 this.ASCII = ASCII;
4.27 }
4.28
4.29 - public Cell(Cell cell)
4.30 - {
4.31 - this.type = cell.type;
4.32 - this.ASCII = cell.ASCII;
4.33 - }
4.34 -
4.35 - public CellTypes getType()
4.36 - {
4.37 - return type;
4.38 - }
4.39 - public void setType(CellTypes type)
4.40 - {
4.41 - this.type = type;
4.42 - }
4.43 -
4.44 public char getASCII()
4.45 {
4.46 return ASCII;