|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include "BlockPruningGenericN2.hpp" 00023 00024 #include <stdio.h> 00025 #include <string.h> 00026 00027 BlockPruningGenericN2::BlockPruningGenericN2() { 00028 this->k = NULL; 00029 this->gridHeight = 0; 00030 this->gridWidth = 0; 00031 } 00032 00033 BlockPruningGenericN2::~BlockPruningGenericN2() { 00034 finalize(); 00035 } 00036 00037 void BlockPruningGenericN2::pruningUpdate(int bx, int by, int score) { 00038 if (getGrid() == NULL) return; 00039 updateBestScore(score); 00040 00041 if (isBlockPrunable(bx, by, score)) { 00042 k[by+1][bx+1] = true; 00043 } 00044 } 00045 00046 bool BlockPruningGenericN2::isBlockPruned(int bx, int by) { 00047 if (getGrid() == NULL) return false; 00048 if (k[by+1][bx] && k[by][bx] && k[by][bx+1]) { 00049 k[by+1][bx+1] = true; 00050 return true; 00051 } else { 00052 return false; 00053 } 00054 } 00055 00056 void BlockPruningGenericN2::initialize() { 00057 gridHeight = getGrid()->getGridHeight(); 00058 gridWidth = getGrid()->getGridWidth(); 00059 00060 this->k = new int*[gridHeight+1]; 00061 for (int i=0; i<=gridHeight; i++) { 00062 this->k[i] = new int[gridWidth+1]; 00063 memset(this->k[i], 0, sizeof(int)*(gridWidth+1)); 00064 } 00065 for (int i=1; i<=gridHeight; i++) { 00066 this->k[i][0] = true; 00067 } 00068 for (int i=1; i<=gridWidth; i++) { 00069 this->k[0][i] = true; 00070 } 00071 } 00072 00073 void BlockPruningGenericN2::finalize() { 00074 if (this->k != NULL) { 00075 00076 for (int i=0; i<=gridHeight; i++) { 00077 delete[] this->k[i]; 00078 } 00079 delete[] this->k; 00080 00081 this->k = NULL; 00082 this->gridHeight = 0; 00083 this->gridWidth = 0; 00084 } 00085 }
1.7.6.1