Example #1
0
bool ai_action(Player *player, Board *board, Players *players, enum State *state) {
    bool end_turn = false;

    PairStack *fields_adjacent_enemies = create_pair_stack();
    PairStack *fields_adjacent_neutrals = create_pair_stack();

    create_fields_adjacent(fields_adjacent_enemies, fields_adjacent_neutrals, player, board);

    switch (*state) {
        case START:
            end_turn = ai_start(player, board);
            break;
        case REINFORCEMENT:
            ai_reinforcement(player, board, state, fields_adjacent_enemies, fields_adjacent_neutrals);
            break;
        case MOVE:
            end_turn = ai_move(player, board, state, players, fields_adjacent_enemies, fields_adjacent_neutrals);
            break;
        default:
            break;
    }

    SDL_Delay(50);

    delete_pair_stack(fields_adjacent_enemies);
    delete_pair_stack(fields_adjacent_neutrals);

    return end_turn;
}
Example #2
0
static void		player_play(t_game *game, int turn)
{
	if ((turn % 2) + 1 == game->ai)
		ai_move(game, (turn % 2) + 1);
	else
		player_move(game, (turn % 2) + 1);
}
Example #3
0
void
ai_stand2(edict_t *self, float dist)
{
  	if (!self)
	{
		return;
	}

	if (self->spawnflags & 8)
	{
		ai_move(self, dist);

		if (!(self->spawnflags & 1) && (self->monsterinfo.idle) &&
			(level.time > self->monsterinfo.idle_time))
		{
			if (self->monsterinfo.idle_time)
			{
				self->monsterinfo.idle(self);
				self->monsterinfo.idle_time = level.time + 15 + random() * 15;
			}
			else
			{
				self->monsterinfo.idle_time = level.time + random() * 15;
			}
		}
	}
	else
	{
		ai_stand(self, dist);
	}
}
Example #4
0
static void entity_update_movement(float secs)
{
    entity  *ent;

    for( ent = root ;  ent != NULL ; ent = ent->next ) {
	if( ent->mode >= ALIVE && ent->ai && ent->controller == CTRL_AI ) {
	    switch( ent->ai ) {
	    case AI_NONE:
		break;
	    case AI_FIGHT:
		if( ent->weapon ) {
		    ai_shooter_think(ent);
		} else
		    ai_fight_think(ent);
		break;
	    case AI_FLEE:
		ai_flee_think(ent);
		break;
	    case AI_SEEK:
		ai_seek_think(ent);
		break;
	    case AI_ROTATE:
		ai_rotate_think(ent);
		break;
	    default:
		break;
	    }
	    ai_move(ent);
	}

	if( ent->class != PROJECTILE )
	    world_friction(ent, secs);

	if( ent->mode >= ALIVE ) {
	    if( ent->x_v > 0 ) {
		if( ent->x_v > ent->speed )
		    ent->x_v = ent->speed;
	    } else if( ent->x_v < 0 ) {
		if( ent->x_v < -ent->speed )
		    ent->x_v = -ent->speed;
	    }
	
	    if( ent->y_v > 0 ) {
		if( ent->y_v > ent->speed )
		    ent->y_v = ent->speed;
	    } else if( ent->y_v < 0 ) {
		if( ent->y_v < -ent->speed )
		    ent->y_v = -ent->speed;
	    }
	}

	world_check_entity_move(ent, secs);

    }

}
Example #5
0
/*
 * Mob autonomous action.
 * This function takes 25% to 35% of ALL Merc cpu time.
 * -- Furey
 */
void mobile_update (void)
{
    CHAR_DATA *ch;
    CHAR_DATA *ch_next;
    CHAR_DATA *rch;

    /* Examine all mobs. */
    for (ch = char_list; ch != NULL; ch = ch_next)
    {
        ch_next = ch->next;

        if (!IS_NPC (ch) || ch->in_room == NULL) continue;

        if (ch->in_room->area->empty && !IS_SET (ch->act, ACT_UPDATE_ALWAYS))
            continue;

        if (ch->pIndexData->pShop != NULL)    /* give him some gold */
            if ((ch->gold * 100 + ch->silver) < ch->pIndexData->wealth)
            {
                ch->gold +=
                    ch->pIndexData->wealth * number_range (1, 20) / 5000000;
                ch->silver +=
                    ch->pIndexData->wealth * number_range (1, 20) / 50000;
            }


        /* That's all for sleeping / busy monster, and empty zones */
        if (ch->position != POS_STANDING)
            continue;
            
    for (rch = ch->in_room->people; rch != NULL; rch = rch->next_in_room)
    {
    if(rch->infight && !ch->infight && IS_NPC(ch) && !ch->pIndexData->pShop)
    {
    do_autodisp(ch," ");
    do_join(ch,"none");
    }
    }

            if(IS_NPC(ch) && ch->infight && TURN(ch))
            ai_move(ch);
        
    }

    return;
}
Example #6
0
int main(int argc, char **argv)
{
    struct gamestate *g = gamestate_init(argc, argv);
    struct gfx_state *s;

    if (g->opts->interactive)
        s = gfx_init(g);

    int game_running = true;
    while (game_running) {

        if (g->opts->interactive)
            gfx_draw(s, g);

get_new_key:;
        int direction = dir_invalid;
        int value = !g->opts->ai ? gfx_getch(s) : ai_move(g);
        switch (value) {
            case 'h':
            case 'a':
                direction = dir_left;
                break;
            case 'l':
            case 'd':
                direction = dir_right;
                break;
            case 'j':
            case 's':
                direction = dir_down;
                break;
            case 'k':
            case 'w':
                direction = dir_up;
                break;
            case 'q':
                game_running = false;
                break;
            default:
                goto get_new_key;
        }

        /* Game will only end if 0 moves available */
        if (game_running) {
            gamestate_tick(s, g, direction, g->opts->animate && g->opts->interactive
                    ? draw_then_sleep : NULL);

            int spawned;
            for (spawned = 0; spawned < g->opts->spawn_rate; spawned++)
                gamestate_new_block(g);

            if (gamestate_end_condition(g)) {
                game_running = false;
            }
        }
    }

    if (g->opts->interactive) {
        // gfx_getch(s);   // getch here would be good,
                         // need an exit message for each graphical output
        gfx_destroy(s);
    }

    printf("%ld\n", g->score);
    gamestate_clear(g);
    return 0;
}
Example #7
0
static int cfun_ai_check_move(lua_State *L)
{
	return ai_move(L, false, false);
}
Example #8
0
static int cfun_ai_execute_move_partial(lua_State *L)
{
	return ai_move(L, true, false);
}
Example #9
0
static int cfun_ai_execute_move_full(lua_State *L)
{
	return ai_move(L, true, true);
}