Author: cazfi Date: Mon Jan 25 04:13:40 2016 New Revision: 31581 URL: http://svn.gna.org/viewcvs/freeciv?rev=31581&view=rev Log: Move ai_fuzzy() from common/player.c to ai/difficulty.c
See patch #5915 Modified: branches/S2_6/ai/default/advmilitary.c branches/S2_6/ai/default/aicity.c branches/S2_6/ai/default/aiunit.c branches/S2_6/ai/difficulty.c branches/S2_6/ai/difficulty.h branches/S2_6/common/player.c branches/S2_6/common/player.h Modified: branches/S2_6/ai/default/advmilitary.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/advmilitary.c?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/ai/default/advmilitary.c (original) +++ branches/S2_6/ai/default/advmilitary.c Mon Jan 25 04:13:40 2016 @@ -47,6 +47,7 @@ #include "infracache.h" /* adv_city */ /* ai */ +#include "difficulty.h" #include "handicaps.h" /* ai/default */ Modified: branches/S2_6/ai/default/aicity.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aicity.c?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/ai/default/aicity.c (original) +++ branches/S2_6/ai/default/aicity.c Mon Jan 25 04:13:40 2016 @@ -47,6 +47,7 @@ /* ai */ #include "aitraits.h" +#include "difficulty.h" #include "handicaps.h" /* ai/default */ Modified: branches/S2_6/ai/default/aiunit.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiunit.c?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/ai/default/aiunit.c (original) +++ branches/S2_6/ai/default/aiunit.c Mon Jan 25 04:13:40 2016 @@ -34,7 +34,6 @@ #include "map.h" #include "movement.h" #include "packets.h" -#include "player.h" #include "specialist.h" #include "traderoutes.h" #include "unit.h" @@ -62,6 +61,7 @@ #include "autosettlers.h" /* ai */ +#include "difficulty.h" #include "handicaps.h" /* ai/default */ Modified: branches/S2_6/ai/difficulty.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/difficulty.c?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/ai/difficulty.c (original) +++ branches/S2_6/ai/difficulty.c Mon Jan 25 04:13:40 2016 @@ -17,6 +17,7 @@ /* utility */ #include "bitvector.h" +#include "rand.h" /* common */ #include "player.h" @@ -214,3 +215,30 @@ return 100; } + +/************************************************************************** + Return the value normal_decision (a boolean), except if the AI is fuzzy, + then sometimes flip the value. The intention of this is that instead of + if (condition) { action } + you can use + if (ai_fuzzy(pplayer, condition)) { action } + to sometimes flip a decision, to simulate an AI with some confusion, + indecisiveness, forgetfulness etc. In practice its often safer to use + if (condition && ai_fuzzy(pplayer,1)) { action } + for an action which only makes sense if condition holds, but which a + fuzzy AI can safely "forget". Note that for a non-fuzzy AI, or for a + human player being helped by the AI (eg, autosettlers), you can ignore + the "ai_fuzzy(pplayer," part, and read the previous example as: + if (condition && 1) { action } + --dwp +**************************************************************************/ +bool ai_fuzzy(const struct player *pplayer, bool normal_decision) +{ + if (!pplayer->ai_controlled || pplayer->ai_common.fuzzy == 0) { + return normal_decision; + } + if (fc_rand(1000) >= pplayer->ai_common.fuzzy) { + return normal_decision; + } + return !normal_decision; +} Modified: branches/S2_6/ai/difficulty.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/difficulty.h?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/ai/difficulty.h (original) +++ branches/S2_6/ai/difficulty.h Mon Jan 25 04:13:40 2016 @@ -15,4 +15,6 @@ void set_ai_level_directer(struct player *pplayer, enum ai_level level); +bool ai_fuzzy(const struct player *pplayer, bool normal_decision); + #endif /* FC__DIFFICULTY_H */ Modified: branches/S2_6/common/player.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.c?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/common/player.c (original) +++ branches/S2_6/common/player.c Mon Jan 25 04:13:40 2016 @@ -19,7 +19,6 @@ #include "fcintl.h" #include "log.h" #include "mem.h" -#include "rand.h" #include "shared.h" #include "support.h" @@ -1186,33 +1185,6 @@ } } city_list_iterate_end; return NULL; -} - -/************************************************************************** -Return the value normal_decision (a boolean), except if the AI is fuzzy, -then sometimes flip the value. The intention of this is that instead of - if (condition) { action } -you can use - if (ai_fuzzy(pplayer, condition)) { action } -to sometimes flip a decision, to simulate an AI with some confusion, -indecisiveness, forgetfulness etc. In practice its often safer to use - if (condition && ai_fuzzy(pplayer,1)) { action } -for an action which only makes sense if condition holds, but which a -fuzzy AI can safely "forget". Note that for a non-fuzzy AI, or for a -human player being helped by the AI (eg, autosettlers), you can ignore -the "ai_fuzzy(pplayer," part, and read the previous example as: - if (condition && 1) { action } ---dwp -**************************************************************************/ -bool ai_fuzzy(const struct player *pplayer, bool normal_decision) -{ - if (!pplayer->ai_controlled || pplayer->ai_common.fuzzy == 0) { - return normal_decision; - } - if (fc_rand(1000) >= pplayer->ai_common.fuzzy) { - return normal_decision; - } - return !normal_decision; } /************************************************************************** Modified: branches/S2_6/common/player.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.h?rev=31581&r1=31580&r2=31581&view=diff ============================================================================== --- branches/S2_6/common/player.h (original) +++ branches/S2_6/common/player.h Mon Jan 25 04:13:40 2016 @@ -414,8 +414,6 @@ struct city *player_capital(const struct player *pplayer); -bool ai_fuzzy(const struct player *pplayer, bool normal_decision); - const char *love_text(const int love); enum diplstate_type cancel_pact_result(enum diplstate_type oldstate); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits