1 | java -verbose:gc meteor.algorithm.Solver |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | public class Piece { private Piece[] permutations = new Piece[NUMBEROFPERMUTATIONS]; private ArrayList[][] occupiedBoardCells = new ArrayList[Piece.NUMBEROFCELLS][Board.NUMBEROFCELLS]; private void generatePermutations(Board board) { Piece prevPermutation=this; for (int i = 0; i < NUMBEROFPERMUTATIONS; i++) { // The original nextPermutation() has been renamed permutations= ((Piece)prevPermutation.clone()).nextPermutation_orig(); prevPermutation=permutations; } // Calculate occupied board cells for every permutation for (int i = 0; i < NUMBEROFPERMUTATIONS; i++) { permutations.generateOccupiedBoardCells(board); } } private void generateOccupiedBoardCells(Board board) { for (int i = 0; i < Piece.NUMBEROFCELLS; i++) { for (int j = 0; j < Board.NUMBEROFCELLS; j++) { occupiedBoardCells[j]=new ArrayList(); resetProcessed(); // We're going to process the piece board.findOccupiedBoardCells(occupiedBoardCells[j], pieceCells, board.getBoardCell(j)); } } } public Piece nextPermutation() { if (currentPermutation == NUMBEROFPERMUTATIONS) currentPermutation = 0; // The new implementation of nextPermutation() // accesses the cache return permutations[currentPermutation++]; } public ArrayList getOccupiedBoardCells(int pieceCellIdx, int boardCellIdx) { // Access requested data in cache return occupiedBoardCells[pieceCellIdx][boardCellIdx]; } } |
1 2 3 4 5 6 7 8 9 | public class Board { public boolean placePiece(Piece piece, int pieceCellIdx, int boardCellIdx) { // Get all the boardCells that this piece would occupy ArrayList occupiedBoardCells = piece.getOccupiedBoardCells(pieceCellIdx, boardCellIdx); ... } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |