1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2%
    3% FILE: CLIMA/main_swi.pl
    4%
    5%  AUTHOR	: Sebastian Sardina
    6%  email	: ssardina@cs.toronto.edu
    7%  WWW		: www.cs.toronto.edu/cogrobo
    8%  TYPE CODE	: system dependent predicates
    9%  TESTED	: SWI Prolog 5.6.24 under FC6 
   10%
   11% IndiGolog agent player for CLIMA-07
   12%
   13% Written for SWI Prolog http://www.swi-prolog.org/) running under Linux
   14%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   15%
   16%                             June 15, 2000
   17%
   18% This software was developed by the Cognitive Robotics Group under the
   19% direction of Hector Levesque and Ray Reiter.
   20%
   21%        Do not distribute without permission.
   22%        Include this notice in any copy made.
   23%
   24%
   25%         Copyright (c) 2000 by The University of Toronto,
   26%                        Toronto, Ontario, Canada.
   27%
   28%                          All Rights Reserved
   29%
   30% Permission to use, copy, and modify, this software and its
   31% documentation for non-commercial research purpose is hereby granted
   32% without fee, provided that the above copyright notice appears in all
   33% copies and that both the copyright notice and this permission notice
   34% appear in supporting documentation, and that the name of The University
   35% of Toronto not be used in advertising or publicity pertaining to
   36% distribution of the software without specific, written prior
   37% permission.  The University of Toronto makes no representations about
   38% the suitability of this software for any purpose.  It is provided "as
   39% is" without express or implied warranty.
   40% 
   41% THE UNIVERSITY OF TORONTO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
   42% SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
   43% FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TORONTO BE LIABLE FOR ANY
   44% SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
   45% RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
   46% CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
   47% CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   48% 
   49%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   50% 
   51% This is the top-level file for a Legolog application program.
   52% It consults all the necessary Legolog prolog files.
   53% In particular, the following is loaded:
   54%
   55%  (1) Load all libraries required. This includes the system dependant
   56%      ones for the specific Prolog plus general libraries
   57%  (2) Load the IndiGolog interpreter and the projector used
   58%  (3) Load the application code itself containing the background theory
   59%      of action plus the high-level program
   60%  (4) Specify which environments should be loaded and how 
   61%  (5) Specify how each action should be executed and how to translate
   62%      exogenous actions
   63%
   64% Moreover, the following is provided:
   65%
   66% -- main: Collects all the procedures named 'mainControl(N)' where
   67%          N is the number representing the N-th controller.
   68%          The user can select which controller to execute and the 
   69%          IndiGolog executor will be run on such controller
   70%
   71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   72
   73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   74% SET GLOBAL PARAMETERS AND GLOBAL VARIABLES/CONSTANTS USED
   75%  
   76%  These may be options to improve performance and variables/constants used
   77%  around the whole arquitecture
   78%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   79
   80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   81% (1) LOAD/COMPILE/IMPORT LIBRARIES, MODULES, ETC that may be required.
   82%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   83:- include('../../lib/systemvar').  % Global include code and Prolog init
   84:- consult('../../lib/alpha_star'). % Alpha* path finding
   85%:- use_module(library(chr)).
   86%:- reset_backquoted_string.
   87
   88
   89%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   90% (2,3) CONSULT NECESSARY FILES
   91%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   92
   93% 1 - Consult the IndiGolog system: top-level and evaluator
   94:- consult('../../Interpreters/indigolog').     % IndiGolog interpreter 
   95% :- consult('../../Eval/eval_know').               % LP evaluator
   96:- consult('../../Eval/evalbat').               % LP evaluator
   97
   98% 2 - Consult environment manager 
   99:- consult(['../../Env/env_man.pl']).         % Load environment manager
  100
  101% 3 - Consult application
  102:- consult(agent_bat).                          % Application code in IndiGolog
  103
  104
  105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  106% (4,5) ENVIRONMENTS TO LOAD
  107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  108:- dynamic 
  109	clima_agentID/2, 
  110	teammember/1, 
  111	mess_location/2,
  112	clima_location/2.  113
  114
  115% This is the address of the CLIMA GAME server environment
  116clima_location('tea.dyndns.org', 12300).
  117%clima_location(teahp, 12300).
  118%clima_location(localhost, 12300).
  119%clima_location('agentmaster.in.tu-clausthal.de', 12300).
  120
  121clima_agentID(participant1,1).	% default
  122
  123% set the agent ID and PASSWORD and the corresponding teammates
  124set_agentID(AgentId,PassId) :-
  125	retractall(clima_agentID(_,_)),
  126	assert(clima_agentID(AgentId, PassId)).
  127
  128
  129% This is the address and information for the MESSENGER environment
  130mess_location('tea.dyndns.org', 12340).
  131%mess_location('eon.cs.toronto.edu', 12340).
  132%mess_location('teahp, 12340).
  133%mess_location(localhost, 12340).
  134agentID(Id) :- clima_agentID(Id,_).
  135teammember(participant1).	% Default team-members
  136teammember(participant2).
  137teammember(participant3).
  138teammember(participant4).
  139teammember(participant5).
  140teammember(participant6).
  141
  142% set the team
  143set_team(ListPlayers) :- 
  144	retractall(teammember(_)), 
  145	member(Player, ListPlayers),
  146	assert(teammember(Player)),
  147	fail.
  148set_team(_).
  149
  150
  151% Port of environment manager has to be fixed in SWI
  152server_port(_).
  153%server_host('127.0.0.1').
  154server_host(localhost).
  155
  156
  157% Define what environment managers the application will use
  158:- ['../../Env/dev_managers'].              % Common facts (device_manager/4)
  159load_device(Env, Command, Address) :- 
  160	(clima_agentID(boss,_) ->	
  161	        member((Env,Type), [(messenger([quiet,debug(0)]), swi)])
  162	;
  163        	member((Env,Type), 
  164			[(clima07([debug(3)]), swi),(messenger([quiet,debug(0)]), swi)])
  165	),
  166        %member((Env,Type), [(clima07([debug(5)]), swi),(messenger([]), swi)]),
  167        (var(Address) -> 
  168             Host=null, Port=null ; 
  169             Address = [Host, Port]
  170        ),
  171        device_manager(Env, Type, Command, [Host, Port]).
  172
  173
  174
  175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  176% HOW TO EXECUTE ACTIONS: Environment + low-level Code
  177%        how_to_execute(Action, Environment, Code)
  178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  179how_to_execute(Action, messenger(_), Action) :-
  180	member(Action, [tell(_,_), broadcast(_)]), !.
  181how_to_execute(Action, clima07(_), Action) :-
  182	clima_action(Action).
  183
  184
  185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  186%   EXOGENOUS ACTION AND SENSING OUTCOME TRANSLATION
  187%          translateExogAction(Code, Action)
  188%          translateSensing(Action, Outcome, Value)
  189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  190translateExogAction(CodeAction, Action) :- 
  191	actionNum(Action, CodeAction).
  192
  193
  194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  195% MAIN PREDICATE - evaluate this to run demo
  196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  197
  198% golog team
  199golog1 :- set_golog_team, login(1,UserName, Pass), main(UserName,Pass).
  200golog2 :- set_golog_team, login(2,UserName, Pass), main(UserName,Pass).
  201golog3 :- set_golog_team, login(3,UserName, Pass), main(UserName,Pass).
  202golog4 :- set_golog_team, login(4,UserName, Pass), main(UserName,Pass).
  203golog5 :- set_golog_team, login(5,UserName, Pass), main(UserName,Pass).
  204golog6 :- set_golog_team, login(6,UserName, Pass), main(UserName,Pass).
  205boss :- set_golog_team, login(7,UserName, Pass), main(UserName,Pass).
  206
  207
  208
  209
  210% for the test server
  211%login(1,'GOLOGteam1',va5Liove).
  212%login(2,'GOLOGteam2','Aerai6Pa').
  213%login(3,'GOLOGteam3','Efool1lu').
  214%login(4,'GOLOGteam4',cahk6Oi7).
  215%login(5,'GOLOGteam5',iuY1soj5).
  216%login(6,'GOLOGteam6',deiZak5f).
  217
  218% for the contest server
  219login(1,'GOLOGteam1',lH9fsomB).
  220login(2,'GOLOGteam2',gEvak2OS).
  221login(3,'GOLOGteam3',nv1w2hTh).
  222login(4,'GOLOGteam4','4qRgWlgr').
  223login(5,'GOLOGteam5',j6J2iyYI).
  224login(6,'GOLOGteam6',z54IqyLb).
  225login(7,boss,null).
  226
  227set_golog_team :- 
  228	set_team(['GOLOGteam1','GOLOGteam2','GOLOGteam3','GOLOGteam4','GOLOGteam5','GOLOGteam6',boss]).
  229
  230
  231
  232
  233% set an agent player and go!
  234main(AgentId, PassId) :-
  235	set_agentID(AgentId,PassId), !,
  236	indigolog.	
  237
  238
  239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  240% PREDICATES WITH SYSTEM DEPENDENT CODE
  241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  242
  243:- set_option(debug_level,0).  244:- set_option(wait_step,0).  245:- set_option(debug_level,warn_off).  246
  247
  248run_firefox :-
  249        (    fork(child),
  250             exec(xterm)
  251        ;    true
  252        )