[freeciv-ai] (PR#11009) AI Hunts Own Units
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=11009 >
> [badamson@xxxxxxxxxxxxx - Thu Nov 18 23:17:39 2004]:
>
> OK, it seems you won't let me wriggle out of this one :-). A proper try
> this time.
>
> Self loathing leads to self harm: some additional assertions revealled
> the culprit to be the comparison
> ai->diplomacy.acceptable_reputation > aplayer->reputation
> That is, if the AI is a scum bag, he thinks he is a danger to himself.
Hehe! Good job.
> Attached is a patch, which fixes the problem, provides comments to
> document the peculiarities, and has assertions for checking the
> invariants that the is_player_dangerous function depends on, near where
> those invariants might be broken.
I am no so sure about peppering the asserts around. Might leave it to
Per. For now I want to fix the style and put a little comment into
already committed code, see the attachment.
Gr.
? civ.serv
? ttt
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.128
diff -u -r1.128 aitools.c
--- ai/aitools.c 18 Nov 2004 07:44:29 -0000 1.128
+++ ai/aitools.c 19 Nov 2004 02:47:21 -0000
@@ -85,15 +85,17 @@
bool is_player_dangerous(struct player *pplayer, struct player *aplayer)
{
struct ai_data *ai = ai_data_get(pplayer);
- struct ai_dip_intel *adip
- = &ai->diplomacy.player_intel[aplayer->player_no];
+ struct ai_dip_intel *adip = &ai->diplomacy.player_intel[aplayer->player_no];
+ int reason = pplayer->diplstates[aplayer->player_no].has_reason_to_cancel;
- return (pplayer != aplayer)
- && ((pplayers_at_war(pplayer, aplayer)
- || ai->diplomacy.target == aplayer
- || pplayer->diplstates[aplayer->player_no].has_reason_to_cancel != 0
- || ai->diplomacy.acceptable_reputation > aplayer->reputation
- || adip->is_allied_with_enemy));
+ /* Have to check if aplayer == pplayer explicitly because our reputation
+ * can be so low that we'd fear being stabbed in the back by ourselves */
+ return (pplayer != aplayer
+ && (pplayers_at_war(pplayer, aplayer)
+ || ai->diplomacy.target == aplayer
+ || reason != 0
+ || ai->diplomacy.acceptable_reputation > aplayer->reputation
+ || adip->is_allied_with_enemy));
}
/*************************************************************************
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Benedict Adamson, 2004/11/15
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Benedict Adamson, 2004/11/15
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Gregory Berkolaiko, 2004/11/15
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Benedict Adamson, 2004/11/16
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Benedict Adamson, 2004/11/16
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Jason Short, 2004/11/16
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units], Benedict Adamson, 2004/11/18
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Gregory Berkolaiko, 2004/11/18
- [freeciv-ai] (PR#11009) AI Hunts Own Units, Jason Short, 2004/11/18
- [freeciv-ai] Re: (PR#11009) AI Hunts Own Units, Benedict Adamson, 2004/11/19
- [freeciv-ai] (PR#11009) AI Hunts Own Units,
Gregory Berkolaiko <=
- [freeciv-ai] (PR#11009) AI Hunts Own Units, Benedict Adamson, 2004/11/20
|
|