git repos / blockattack-game

commit 9f2c006a

sago007 · 2016-03-24 21:15
9f2c006a8dd8422e90efc4c40b77a1416b4b97f8 patch · browse files
parent 212fd2530c584849c81d43a59ee5627379e63909

Removed redundant code.

Changed files

M source/code/BlockGame.cpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index ce52d84..46c79d8 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -1453,81 +1453,67 @@ void BlockGame::AI_ClearTower() {
void BlockGame::AI_ClearHori() {
// cout << "AI: ClearHori";
int lowestLine = AIlineToClear;
- //AIcolorToClear
- bool found =true;
- /*for(int i; (i<12)&&(!found);i++)
- * {
- * if(horiInLine(i)>2)
- * {
- * int lowestLine = i;
- * found = true;
- * }
- * }*/
for (int i=0; i<7; i++) {
if (nrOfType(lowestLine, i)>2) {
AIcolorToClear = i;
}
}
- if (found) {
- if (cursory>lowestLine-1) {
- MoveCursor('S');
+ if (cursory>lowestLine-1) {
+ MoveCursor('S');
+ }
+ else if (cursory<lowestLine-1) {
+ MoveCursor('N');
+ }
+ else if (nrOfType(lowestLine, AIcolorToClear)>2) {
+ int left=0, right=0;
+ if (board[0][lowestLine]==AIcolorToClear) {
+ left++;
}
- else if (cursory<lowestLine-1) {
- MoveCursor('N');
+ if (board[1][lowestLine]==AIcolorToClear) {
+ left++;
}
- else if (nrOfType(lowestLine, AIcolorToClear)>2) {
- int left=0, right=0;
- if (board[0][lowestLine]==AIcolorToClear) {
- left++;
- }
- if (board[1][lowestLine]==AIcolorToClear) {
- left++;
- }
- if (board[2][lowestLine]==AIcolorToClear) {
- left++;
- }
- if (board[3][lowestLine]==AIcolorToClear) {
- right++;
- }
- if (board[4][lowestLine]==AIcolorToClear) {
- right++;
- }
- if (board[5][lowestLine]==AIcolorToClear) {
- right++;
- }
- int xplace = 0;
- if (left<right) {
- // cout << ", right>left";
- int count=0;
- for (int i=0; (i<4)&&(count<1); i++)
- if ((board[i][lowestLine]==AIcolorToClear)&&((i==0)||(board[i+1][lowestLine]!=AIcolorToClear))) {
- count++;
- xplace = i;
- }
- }
- else {
- // cout << ", left>=right";
- int count=0;
- for (int i=3; (i<=5)&&(count<1); i++)
- if ((board[i][lowestLine]==AIcolorToClear)&&(board[i-1][lowestLine]!=AIcolorToClear)) {
- count++;
- xplace = --i;
- }
- }
- //cout << ", xplace: " << xplace;
- if (cursorx<xplace) {
- MoveCursor('E');
- }
- else if (cursorx>xplace) {
- MoveCursor('W');
- }
- else if (cursorx==xplace) {
- SwitchAtCursor();
- }
- else {
- AIstatus = 0;
+ if (board[2][lowestLine]==AIcolorToClear) {
+ left++;
+ }
+ if (board[3][lowestLine]==AIcolorToClear) {
+ right++;
+ }
+ if (board[4][lowestLine]==AIcolorToClear) {
+ right++;
+ }
+ if (board[5][lowestLine]==AIcolorToClear) {
+ right++;
+ }
+ int xplace = 0;
+ if (left<right) {
+ // cout << ", right>left";
+ int count=0;
+ for (int i=0; (i<4)&&(count<1); i++)
+ if ((board[i][lowestLine]==AIcolorToClear)&&((i==0)||(board[i+1][lowestLine]!=AIcolorToClear))) {
+ count++;
+ xplace = i;
+ }
+ }
+ else {
+ // cout << ", left>=right";
+ int count=0;
+ for (int i=3; (i<=5)&&(count<1); i++) {
+ if ((board[i][lowestLine]==AIcolorToClear)&&(board[i-1][lowestLine]!=AIcolorToClear)) {
+ count++;
+ xplace = --i;
+ }
}
}
+ //cout << ", xplace: " << xplace;
+ if (cursorx<xplace) {
+ MoveCursor('E');
+ }
+ else if (cursorx>xplace) {
+ MoveCursor('W');
+ }
+ else if (cursorx==xplace) {
+ SwitchAtCursor();
+ }
else {
AIstatus = 0;
}
diff --git a/source/code/main.cpp b/source/code/main.cpp index be7136b..48c3a6e 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -627,7 +627,7 @@ private:
void PaintBricks() const {
for (int i=0; ((i<13)&&(i<30)); i++) {
for (int j=0; j<6; j++) {
- int basicBrick = board[j][i]%10;
+ int basicBrick = board[j][i]%10; //The basic brick, stored on the least significant digit
if ((basicBrick > -1) && (basicBrick < 7) && ((board[j][i]/1000000)%10==0)) {
DrawImgBoardBounded(bricks[basicBrick], j*bsize, bsize*12-i*bsize-pixels);
if ((board[j][i]/BLOCKWAIT)%10==1) {