aboutsummaryrefslogtreecommitdiff
path: root/ai_trade.c
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-04-03 19:21:20 -0400
committerNathan Vance <nathav63@gmail.com>2015-04-03 19:21:20 -0400
commite5cc06ddd5e6f725605ccabd312bcd5c5da2aa8c (patch)
tree42fde640ee2a6f3a0e85a74cb364805d8525abc5 /ai_trade.c
parentHalicarnassus bug fixes (diff)
download7w-e5cc06ddd5e6f725605ccabd312bcd5c5da2aa8c.tar.gz
7w-e5cc06ddd5e6f725605ccabd312bcd5c5da2aa8c.tar.bz2
7w-e5cc06ddd5e6f725605ccabd312bcd5c5da2aa8c.zip
Can now see history of previous turn
Diffstat (limited to 'ai_trade.c')
-rw-r--r--ai_trade.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/ai_trade.c b/ai_trade.c
index e45272e..2cdc35b 100644
--- a/ai_trade.c
+++ b/ai_trade.c
@@ -20,9 +20,10 @@ void ai_cleartrade(int trade[3][GOLD])
trade[i][j] = 0;
}
-void recurse(int ret[], int cost, int trade[3][GOLD], int player, int era, int card)
+int recurse(int ret[], int cost, int trade[3][GOLD], int player, int era, int card)
{
int i, j;
+ int tradea, tradeb;
if(data_canafford(player, era, card)) {
if(cost < ret[2] || ret[2] == 0) {
ret[2] = cost;
@@ -33,20 +34,21 @@ void recurse(int ret[], int cost, int trade[3][GOLD], int player, int era, int c
}
}
}
- return; //if we can afford it, don't bother recursing further.
+ return 1; //if we can afford it, don't bother recursing further.
}
for(i = 0; i < 2; i++) {
for(j = 0; j < GOLD; j++) {
if(data_getgold(player) - cost - get_trade(player, j, i) >= 0 && trade_gettradables(player, i)[j] >= trade[i][j]+1) {
- trade[i][j]++;
- trade[2][j]++;
+ tradea = trade[i][j]++;
+ tradeb = trade[2][j]++;
trade_set(player, trade);
- recurse(ret, cost+get_trade(player, j, i), trade, player, era, card);
- trade[i][j]--;
- trade[2][j]--;
+ if(recurse(ret, cost+get_trade(player, j, i), trade, player, era, card)) return 1;
+ trade[i][j] = tradea;
+ trade[2][j] = tradeb;
}
}
}
+ return 0;
}
int* ai_trade(int player, int era, int card)
bgstack15