Учебный Проект. Релиз 7. Класс Human: различия между версиями

Материал из wikiru.visual-prolog.com

м
м
 
(не показана 1 промежуточная версия этого же участника)
Строка 2: Строка 2:
<vip>
<vip>
/******************************************************
/******************************************************
Copyright (c) 2008. Prolog Development Center SPb
Copyright (c) Victor Yukhtenko
Written by: Victor Yukhtenko


Class human
Class human
Строка 77: Строка 76:
end implement human
end implement human
</vip>
</vip>
==Ссылки==
[[Category:Проекты]]
[[Category:Игры]]

Текущая версия на 17:16, 28 марта 2011

Учебный Проект. Релиз 7
/******************************************************
Copyright (c) Victor Yukhtenko
 
Class human
******************************************/
class human:player
open core
 
predicates
    getPlayerDescriptor:(game::language_D)->string Descriptor.
 
end class human
 
implement human
open core
 
facts
    name:string:="Hum_".
 
clauses
   getPlayerDescriptor(game::en)="Human: Your strategy".
   getPlayerDescriptor(game::ru)="Человек: Ваша стратегия".
 
clauses
    setName(ProposedId):-
        name:=string::format("%s%s",name,ProposedId),
        Name=humanInterface::getInput(humanInterface::playerName_S,name),
        if not(Name="") then
            name:=Name
        end if.
 
clauses
    move():-
        InputString=humanInterface::getInput(humanInterface::playerStep_S),
        try
            juniourJudge::set(InputString)
        catch TraceID do
            handleException(TraceID),
            fail
        end try,
        !.
    move():-
        move().
 
clauses
    announceWin():-
        humanInterface::announce(humanInterface::win_S,name).
 
    announceLoss():-
        humanInterface::announce(humanInterface::loss_S,name).
 
class predicates
    handleException:(exception::traceId TraceID).
clauses
    handleException(TraceID):-
        foreach Descriptor=exception::getDescriptor_nd(TraceID) do
            Descriptor = exception::descriptor(
                _ClassInfo1,
                _Descriptor,
                _Kind,
                ExtraInfo,
                _GMTTime,
                _ExceptionDescription,
                _ThreadId),
            if
                ExtraInfo=[namedValue("data",string(CellPointer))]
            then
                humanInterface::announce(humanInterface::errorWrongCell_S,CellPointer)
            else
                humanInterface::announce(humanInterface::error_S,"")
            end if
        end foreach.
 
end implement human