瀏覽代碼

defending, when not possible to attack invincible

Laserlicht 1 年之前
父節點
當前提交
a1384bf47f
共有 2 個文件被更改,包括 12 次插入1 次删除
  1. 4 1
      AI/BattleAI/BattleEvaluator.cpp
  2. 8 0
      AI/StupidAI/StupidAI.cpp

+ 4 - 1
AI/BattleAI/BattleEvaluator.cpp

@@ -337,7 +337,10 @@ BattleAction BattleEvaluator::moveOrAttack(const CStack * stack, BattleHex hex,
 	}
 	else
 	{
-		return BattleAction::makeMove(stack, hex);
+		if(stack->position == hex)
+			return BattleAction::makeDefend(stack);
+		else
+			return BattleAction::makeMove(stack, hex);
 	}
 }
 

+ 8 - 0
AI/StupidAI/StupidAI.cpp

@@ -296,7 +296,11 @@ BattleAction CStupidAI::goTowards(const BattleID & battleID, const CStack * stac
 	for(auto hex : hexes)
 	{
 		if(vstd::contains(avHexes, hex))
+		{
+			if(stack->position == hex)
+				return BattleAction::makeDefend(stack);
 			return BattleAction::makeMove(stack, hex);
+		}
 
 		if(stack->coversPos(hex))
 		{
@@ -336,7 +340,11 @@ BattleAction CStupidAI::goTowards(const BattleID & battleID, const CStack * stac
 			}
 
 			if(vstd::contains(avHexes, currentDest))
+			{
+				if(stack->position == currentDest)
+					return BattleAction::makeDefend(stack);
 				return BattleAction::makeMove(stack, currentDest);
+			}
 
 			currentDest = reachability.predecessors[currentDest];
 		}