aboutsummaryrefslogtreecommitdiff
path: root/gst/gst.c
diff options
context:
space:
mode:
authorjacopo grandi <jak.sk8@hotmail.it>2021-02-20 00:11:23 +0100
committerjacopo grandi <jak.sk8@hotmail.it>2021-02-20 00:11:23 +0100
commit2eef87c8970db643c4ef09e0fd9e8110c8193043 (patch)
tree78a9bcc7932ab8edb8669ded755ee2c81afc0912 /gst/gst.c
parentc135f85fcdc1eeedd04e0c9e9f626b907500f20a (diff)
finish condition and bad cost function
Diffstat (limited to 'gst/gst.c')
-rw-r--r--gst/gst.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/gst/gst.c b/gst/gst.c
index 09f3c1c..a97b4f9 100644
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -66,6 +66,24 @@ void gst_tobattle (gamestate *gst) {
gst->starttime = FLT_MAX;
gst->turn = 0;
gst->coveredtime = 0;
+ gst->turn_until_finish = 5;
+ gst->over = 0;
+}
+
+void gst_toeditor(gamestate *gst) {
+ gst->playernum = 1;
+}
+
+int gst_check_victory (gamestate *gst) {
+ int counts[gst->playernum], max=-1, imax = -1;
+ for (int i=0; i<gst->ar.uslen; i++) {
+ counts[gst->ar.us[i].owner] ++;
+ if (counts[gst->ar.us[i].owner] > max) {
+ imax = gst->ar.us[i].owner;
+ max = counts[gst->ar.us[i].owner];
+ }
+ }
+ return imax;
}
void gst_process (gamestate *gst, infos *info, float t) {
@@ -76,8 +94,15 @@ void gst_process (gamestate *gst, infos *info, float t) {
gst->turn ++;
map *m; army *ar;
gst_get_maparmy(gst, &m, &ar);
- army_move(info, ar, m);
- army_fire(info, ar, m);
+ int move = army_move(info, ar, m);
+ int fire = army_fire(info, ar, m);
army_upkeep(info, ar, m);
+ printf("%d, %d\n", move, fire);
+ if (move == 0 && fire == 0) {
+ gst->turn_until_finish--;
+ } else { gst->turn_until_finish = 5; }
+ if (gst->turn_until_finish <= 0) {
+ gst->over = 1;
+ }
}
} \ No newline at end of file