made it so castles cannot appear on the very edge of the map.
tweaks to AI to try to make it group slightly better
This commit is contained in:
parent
1de99909a8
commit
e53da7161c
3 changed files with 36 additions and 8 deletions
|
@ -238,9 +238,6 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
}
|
||||
|
||||
assert(best_target >= targets.begin() && best_target < targets.end());
|
||||
best_target->value -= best->second.type().cost()/20.0;
|
||||
if(best_target->value <= 0.0)
|
||||
targets.erase(best_target);
|
||||
|
||||
for(ittg = targets.begin(); ittg != targets.end(); ++ittg) {
|
||||
assert(map_.on_board(ittg->loc));
|
||||
|
@ -262,6 +259,15 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
std::pair<Itor,Itor> its = dstsrc.equal_range(*ri);
|
||||
while(its.first != its.second) {
|
||||
if(its.first->second == best->first && !should_retreat(its.first->first,fullmove_srcdst,fullmove_dstsrc,enemy_srcdst,enemy_dstsrc)) {
|
||||
const double value = best_target->value - best->second.type().cost()/20.0;
|
||||
targets.erase(best_target);
|
||||
|
||||
//if this is a sufficiently valuable target, we add this unit as a target -- meaning
|
||||
//that a group of units will rally around it, creating a teaming effect
|
||||
if(best_target->value > 0.0) {
|
||||
targets.push_back(target(its.first->first,value));
|
||||
}
|
||||
|
||||
return std::pair<location,location>(its.first->second,its.first->first);
|
||||
}
|
||||
|
||||
|
@ -271,6 +277,10 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
|
||||
if(best != units_.end()) {
|
||||
std::cout << "Could not make good move, staying still\n";
|
||||
|
||||
//this sounds like the road ahead might be dangerous, and that's why we don't advance.
|
||||
//create this as a target, attempting to rally units around
|
||||
targets.push_back(target(best->first,best_target->value));
|
||||
return std::pair<location,location>(best->first,best->first);
|
||||
}
|
||||
|
||||
|
|
|
@ -618,6 +618,28 @@ std::string config::write() const
|
|||
return res;
|
||||
}
|
||||
|
||||
//data compression. Compression is designed for network traffic.
|
||||
//assumptions compression is based on:
|
||||
// - most space is taken up by element names and attribute names
|
||||
// - there are relatively few element names and attribute names that are repeated many times
|
||||
//
|
||||
//how it works: there are some control characters:
|
||||
// 'compress_open_element': signals that the next word found is an element.
|
||||
// any words found that are not after this are assumed to be attributes
|
||||
// 'compress_close_element': signals to close the current element
|
||||
// 'compress_schema_item': signals that following is a nul-delimited string, which should
|
||||
// be added as a word in the schema
|
||||
// 'compress_literal_word': signals that following is a word stored as a nul-delimited string
|
||||
// (an attribute name, unless it was preceeded by 'compress_open_element')
|
||||
//
|
||||
// all other characters are mapped to words. When an item is inserted into the schema,
|
||||
// it is mapped to the first available character. Any attribute found is always followed
|
||||
// by a nul-delimited string which is the value for the attribute.
|
||||
//
|
||||
// the schema objects are designed to be persisted. That is, in a network game, both peers
|
||||
// can store their schema objects, and so rather than sending schema data each time, the peers
|
||||
// use and build their schemas as the game progresses, adding a new word to the schema anytime
|
||||
// it is required.
|
||||
namespace {
|
||||
const unsigned char compress_open_element = 0, compress_close_element = 1,
|
||||
compress_schema_item = 2, compress_literal_word = 3,
|
||||
|
|
|
@ -303,7 +303,6 @@ void place_castles(std::vector<gamemap::location>& castles, const std::set<gamem
|
|||
ci->y *= 1000;
|
||||
xvelocity.push_back(0.0);
|
||||
yvelocity.push_back(0.0);
|
||||
std::cerr << "castle at " << ci->x << "," << ci->y << "\n";
|
||||
}
|
||||
|
||||
std::vector<gamemap::location> villages;
|
||||
|
@ -337,7 +336,6 @@ void place_castles(std::vector<gamemap::location>& castles, const std::set<gamem
|
|||
const double ypower = power * ydist/(xdist+ydist) * (ci->y < i->y ? -1.0 : 1.0);
|
||||
xvelocity[index] += xpower;
|
||||
yvelocity[index] += ypower;
|
||||
std::cerr << "xpower = " << xpower << ", ypower = " << ypower << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,8 +414,6 @@ void place_castles(std::vector<gamemap::location>& castles, const std::set<gamem
|
|||
yvelocity[index] *= -1.0;
|
||||
ci->y = min_y*1000;
|
||||
}
|
||||
|
||||
std::cerr << "castle at " << ci->x << "," << ci->y << " (" << xvelocity[index] << "," << yvelocity[index] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -711,7 +707,7 @@ std::string default_generate_map(size_t width, size_t height,
|
|||
castles.push_back(location(x,y));
|
||||
}
|
||||
|
||||
place_castles(castles,villages,width/3,height/3,(width/3)*2 - 1,(height/3)*2 - 1);
|
||||
place_castles(castles,villages,width/3 + 2,height/3 + 2,(width/3)*2 - 3,(height/3)*2 - 3);
|
||||
|
||||
//make sure all castles are placed on valid terrain. Check the castle tile
|
||||
//itself, and all surrounding tiles
|
||||
|
|
Loading…
Add table
Reference in a new issue