1 package ru.bosony.icfpc;
3 import java.nio.file.FileVisitOption;
4 import java.util.LinkedHashMap;
7 import ru.bosony.icfpc.cells.Cell;
17 private Map<Character, Cell> cellPrototypes = new LinkedHashMap<Character, Cell>();
19 private Cell cells[][][];
20 private int index = 0;
22 public Mine(int n, int m, String content)
26 cells = new Cell[2][n][m];
30 for(int i=0; i<n; ++i)
31 for(int j=0; j<m; ++j)
33 cells[index][i][j] = cellPrototypes.get(content.charAt(index++));
37 private Cell[][] firstBuffer()
42 private Cell[][] secondBuffer()
44 return cells[index==0 ? 1 : 0];
47 private void swapBuffers()
49 index = index==0 ? 1 : 0;
52 private void initCellPrototypes()
54 for(Cell c : Cell.values())
56 cellPrototypes.put(c.getASCII(), c);
62 for(int i=0; i<cells.length; ++i)
64 for(int j=0; j<cells[i].length; ++j)
66 System.out.print(firstBuffer()[i][j]);
72 public void updateAfterMove()
74 for(int i=0; i<cells.length; ++i)
75 for(int j=0; j<cells[i].length; ++j)
77 secondBuffer()[i][j] = firstBuffer()[i][j];
80 for(int i=1; i<cells.length-1; ++i)
81 for(int j=cells[i].length-1; j>1; --j)
83 switch(firstBuffer()[i][j])
87 if(firstBuffer()[i][j-1] == Cell.EMPTY)
89 secondBuffer()[i][j] = Cell.EMPTY;