[Freeciv-Dev] Re: (PR#14763) Advanced govt patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14763 >
Benedict Adamson wrote:
>>The reason for this approach is 1) that the current governments evaluation
>>code became unviable with 5x5x6 combinations of governments, and 2) it
>>seemed superfluous to make the AI choose a personality and then select the
>>governments that suited its personality, when it the AI instead could
>>_express_ its personality through its choice of governments and diplomatic
>>actions.
>
>
> But what if more than one kind of government can express the AI's
> personality? How is the AI to choose between them?
Government evaluation is something that does not have to be done during
the AI player's "turn" (there are other AI operations, like city
management, that also fit into this category).
With a slightly different server model, the AI work for these operations
could be done while the human player is moving. (The CM is already
designed to work in exactly this fashion, containing a "state" and
operating in discrete steps.) All that is needed is to generalize this
mechanism to the top-level AI; if the state of the AI's operations is
stored globally it is possible to break all actions down into smaller
steps, and we can then do these steps while the human player is moving.
The code in main_loop then becomes:
bool done = FALSE;
while (!done && sniff_packets(done) == 1) {
done = do_one_ai_step();
}
This allows not only AI actions to be done while humans are moving, but
even after all humans are moving and the AI keeps evaluating
governments, human interaction is possible. The changes to main_loop
and sniff_packets are trivial; of course the hard part is in
do_one_ai_step. The drawback is potentially higher latency on human
actions, if any single do_one_ai_step() call takes too long, or lower
efficiency of AI actions if do_one_ai_step doesn't take long enough
(since then we end up polling the network too much).
The same is possible using threading of course. Threading has the
advantages of working better on multiprocessor machines, and solves both
disadvantages of the above system (neither latency nor polling is a
problem). However it has the disadvantage of requiring locking, and in
general will be more work, more bug-prone, and harder to debug.
-jason
|
|