%%%----------------------------------------------------------------------
%%% File    : erbot.erl
%%% Author  : Luke Gorrie <luke@vegetable.org>
%%% Purpose : To seek out and destroy other robots!
%%% Created : 13 Apr 1999 by Luke Gorrie <luke@vegetable.org>
%%%----------------------------------------------------------------------

-module(erbot).
-author('luke@vegetable.org').

-include("corba.hrl").
-include("corba_GameInterface.hrl").
-include("corba_BotInterface.hrl").
-include("CosNaming.hrl").

-export([start/1, test/1]).

%% Read an IOR for a COS Naming service from a file, and use it
%% to lookup the game server.
start(IORFileName) ->
    {ok,IORFile} = file:open(IORFileName,[read]),
    IOR = io:get_line(IORFile, []),
    Naming = corba:string_to_object(IOR),
    NC = lname_component:set_id(lname_component:create(), "Game"),
    GameName = lname:insert_component(lname:create(), 1, NC),
    %% Next line causes the problem!
    GameServer ='CosNaming_NamingContext':resolve(Naming, GameName),
    Game = corba:call(GameServer, addPlayer, ["Luke","Erbot"]),
    play(Game).

%% Test function for going directly to the game object,
%% suffers the same "badarg" problem.
test(IORFileName) ->
    {ok, IORFile} = file:open(IORFileName, [read]),
    IOR = io:get_line(IORFile, []),
    Game = corba:string_to_object(IOR),
    io:format("~p~n", [Game]),
    corba_GameInterface:addPlayer(Game, "Luke", "Erbot").

play(Game) ->
    ok.

