aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai.c12
-rw-r--r--data.c18
-rw-r--r--main.c13
3 files changed, 29 insertions, 14 deletions
diff --git a/ai.c b/ai.c
index b872ef5..2f78a74 100644
--- a/ai.c
+++ b/ai.c
@@ -21,13 +21,13 @@ 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
+void ai_bestcard(int *hand, int player, int *ret)
{
int i, temp;
int max = 0;
int card = 0;
int *trade = get_intarray(3);
- static int ret[5];
+ for(i = 0; i < 5; i++) ret[i] = 0;
for(i = 0; hand[i] != -1 && i < 7; i++) {
trade[0] = trade[1] = trade[2] = 0;
temp = weight_buildcard(data_getera(), hand[i], player);
@@ -48,19 +48,18 @@ int* ai_bestcard(int *hand, int player) //return card
}
ret[0] = max;
ret[1] = card;
- return ret;
}
void ai_turn(int player)
{
- int *bestcard;
+ int bestcard[5];
int *hand = data_gethand(player);
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);
+ ai_bestcard(hand, player, bestcard);
if(bestcard[0] > wonder[0] && bestcard[0] > 0) {
data_build(player, bestcard[1]);
for(i = 0; i < 2; i++) {
@@ -70,7 +69,8 @@ void ai_turn(int player)
data_addgold(bestcard[4] * -1, player);
return;
}
- bestcard = ai_bestcard(hand, data_getnext(player));
+ ai_bestcard(hand, data_getnext(player), bestcard);
+ if(bestcard[0] == 0) bestcard[1] = hand[0];
if(wonder[0] > 0) {
data_buildwonder(player, bestcard[1]);
for(i = 0; i < 2; i++) {
diff --git a/data.c b/data.c
index ff59685..d8aa83c 100644
--- a/data.c
+++ b/data.c
@@ -25,6 +25,7 @@ void clear_history();
void write_purchase(int player, int era, int card, int type);
void write_trade(int player, int tradel, int trader);
void player_turn(int player);
+void haltError(char *message, int num);
#define MISC 3
#define DATAGOLD 0
@@ -218,10 +219,11 @@ int data_getnext(int p)
int* data_gethand(int p)
{
- int *ret = get_intarray(7);
+ //int *ret = get_intarray(7);
+ static int ret[7];
int i;
for(i = 0; i < 7; i++)
- ret[i] = hands[(p+turn)%numplayers][i];
+ ret[i] = hands[(p+turn)%numplayers][i];
return ret;
}
@@ -335,19 +337,21 @@ void data_deletediscard(int era, int card)
discards[era][i] = -1;
}
-void data_remove(int p, int card) //as in, removes it from the hand
+int data_remove(int p, int card) //as in, removes it from the hand
{
int i;
int *hand = hands[(p+turn)%numplayers];
- for(i = 0; hand[i] != card; i++);
+ for(i = 0; hand[i] != card && i < 7; i++);
+ if(i == 7) return 1;
for(; i < 6; i++) hand[i] = hand[i+1];
hand[6] = -1;
for(i = 0; i < 7; i++) turngoldbuffer[i] = 0; //end of turn
+ return 0;
}
void data_discard(int p, int card)
{
- data_remove(p, card);
+ if(data_remove(p, card)) haltError("Error discarding", totturns);
int i;
for(i = 0; discards[era][i] != -1 && i < 49; i++);
discards[era][i] = card;
@@ -370,7 +374,7 @@ void data_build(int p, int card)
data_addvps(cards_getproduction(era, card)[VP], p);
data_addgold(get_special(era, card, p)[1], p);
data_addgold(cards_getcost(era, card)[GOLD] * -1, p);
- data_remove(p, card);
+ if(data_remove(p, card)) haltError("Error building card", totturns);
}
void data_buildwonder(int p, int card)
@@ -380,7 +384,7 @@ void data_buildwonder(int p, int card)
data_addgold(cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[GOLD], p);
data_addvps(cards_getproduction(data_getwonder(p), data_getwonderside(p)*3+1+data_getwonderstages(p))[VP], p);
data_setspecialflag(p);
- data_remove(p, card);
+ if(data_remove(p, card)) haltError("Error building wonder", totturns);
}
//0 is non producing, 1 produces one kind of resource, 2 produces multiple resources
diff --git a/main.c b/main.c
index f37bba3..2bf5781 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
#include "7w.h"
#include <stdlib.h>
+#include <stdio.h>
void tester();
void io_init();
@@ -23,7 +24,17 @@ void halt()
exit(0);
}
-static int ais[7] = {0, 1, 1, 1, 1, 1, 1};
+void haltError(char *message, int num)
+{
+ endwin();
+ printf("Something has gone wrong, very wrong.\n");
+ printf(message);
+ printf("\n");
+ printf("Number associated with this error: %d\n", num);
+ exit(1);
+}
+
+static int ais[7] = {1, 1, 1, 1, 1, 1, 1};
main_routine()
{
bgstack15