implement mining functionality in SortBot and add .gitignore
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
@@ -7,3 +7,4 @@ class SortBot : public BaseRobot {
|
||||
SortBot ( int startX, int startY );
|
||||
int mine ( World &world ) override;
|
||||
};
|
||||
|
||||
|
||||
+26
-1
@@ -4,4 +4,29 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
SortBot::SortBot ( int startX, int startY ) : BaseRobot ( "SortBot", startX, startY ) {}
|
||||
SortBot::SortBot ( const int startX, const int startY ) : BaseRobot ( "SortBot", startX, startY ) {}
|
||||
|
||||
int SortBot::mine ( World &world ) {
|
||||
// create ( value, z ) pairs for positive values ( exclude mined blocks and effects )
|
||||
std::vector<std::pair<int, int>> values;
|
||||
for ( int z = 0; z < world.getSizeZ(); ++z ) {
|
||||
int v = world.getValue(x_, y_, z );
|
||||
if ( v > 0 ) values.emplace_back(v, z );
|
||||
}
|
||||
if ( values.empty()) return 0;
|
||||
// sort descending
|
||||
std::sort ( values.begin(), values.end(), [] ( const auto& a, const auto& b ) { return a.first > b.first;} );
|
||||
|
||||
for ( auto& [x, z] : values ) {
|
||||
world.setValue ( x_, y_, z, 0);
|
||||
}
|
||||
for ( std::size_t i = 0; i < values.size(); ++i ) {
|
||||
world.setValue( x_, y_, static_cast<int>(i), values[i].first );
|
||||
}
|
||||
int surface = world.getSurfaceLevel(x_, y_);
|
||||
if ( surface < 0 ) return 0;
|
||||
int mined = world.getValue ( x_, y_, surface );
|
||||
world.setValue ( x_, y_, surface, 0 );
|
||||
score_ += mined;
|
||||
return mined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user