blob: 22bd8638292d7a8c49d627e0419515dcb928a21f (
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
54
55
56
|
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include "constantes.h"
#include "structures.h"
#include "prototypes.h"
#include <time.h>
#include "actions.h"
static struct chr_t *ai_find_random_target(const struct team_t *team)
{
int alive = 0;
int target_idx;
for (int i = 0; i < team->chr_cnt; ++i) {
if (team->chrs[i].alive)
++alive;
}
target_idx = rand() % alive;
alive = 0;
for (int i = 0; i < team->chr_cnt; ++i) {
if (team->chrs[i].alive) {
if (alive == target_idx)
return &team->chrs[i];
++alive;
}
}
/* no one is alive */
return NULL;
}
void ai_play_turn(struct action_params_t *params)
{
/* XXX complete brainless articial intelligence */
struct team_t *target_team;
struct target_t target;
target.is_chr = true;
target_team = (params->src->team == params->t1) ? params->t2 : params->t1;
target.chr = ai_find_random_target(target_team);
if (target.chr == NULL) {
/* do nothing, everyone is dead */
return;
}
attack(params->surfaces, params->positions, params->src, &target, NULL);
}
|