bnordli / rftg

Race for the Galaxy AI
173 stars 32 forks source link

AI should not evaluate (Prestige) actions that a player cannot perform #42

Closed bnordli closed 7 years ago

bnordli commented 7 years ago

In predict_action, the AI evaluates all possible actions of an opponent. This even includes Prestige actions when a player does not have any Prestige, or the Search action, even when the Prestige action is used.

The AI should simply set act_scores[i] = 0 for all illegal actions.

Found in this save game

RFTG Save
0.9.5
1482186383
5 3
0 1 0
none
154 1 0 2 52 45 1 183 0 0 2 2 -1 0 2 0 2 125 114 0 5 214 3 214 86 10 0 6 0 2 10 86 0 5 -1 1 136 0 0 0 2 2 -1 0 2 0 2 31 189 0 5 -1 0 0 0 0 2 133 -1 0 2 0 2 1 27 0 5 -1 0 0 5 207 3 135 207 136 0 6 0 2 135 204 0 15 0 1 207 2 207 1 0 0 2 9 -1 0 2 0 3 130 68 35 0 5 30 4 196 137 30 136 0 6 0 5 136 137 196 42 56 0 0 0 2 7 -1 0 5 -1 0 0 12 0 1 30 0 15 0 1 207 2 207 1 0 0 2 9 -1 0 2 0 3 146 157 192 0 
147 1 0 2 43 47 1 3 0 0 2 5 -1 0 2 0 1 94 0 5 -1 2 201 21 0 5 95 2 226 95 0 6 0 0 0 0 0 2 3 -1 0 2 0 1 202 0 5 21 3 161 201 21 0 0 0 2 2 -1 0 2 0 1 48 0 5 161 3 89 161 201 0 6 0 3 89 209 226 0 5 -1 2 20 180 0 0 0 2 5 -1 0 2 0 1 160 0 5 174 3 174 20 180 0 6 0 0 1 21 0 0 2 7 -1 0 5 20 3 75 20 180 0 12 0 1 174 0 2 0 1 159 0 0 0 2 9 -1 0 2 0 3 83 77 152 0 2 0 1 179 0 
165 1 0 2 16 147 1 182 0 0 2 3 -1 0 2 0 3 46 108 224 0 5 158 2 18 158 0 5 -1 1 29 0 0 0 2 3 -1 0 2 0 3 26 98 13 0 5 18 1 18 0 6 0 0 0 13 0 1 158 1 1 14 0 1 91 0 0 0 2 7 -1 0 2 0 3 58 120 32 0 5 221 1 221 0 6 0 2 29 225 1 158 5 62 1 62 0 6 0 1 8 0 12 0 1 62 0 13 0 0 0 0 0 2 9 -1 0 2 0 3 171 60 198 0 5 107 2 107 72 0 6 0 1 37 0 0 0 2 7 -1 0 5 -1 1 72 0 12 0 1 62 0 13 0 0 0 0 0 2 9 -1 0 2 0 3 128 208 111 0 
161 1 0 2 92 154 1 116 2 0 1 103 0 0 0 2 3 -1 0 2 0 1 78 0 5 199 1 199 0 5 -1 0 0 0 0 2 7 -1 0 2 0 2 9 82 0 5 -1 0 0 12 0 1 116 0 0 0 2 3 -1 0 2 0 2 186 155 0 5 25 3 25 213 145 0 5 99 6 99 167 216 11 73 74 0 6 0 1 167 1 25 0 0 2 5 -1 0 2 0 2 36 148 0 5 80 6 80 106 216 11 73 74 0 6 0 0 1 25 0 0 2 5 -1 0 5 73 6 176 106 216 11 73 74 0 6 0 0 1 25 0 0 2 130 -1 0 2 0 8 213 145 85 41 176 173 61 121 0 2 0 3 11 197 106 0 
159 1 0 2 57 112 1 138 0 0 2 5 -1 0 2 0 2 97 109 0 5 6 2 6 100 0 6 0 1 132 0 5 40 1 40 0 0 0 2 3 -1 0 2 0 2 178 76 0 5 163 2 163 100 0 6 0 3 87 96 100 0 0 0 2 3 -1 0 2 0 2 217 227 0 5 22 1 22 0 5 212 2 212 127 0 6 0 0 0 0 0 2 2 -1 0 2 0 2 187 69 0 5 -1 2 67 127 0 0 0 2 133 -1 0 5 175 3 175 67 127 0 6 0 0 0 13 0 4 163 163 40 6 4 0 0 0 1 13 0 1 40 1 0 15 0 1 175 2 40 0 0 0 2 9 -1 0 2 0 2 185 64 0 

resulting in "Couldn't find valid payment", because a player actually goes to negative Prestige and the code can't handle that.

(Note that this specific failure is a regression in 0.9.5, since in settle_legal, p_ptr->prestige > 0 was inverted to p_ptr->prestige == 0.)

Marsux commented 7 years ago

this seems weird since any inversion in the tests was not meant to change the behaviour of the function. Could you point to the implied source code line?

bnordli commented 7 years ago

https://github.com/bnordli/rftg/blob/d47f04451bc17aa1dff9fbc144054235ccc61310/src/engine.c#L3915

It was reasonable to negate prestige > 0 to prestige == 0, but this breaks down when prestige goes negative..

Marsux commented 7 years ago

Well, then it seems to me that the bug is then to allow for negative prestige. It does not have any sense in the context of the game, is it really necessary to accomodate for the possibility of having negative prestige?

bnordli commented 7 years ago

I agree with you: This is a bug in the AI.

So this boils down to whether/when we want to change the AI behavior (possibly retraining all nets). If we do not change the AI for the next release, we unfortunately have to deal with negative prestige.

dsnvwlmnt commented 7 years ago

"It does not have any sense in the context of the game, is it really necessary to accomodate for the possibility of having negative prestige?"

I don't fully know what you guys are saying, but if the AI is considering impossible states and making decisions based on that, then yes you might have to accomodate for negative prestige. So that it plays more correctly.

bnordli commented 7 years ago

On second thoughts, this only affects BoW, and is a fairly simple code change.

@Marsux, can you retrain the BoW nets if I make this change to the AI?

Marsux commented 7 years ago

yes

bnordli commented 7 years ago

Code is ready and pushed to master. @Marsux, will you start retraning the Brink of War nets?

ayao44 commented 7 years ago

Have all cases of this "Valid Payment" been accounted for? I'm still getting them even though it seems to be me that's causing these (as in the sole AI opponent doesn't have any dealings with Prestige). Details, and files available upon request.

bnordli commented 7 years ago

Sadly, not everything has been solved yet. I haven't had time to investigate further, but I have a repro that I can work on. I'll let you know when I think a fix is ready.

bnordli commented 7 years ago

Finally, I think I have fixed this. Can you see if the new code in master works better?

bnordli commented 7 years ago

Tests are looking very good. Closing this for now.