Commit c6990c5f authored by Jaime Torres Amate's avatar Jaime Torres Amate
Browse files

make the AI smarter to not shoot at places it knows there are no ships

When notify is called after a shoot, and an opponent ship is sunk,
mark the surrounding cells as border, therefore the AI will not try
them in the future.

BUG: 318594
FIXED-IN: 4.12
REVIEW: 113054
parent c6998efa
......@@ -180,6 +180,7 @@ class DiagonalStrategy : public Strategy
int m_offset;
int m_range;
// following a diagonal, return true if there is water at the enemy's panel.
bool movesAvailable() const {
Sea::Player opp = Sea::opponent(m_player);
for (int i = 0; i < m_sea->size().x; i++)
......
......@@ -41,6 +41,16 @@ AIEntity::~AIEntity()
void AIEntity::notify(Sea::Player player, const Coord& c, const HitInfo& info)
{
m_ai->notify(player, c, info);
// add a border around opponent sunk ship in KBS4 mode when no adjacentShips
// are allowed, the AI will not try to shoot at points that are not free
if (m_level == COMPAT_KBS4 &&
player == m_player &&
!m_sea->isAdjacentShipsAllowed() &&
info.shipDestroyed) {
m_sea->addBorder(Sea::opponent(player), info.shipPos);
}
getShoot();
}
......
......@@ -106,13 +106,6 @@ void PlayerEntity::hit(Shot* shot)
void PlayerEntity::notify(Sea::Player player, const Coord& c, const HitInfo& info)
{
UIEntity::notify(player, c, info);
// add a border around sunk ship in KBS3 mode
if (m_level == COMPAT_KBS3 &&
player == m_player &&
info.shipDestroyed) {
m_sea->addBorder(player, info.shipPos);
}
}
void PlayerEntity::changeDirection(Sea::Player player)
......
......@@ -67,6 +67,7 @@ public:
inline Player turn() const { return m_turn; }
static Player opponent(Player p);
inline Coord size() const { return m_size; }
inline bool isAdjacentShipsAllowed() const { return m_allow_adjacent_ships; }
};
#endif // Sea_H
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment