void findScoreStartingAtFor(MatchingScoreContext_t scoreContext, int row, int col, char myColor) { int dR = 0; int dC = 1; int r, c, i; for(i = 0; i < 4; i++) { r = row + dR; c = col + dC; int temp = dR; dR = dC; dC = -temp; if(!inBoard(r) || !inBoard(c)) { continue; } if(scoreContext->visited[r][c] == TRUE) { continue; } char otherColor = scoreContext->context->board[r][c]; if(otherColor == EMPTY_SPACE) { scoreContext->visited[r][c] = TRUE; continue; } if(otherColor == STAR_CHAR) { scoreContext->starsFound += 1; } else { if(myColor != otherColor) { continue; } scoreContext->tilesFound += 1; } #ifdef RUBY_ENV VALUE hash = rb_hash_new(); rb_hash_aset(hash, rb_str_new2("r"), INT2NUM(r)); rb_hash_aset(hash, rb_str_new2("c"), INT2NUM(c)); rb_ary_push(scoreContext->matches, hash); #endif scoreContext->scoreMultiplier *= scoreContext->context->bonus[r][c]; scoreContext->visited[r][c] = TRUE; findScoreStartingAtFor(scoreContext, r, c, myColor); } }
inline bool playerMove(int dirX, int dirY) { int tempX, tempY; int x = playerPosition.getX() + dirX; int y = playerPosition.getY() + dirY; if(inBoard(x,y)) { switch(board[x][y]) { case Debris: tempX = x + dirX; tempY = y + dirY; if(inBoard(tempX, tempY)) { switch(board[tempX][tempY]) { case Enemy: case Empty: board[tempX][tempY] = Debris; break; case Debris: return true; } } else { return true; } case Empty: board[x][y] = Player; board[playerPosition.getX()][playerPosition.getY()] = Empty; playerPosition.setPoint(x, y); case Player: return false; } } return true; }
boolean checkAndPlaceTile(MatchingContext_t context, char *currentTile, int row, int col, int dir) { int i, j; if(dir % 2 == 0) { int d = dir < 2 ? 1 : -1; if(!inBoard(col + d * (TILE_SIZE - 1))) { return FALSE; } for(i = 0; i < TILE_SIZE; i++) { if(context->board[row][col + d * i] != EMPTY_SPACE) { return FALSE; } } if( (inBoard(col - d) && context->board[row][col - d] != EMPTY_SPACE) || (inBoard(col + d * TILE_SIZE) && context->board[row][col + d * TILE_SIZE] != EMPTY_SPACE)) { for(i = 0; i < TILE_SIZE; i++) { context->board[row][col + d * i] = currentTile[i]; } return TRUE; } for(i = 0; i < TILE_SIZE; i++) { if( (row > 0 && context->board[row - 1][col + d * i] != EMPTY_SPACE) || (row < BOARD_SIZE - 1 && context->board[row + 1][col + d * i] != EMPTY_SPACE)) { for(j = 0; j < TILE_SIZE; j++) { context->board[row][col + d * j] = currentTile[j]; } return TRUE; } } return FALSE; } else { int d = dir < 2 ? 1 : -1; if(!inBoard(row + d * (TILE_SIZE - 1))) { return FALSE; } for(i = 0; i < TILE_SIZE; i++) { if(context->board[row + d * i][col] != EMPTY_SPACE) { return FALSE; } } if( (inBoard(row - d) && context->board[row - d][col] != EMPTY_SPACE) || (inBoard(row + d * TILE_SIZE) && context->board[row + d * TILE_SIZE][col] != EMPTY_SPACE)) { for(i = 0; i < TILE_SIZE; i++) { context->board[row + d * i][col] = currentTile[i]; } return TRUE; } for(i = 0; i < TILE_SIZE; i++) { if( (col > 0 && context->board[row + d * i][col - 1] != EMPTY_SPACE) || (col < BOARD_SIZE - 1 && context->board[row + d * i][col + 1] != EMPTY_SPACE)) { for(j = 0; j < TILE_SIZE; j++) { context->board[row + d * j][col] = currentTile[j]; } return TRUE; } } return FALSE; } }
inline bool robotsMove() { int minLength, pointer; int tempX, tempY, tempLength; bool flag = false; for(int i=1;i<=31;++i) { for(int j=1;j<=31;++j) { if(board[i][j] == Enemy) { tempBoard[i][j] = Empty; } else { tempBoard[i][j] = board[i][j]; } } } for(int i=1;i<=31;++i) { for(int j=1;j<=31;++j) { if(board[i][j] == Enemy) { minLength = 19627; for(int k=0;k<9;++k) { tempX = i + directionX[k]; tempY = j + directionY[k]; if(inBoard(tempX, tempY)) { tempLength = getLengthI4(tempX, tempY, playerPosition.getX(), playerPosition.getY()); if(tempLength < minLength) { minLength = tempLength; pointer = k; } } } tempX = i + directionX[pointer]; tempY = j + directionY[pointer]; switch(tempBoard[tempX][tempY]) { case Empty: tempBoard[tempX][tempY] = Enemy; break; case Enemy: case Debris: tempBoard[tempX][tempY] = Debris; break; case Player: flag = true; tempBoard[tempX][tempY] = Enemy; break; } } } } memcpy(board,tempBoard,sizeof(board)); return flag; }