AI masters build only rooms and towers they have researched

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-06 09:54:19 +01:00
1 parent e1a8e2c49c
commit cccb6b64c3
2 files changed
+41 -1

No files matched your search

+10 -1
View File
@@ -221,6 +221,10 @@ impl Game {
// the next room of the build order, where there is free own floor for it
fn ai_rooms(&mut self, cx: i32, cy: i32) {
for &(room, w, h, n) in BUILD.iter() {
// only what this master has researched (the same rules as the player)
if !self.ai_knows(crate::ui::Tool::Room(room)) {
continue;
}
let tiles = self.counts[room];
if tiles >= (w * h) as usize * n {
continue;
@@ -236,6 +240,11 @@ impl Game {
}
}
// has this master researched the tool (rooms, towers)?
fn ai_knows(&self, tool: crate::ui::Tool) -> bool {
crate::ui::TOOLS.iter().position(|&t| t == tool).map_or(false, |i| self.tool_allowed(i))
}
// a rectangle of own plain floor, as near the heart as possible (not right next to it)
fn ai_free_rect(&self, cx: i32, cy: i32, w: i32, h: i32) -> Option<(i32, i32)> {
let me = self.me;
@@ -260,7 +269,7 @@ impl Game {
fn ai_towers(&mut self, d: usize, cx: i32, cy: i32) {
let me = self.me;
let mine = self.towers.iter().filter(|t| !t.hero && self.map.t[t.tile].owner == me).count();
if mine >= MAX_TOWERS[d] || self.gold < 1800.0 || self.counts[0] == 0 {
if mine >= MAX_TOWERS[d] || self.gold < 1800.0 || self.counts[0] == 0 || !self.ai_knows(crate::ui::Tool::Tower(TowerKind::Arrow)) {
return;
}
let spot = (0..self.map.t.len()).filter(|&i| {