aboutsummaryrefslogtreecommitdiff
path: root/test/test_gst.c
blob: d54e15c03e22b54b75aeb0a095da1b331e3ef210 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>

#include "test.h"

#include "../gst/fxs.h"
#include "../gst/gst.h"

int test_gst_mirror_match (infos *info, int n);
    
    
int test_gst_run (infos *info) {
    int result = 0;
    for (int i=0; i<1; i++) {
        result += test_gst_mirror_match(info, i);
    }
    return result;
}

int test_gst_mirror_match (infos *info, int n) {
    if(TEST_VERBOSE) printf("test_gst: mirror match __test%d\n", n);
    fxs fx;
    fx_init(&fx);
    gamestate gst;
    gst_init(&gst);
    
    char name[64]; sprintf(name, "hidden/__test%d", n);
    info_load_army(gst.army_bp+0, name);
    info_load_army(gst.army_bp+1, name);
    gst.playernum = 2;
    gst_tobattle(&gst, info);
    
    float t = 0; int i=0;
    for (; i < 2000; i++) {
        gst_next_turn(&gst, info, &fx, t);
        t += gst.turnspeed;
        if (gst.over == 1) {
            break;
        }
    }
    if (i < 2000) {
        if(TEST_VERBOSE) printf("test_gst: %d turns\n", i);
        int winner = gst_check_victory(&gst);
        if (winner == -1) {
            if(TEST_VERBOSE) printf("test_gst success: draw\n");
        } else {
            printf("test_gst failed: not draw (%d)\n", winner);
            return 1;
        }
        gst_destroy(&gst);
        return 0;
    }
    return 1;
}