aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai.c16
-rw-r--r--ai_trade.c16
-rw-r--r--ai_weights.c19
-rw-r--r--data.c15
-rw-r--r--history.c66
-rw-r--r--player_turn.c4
-rw-r--r--view.c2
7 files changed, 119 insertions, 19 deletions
diff --git a/ai.c b/ai.c
index e9a1bdf..b872ef5 100644
--- a/ai.c
+++ b/ai.c
@@ -13,12 +13,13 @@ void data_buildwonder(int p, int card);
void data_addgold(int amnt, int p);
int wonder_numstages(int player);
int weight_buildcard(int era, int card, int player);
-int weight_buildwonder(int player);
+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);
+void write_trade(int player, int tradel, int trader);
int* ai_bestcard(int *hand, int player) //return card
{
@@ -54,22 +55,29 @@ void ai_turn(int player)
{
int *bestcard;
int *hand = data_gethand(player);
- int wonder = 0;
+ int *wonder = get_intarray(4);
+ wonder[0] = 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) {
+ if(bestcard[0] > wonder[0] && bestcard[0] > 0) {
data_build(player, bestcard[1]);
for(i = 0; i < 2; i++) {
data_addgold(bestcard[2+i], data_getdir(i, player));
}
+ write_trade(player, bestcard[2], bestcard[3]);
data_addgold(bestcard[4] * -1, player);
return;
}
bestcard = ai_bestcard(hand, data_getnext(player));
- if(wonder > 0) {
+ if(wonder[0] > 0) {
data_buildwonder(player, bestcard[1]);
+ for(i = 0; i < 2; i++) {
+ data_addgold(wonder[1+i], data_getdir(i, player));
+ }
+ write_trade(player, wonder[1], wonder[2]);
+ data_addgold(wonder[3] * -1, player);
return;
}
data_discard(player, bestcard[1]);
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)
diff --git a/ai_weights.c b/ai_weights.c
index f614fe9..67fbd8e 100644
--- a/ai_weights.c
+++ b/ai_weights.c
@@ -16,9 +16,11 @@ int get_trade(int player, int type, int direction);
int cards_gettype(int era, int card);
int* get_science(int player);
int* get_special(int era, int card, int player);
+int* get_intarray(int size);
int data_potentialvps(int p, int era, int card);
int data_gettotvps(int p);
int military_might(int player);
+int* ai_trade(int player, int era, int card);
int weight_science(int era, int card, int player)
{
@@ -126,8 +128,19 @@ int weight_buildcard(int era, int card, int player)
return weight;
}
-int weight_buildwonder(int player)
+int* weight_buildwonder(int player)
{
- if(! data_canafford(player, data_getwonder(player), data_getnextwonderstage(player))) return 0;
- return (data_getwonderstages(player)+2) * 2;
+ int *trade = get_intarray(3);
+ static int ret[4];
+ ret[0] = (data_getwonderstages(player)+2) * 2;
+ ret[1] = ret[2] = ret[3] = 0;
+ if(data_canafford(player, data_getwonder(player), data_getnextwonderstage(player)) != 1) {
+ trade = ai_trade(player, data_getwonder(player), data_getnextwonderstage(player));
+ if(trade[2]) ret[0] -= trade[2] / 3;
+ else ret[0] = 0;
+ ret[1] = trade[0];
+ ret[2] = trade[1];
+ ret[3] = trade[2];
+ }
+ return ret;
}
diff --git a/data.c b/data.c
index a14c074..2372672 100644
--- a/data.c
+++ b/data.c
@@ -21,6 +21,9 @@ int io_printtext(int xorigin, int y, int width, char* text);
int io_getkey();
int data_haswonderstage(int p, int wonder, int stage);
void special_action(int player, int wonder, int stage);
+void clear_history();
+void write_purchase(int player, int era, int card, int type);
+void write_trade(int player, int tradel, int trader);
#define MISC 3
#define DATAGOLD 0
@@ -82,7 +85,7 @@ void data_distributewonders()
for(i = 0; i < numplayers; i++) {
player[i][3][0] = wonders[i];
player[i][3][1] = rand()%2;
- player[0][3][0] = 8; //delete these lines later
+ player[0][3][0] = 6; //delete these lines later
player[0][3][1] = 1; //this one too!
}
}
@@ -127,11 +130,15 @@ void data_endturn()
turn--;
if(turn < 0) turn = numplayers-1;
for(i = 0; i < numplayers; i++) {
- if(buffer[i][0] == -2) {
+ if(buffer[i][0] == -2) { //build wonder
player[i][3][2]++;
- } else {
+ write_purchase(i, -1, -1, 2);
+ } else if(buffer[i][0] != -1) { //bulid card
for(j = 0; player[i][era][j] != -1; j++); //get free spot in array
- player[i][era][j] = buffer[i][0]; //build card
+ player[i][era][j] = buffer[i][0];
+ write_purchase(i, era, buffer[i][0], 0);
+ } else { //sold card
+ write_purchase(i, -1, -1, 1);
}
player[i][3][3] += buffer[i][1]; //change in gold
player[i][3][6] += buffer[i][2];
diff --git a/history.c b/history.c
new file mode 100644
index 0000000..fa5fec7
--- /dev/null
+++ b/history.c
@@ -0,0 +1,66 @@
+#include "7w.h"
+#include <stdio.h>
+
+void io_printborder(int x, int y, int width);
+int io_printtext(int xorigin, int y, int width, char* text);
+void io_printname(int x, int y, int era, int card);
+
+static int history[7][6]; //goes card era, card, purchase type, trade left, trade right, extra stuff?
+static int ready;
+
+int write_history(int player, int x, int y)
+{
+ if(! ready) return y;
+ int width = 28;
+ io_printborder(x, y++, width);
+ y = io_printtext(x, y, width, "Activity last turn:");
+ if(history[player][2] == 0) { // Built card
+ y = io_printtext(x, y, width, " Purchased");
+ io_printname(x, y++, history[player][0], history[player][1]);
+ } else if(history[player][2] == 1) { // Sold card
+ y = io_printtext(x, y, width, " Sold a card");
+ } else { // Built wonder
+ y = io_printtext(x, y, width, " Built a wonder stage");
+ }
+ y = io_printtext(x, y, width, "Trade activity:");
+ if(history[player][3] || history[player][4]) {
+ char s[30];
+ if(history[player][3]) {
+ sprintf(s, " Traded %d gold to the east", history[player][3]);
+ y = io_printtext(x, y, width, s);
+ }
+ if(history[player][4]) {
+ sprintf(s, " Traded %d gold to the west", history[player][4]);
+ y = io_printtext(x, y, width, s);
+ }
+ } else {
+ y = io_printtext(x, y, width, " none");
+ }
+ io_printborder(x, y++, width);
+ return y;
+}
+
+void clear_history()
+{
+ ready = 0;
+ int i, j;
+ for(i = 0; i < 7; i++)
+ for(j = 0; j < 6; j++)
+ history[i][j] = 0;
+}
+
+void write_purchase(int player, int era, int card, int type)
+{
+ ready = 1;
+ history[player][0] = era;
+ history[player][1] = card;
+ history[player][2] = type;
+ //type 0 is build, 1 is sell, 2 is wonder
+}
+
+void write_trade(int player, int tradel, int trader)
+{
+ ready = 1;
+ history[player][3] = tradel;
+ history[player][4] = trader;
+}
diff --git a/player_turn.c b/player_turn.c
index da2e6f7..62e2ff4 100644
--- a/player_turn.c
+++ b/player_turn.c
@@ -26,6 +26,8 @@ int trade_routine(int x, int y, int player);
void trade_commit(int player);
int data_spendfreebuild();
int postyn(int x, int y, char *message);
+void write_trade(int player, int tradel, int trader);
+
void halt();
int player_build(int focus, int cursor, int player, int y)
@@ -54,7 +56,7 @@ int player_build(int focus, int cursor, int player, int y)
if(data_getnextwonderstage(player) == -1) {
postmessage("Wonder already complete.");
} else if(data_canafford(player, data_getwonder(player), data_getnextwonderstage(player))) {
- data_buildwonder(player, hand[cursor]);
+ data_buildwonder(player, hand[cursor]);
return 1;
} else postmessage("Can't afford this!");
}
diff --git a/view.c b/view.c
index 82dec18..006a74d 100644
--- a/view.c
+++ b/view.c
@@ -9,6 +9,7 @@ int data_numplayers();
void printmessage(int x, int y, int width);
int data_geteast(int p);
int data_getwest(int p);
+int write_history(int player, int x, int y);
int* view_printwonders(int focus, int cursor, int player)
{
@@ -25,6 +26,7 @@ int* view_printwonders(int focus, int cursor, int player)
ret = print_wonder(34, 0, p, cursor);
y = print_wondersmall(x, y, p, focus == p, dir);
}
+ y = write_history(focus, 0, y);
printmessage(0, y+2, 35);
return ret;
}
bgstack15