aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-04-04 15:57:34 -0400
committerNathan Vance <nathav63@gmail.com>2015-04-04 15:57:34 -0400
commit2e517f83554f072abf57800f06d26aea9fb51d52 (patch)
tree37e93d9255512b6c61b6a43e318b095ff471adad
parentCan now see history of previous turn (diff)
download7w-2e517f83554f072abf57800f06d26aea9fb51d52.tar.gz
7w-2e517f83554f072abf57800f06d26aea9fb51d52.tar.bz2
7w-2e517f83554f072abf57800f06d26aea9fb51d52.zip
ai trading bug fixes
-rw-r--r--ai.c2
-rw-r--r--ai_trade.c22
-rw-r--r--data.c2
-rw-r--r--trade.c3
4 files changed, 18 insertions, 11 deletions
diff --git a/ai.c b/ai.c
index b872ef5..4b84e77 100644
--- a/ai.c
+++ b/ai.c
@@ -66,6 +66,8 @@ void ai_turn(int player)
for(i = 0; i < 2; i++) {
data_addgold(bestcard[2+i], data_getdir(i, player));
}
+ //data_addgold(bestcard[2], data_geteast(player));
+ //data_addgold(bestcard[3], data_getwest(player));
write_trade(player, bestcard[2], bestcard[3]);
data_addgold(bestcard[4] * -1, player);
return;
diff --git a/ai_trade.c b/ai_trade.c
index 2cdc35b..00b9ea3 100644
--- a/ai_trade.c
+++ b/ai_trade.c
@@ -8,9 +8,10 @@ This class is designed for the sole purpose of analyzing potential transactions
int data_getgold(int p);
int get_trade(int player, int type, int direction);
int data_canafford(int p, int era, int card);
-void trade_clear(int player);
void trade_set(int player, int trade[3][GOLD]);
int* trade_gettradables(int player, int direction);
+int data_gettotvps(int p);
+int data_getdir(int dir, int p);
void ai_cleartrade(int trade[3][GOLD])
{
@@ -22,8 +23,7 @@ void ai_cleartrade(int trade[3][GOLD])
int recurse(int ret[], int cost, int trade[3][GOLD], int player, int era, int card)
{
- int i, j;
- int tradea, tradeb;
+ int i, j, k;
if(data_canafford(player, era, card)) {
if(cost < ret[2] || ret[2] == 0) {
ret[2] = cost;
@@ -36,15 +36,19 @@ int recurse(int ret[], int cost, int trade[3][GOLD], int player, int era, int ca
}
return 1; //if we can afford it, don't bother recursing further.
}
- for(i = 0; i < 2; i++) {
+ for(k = 0; k < 2; k++) {
+ if(data_gettotvps(data_getdir(0, player)) > data_gettotvps(data_getdir(1, player)))
+ i = 0;
+ else i = 1;
+ if(k) i = (i-1)*-1; //The preceeding block selects the weaker neighbor for trade preference.
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) {
- tradea = trade[i][j]++;
- tradeb = trade[2][j]++;
+ if(data_getgold(player) - cost - get_trade(player, j, i) >= 0 && trade_gettradables(player, i)[j] - trade[i][j] >= trade[i][j]+1) {
+ trade[i][j]++;
+ trade[2][j]++;
trade_set(player, trade);
if(recurse(ret, cost+get_trade(player, j, i), trade, player, era, card)) return 1;
- trade[i][j] = tradea;
- trade[2][j] = tradeb;
+ trade[i][j]--;
+ trade[2][j]--;
}
}
}
diff --git a/data.c b/data.c
index 2372672..e6cbac1 100644
--- a/data.c
+++ b/data.c
@@ -124,6 +124,7 @@ void data_endturn()
data_discard((i+numplayers-turn)%numplayers, hands[i][0]);
}
}
+ for(i = 0; i < 7; i++) turngoldbuffer[i] = 0; //Clear the visible buffer, the real one will be processed later.
if(era == 0 || era == 2) //pass to the left
turn++;
else //pass to the right
@@ -182,6 +183,7 @@ int data_geteast(int p)
{
int ret = p-1;
if(ret < 0) ret = numplayers-1;
+ return ret;
}
int data_getwest(int p)
diff --git a/trade.c b/trade.c
index d78fe4f..1a187b1 100644
--- a/trade.c
+++ b/trade.c
@@ -53,13 +53,12 @@ void trade_clear(int player)
void trade_set(int player, int trade[3][GOLD])
{
- trade_clear(player);
int i, j;
for(i = 0; i < 3; i++) {
for(j = 0; j < GOLD; j++) {
tradebuffer[i][j] = trade[i][j];
- tradebuffer[i][GOLD] = 0; //we deal with gold in the method that calls this
}
+ tradebuffer[i][GOLD] = 0; //we deal with gold in the method that calls this
}
}
bgstack15