aboutsummaryrefslogtreecommitdiff
path: root/ai.c
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-03-24 12:34:19 -0400
committerNathan Vance <nathav63@gmail.com>2015-03-24 12:34:19 -0400
commit01d411a870580e368d6530a2eaacd9c828a258ce (patch)
tree3b429979de6008bc31b2643711b231cc9623b7b9 /ai.c
parentstarted thinking about ai trading (diff)
download7w-01d411a870580e368d6530a2eaacd9c828a258ce.tar.gz
7w-01d411a870580e368d6530a2eaacd9c828a258ce.tar.bz2
7w-01d411a870580e368d6530a2eaacd9c828a258ce.zip
Implemented ai trading (buggy)
Diffstat (limited to 'ai.c')
-rw-r--r--ai.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/ai.c b/ai.c
index 1eb8c11..e166585 100644
--- a/ai.c
+++ b/ai.c
@@ -5,6 +5,7 @@ int* data_gethand(int p);
int data_numcards(int p);
int data_getera();
int data_getnext(int p); //next recipient of the hand
+int data_getdir(int dir, int p);
int data_getwonderstages(int p);
void data_discard(int p, int card);
void data_build(int p, int card);
@@ -16,22 +17,34 @@ int weight_buildwonder(int player);
int* cards_getproduction(int era, int card);
int* cards_getcost(int era, int card);
int data_hasbuiltname(int p, int era, int card);
+int* get_intarray(int size);
+int* ai_trade(int player, int era, int card);
int* ai_bestcard(int *hand, int player) //return card
{
int i, temp;
int max = 0;
int card = 0;
+ int *trade = get_intarray(3);
+ static int ret[5];
for(i = 0; hand[i] != -1 && i < 7; i++) {
+ trade[0] = trade[1] = trade[2] = 0;
temp = weight_buildcard(data_getera(), hand[i], player);
- if(! data_canafford(player, data_getera(), hand[i]) || data_hasbuiltname(player, data_getera(), hand[i]))
+ if(data_hasbuiltname(player, data_getera(), hand[i]))
temp = 0;
+ else if(! data_canafford(player, data_getera(), hand[i])) {
+ trade = ai_trade(player, data_getera(), hand[i]);
+ if(trade[2]) temp -= trade[2] / 3;
+ else temp = 0;
+ }
if(temp > max) {
max = temp;
card = hand[i];
+ ret[2] = trade[0];
+ ret[3] = trade[1];
+ ret[4] = trade[2];
}
}
- static int ret[2];
ret[0] = max;
ret[1] = card;
return ret;
@@ -42,11 +55,16 @@ void ai_turn(int player)
int *bestcard;
int *hand = data_gethand(player);
int wonder = 0;
+ int i;
if(data_getwonderstages(player) < wonder_numstages(player))
wonder = weight_buildwonder(player);
bestcard = ai_bestcard(hand, player);
if(bestcard[0] > wonder && bestcard[0] > 0) {
data_build(player, bestcard[1]);
+ for(i = 0; i < 2; i++) {
+ data_addgold(bestcard[2+i], data_getdir(i, player));
+ }
+ data_addgold(bestcard[4] * -1, player);
return;
}
bestcard = ai_bestcard(hand, data_getnext(player));
bgstack15