1.1 --- a/src/ru/bosony/icfpc/Mine.java Fri Jul 13 18:13:05 2012 +0400
1.2 +++ b/src/ru/bosony/icfpc/Mine.java Fri Jul 13 18:45:38 2012 +0400
1.3 @@ -1,10 +1,10 @@
1.4 package ru.bosony.icfpc;
1.5
1.6 +import java.nio.file.FileVisitOption;
1.7 import java.util.LinkedHashMap;
1.8 import java.util.Map;
1.9
1.10 import ru.bosony.icfpc.cells.Cell;
1.11 -import ru.bosony.icfpc.cells.CellTypes;
1.12
1.13 /**
1.14 * Шахта
1.15 @@ -16,44 +16,82 @@
1.16 {
1.17 private Map<Character, Cell> cellPrototypes = new LinkedHashMap<Character, Cell>();
1.18
1.19 - private Cell cells[][];
1.20 + private Cell cells[][][];
1.21 + private int index = 0;
1.22
1.23 public Mine(int n, int m, String content)
1.24 {
1.25 initCellPrototypes();
1.26
1.27 - cells = new Cell[n][m];
1.28 + cells = new Cell[2][n][m];
1.29
1.30 int index = 0;
1.31
1.32 for(int i=0; i<n; ++i)
1.33 for(int j=0; j<m; ++j)
1.34 {
1.35 - cells[i][j] = new Cell( cellPrototypes.get(content.charAt(index++)) );
1.36 + cells[index][i][j] = cellPrototypes.get(content.charAt(index++));
1.37 }
1.38 }
1.39
1.40 + private Cell[][] firstBuffer()
1.41 + {
1.42 + return cells[index];
1.43 + }
1.44 +
1.45 + private Cell[][] secondBuffer()
1.46 + {
1.47 + return cells[index==0 ? 1 : 0];
1.48 + }
1.49 +
1.50 + private void swapBuffers()
1.51 + {
1.52 + index = index==0 ? 1 : 0;
1.53 + }
1.54 +
1.55 private void initCellPrototypes()
1.56 {
1.57 - cellPrototypes.put('*', new Cell(CellTypes.ROCK, '*'));
1.58 - cellPrototypes.put('\\', new Cell(CellTypes.LAMBDA, '\\'));
1.59 - cellPrototypes.put('#', new Cell(CellTypes.WALL, '#'));
1.60 - cellPrototypes.put('R', new Cell(CellTypes.ROBOT, 'R'));
1.61 - cellPrototypes.put('L', new Cell(CellTypes.CLOSED_LAMBDA_LIFT, 'L'));
1.62 - cellPrototypes.put('O', new Cell(CellTypes.OPEN_LAMBDA_LIFT, 'O'));
1.63 - cellPrototypes.put(' ', new Cell(CellTypes.SPACE, ' '));
1.64 - cellPrototypes.put('.', new Cell(CellTypes.EARTH, '.'));
1.65 + for(Cell c : Cell.values())
1.66 + {
1.67 + cellPrototypes.put(c.getASCII(), c);
1.68 + }
1.69 }
1.70
1.71 - void print()
1.72 + public void print()
1.73 {
1.74 for(int i=0; i<cells.length; ++i)
1.75 {
1.76 for(int j=0; j<cells[i].length; ++j)
1.77 {
1.78 - System.out.print(cells[i][j].getASCII());
1.79 + System.out.print(firstBuffer()[i][j]);
1.80 }
1.81 System.out.println();
1.82 }
1.83 }
1.84 +
1.85 + public void updateAfterMove()
1.86 + {
1.87 + for(int i=0; i<cells.length; ++i)
1.88 + for(int j=0; j<cells[i].length; ++j)
1.89 + {
1.90 + secondBuffer()[i][j] = firstBuffer()[i][j];
1.91 + }
1.92 +
1.93 + for(int i=1; i<cells.length-1; ++i)
1.94 + for(int j=cells[i].length-1; j>1; --j)
1.95 + {
1.96 + switch(firstBuffer()[i][j])
1.97 + {
1.98 + case ROCK:
1.99 + {
1.100 + if(firstBuffer()[i][j-1] == Cell.EMPTY)
1.101 + {
1.102 + secondBuffer()[i][j] = Cell.EMPTY;
1.103 + }
1.104 + }
1.105 + break;
1.106 + }
1.107 + }
1.108 + }
1.109 +
1.110 }