Menu

Example AI in Prolog

John S.
% -------------------------------------------------
% ProLogic - Example AI Module v1.0
% -------------------------------------------------
% Empty event handlers - simply does nothing.
% -------------------------------------------------

:- module(prologic, [
    example_module_version/1,
    on_game_start/0,
    on_game_end/0,
    on_frame/0,
    on_send_text/1,
    on_receive_text/2,
    on_player_left/1,
    on_nuke_detect/1,
    on_unit_discover/1,
    on_unit_evade/1,
    on_unit_show/1,
    on_unit_hide/1,
    on_unit_create/1,
    on_unit_destroy/1,
    on_unit_morph/1,
    on_unit_renegade/1,
    on_save_game/1
    ]).

% :- consult('your_library_here').

example_module_version(X) :- X = 'Example AI Module v1.0'.

process_command('help') :-
    bwapi:broodwar(Game),
    prologic:version(Appname),
    concat(Appname, ', Example AI Module @ your service.', Message),
    bwapi:game_printf(Game, Message).

on_game_start :-
    bwapi:broodwar(Game),
    example_module_version(Ver),
    bwapi:game_printf(Game, Ver).

on_send_text(Text) :-
    process_command(Text).

on_receive_text(Player, Text) :-
    bwapi:player_getName(Player, PlayerName),
    bwapi:broodwar(Game),
    swritef(TextToSend, '%d, I am not programmed to answer you.', [PlayerName]),
    bwapi:game_sendText(Game, TextToSend).

% ********************
% Unimplemented events
% ********************

on_frame.
on_game_end.
on_player_left(_Player).
on_nuke_detect(_TargetPosition).
on_unit_discover(_Unit).
on_unit_evade(_Unit).
on_unit_show(_Unit).
on_unit_hide(_Unit).
on_unit_create(_Unit).
on_unit_destroy(_Unit).
on_unit_morph(_Unit).
on_unit_renegade(_Unit).
on_save_game(_GameName).


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.