Difference between revisions of "Tutorial Project. Release 7. Class Computer1"

From wiki.visual-prolog.com

Line 1: Line 1:
{{PolyLine7.Players}}
{{PolyLine7.Players}}
<vip>
/******************************************************
Copyright (c) 2007,2008. Elena Efimova
predicate SuccessfullStep implementation
Copyright (c) 2007,2008. Prolog Development Center SPb
Written by: Victor Yukhtenko
Class computer1
*******************************************************/
class computer1:player
open core
predicates
    getPlayerDescriptor:(game::language_D)->string Descriptor.
end class computer1
implement computer1
    inherits genericComputer
open core
clauses
    new():-
        PolyLineBraneObj=polylineStrategy1::new(),
        setpolylineStrategy(PolyLineBraneObj).
clauses
  getPlayerDescriptor(game::en)=polylineStrategy1::playerDescriptorEn_C.
  getPlayerDescriptor(game::ru)=polylineStrategy1::playerDescriptorRu_C.
end implement computer1
/******************************************
  Class polylineStrategy1
******************************************/
class polylineStrategy1:polylineStrategy
open core
predicates
    classInfo : core::classInfo.
constants
    playerDescriptorEn_C="Computer1: Unlimited Depth. Despair move - random".
    playerDescriptorRu_C="Computer1: Неограниченный поиск. Ход отчаяния - случайный".
end class polylineStrategy1
implement polylineStrategy1
open core, exception
constants
    className = "polylineStrategy1".
    classVersion = "1.0".
clauses
    classInfo(className, classVersion).
facts
    genericComputer_V:genericComputer:=erroneous.
clauses
    setGenericComputer(GenericComputerObj):-
        genericComputer_V:=GenericComputerObj.
clauses
    successfulStep(PolyLine)=BestMove:-
        genericComputer_V:stepCandidate(PolyLine, _PolyLine1,BestMove),
        list::isMember(BestMove, PolyLine),
        !.
    successfulStep(PolyLine)=Cell:-
        genericComputer_V:stepCandidate(PolyLine, PolyLine1,Cell),
            not(_=successfulStep(PolyLine1)).
clauses
    randomStep()=Cell:-
        findAll(NewCell,genericComputer_V:stepCandidate(juniourJudge::polyline_P,_Polyline1, NewCell),CellCandidateListWithDuplicates),
        CellCandidateList=list::removeDuplicates(CellCandidateListWithDuplicates),
        not(CellCandidateList=[]),
        NoOfVariants=list::length(CellCandidateList),
        ChoiceNo=math::random(NoOfVariants-1),
        Cell=list::nth(ChoiceNo+1,CellCandidateList).
end implement polylineStrategy1
</vip>


[[ru:Ползунок7. Класс Computer1]]
[[ru:Ползунок7. Класс Computer1]]
[[Category:Examples]]
[[Category:Examples]]
[[Category:Game 1+]]
[[Category:Game 1+]]

Revision as of 21:41, 6 January 2008

Tutorial Project. Release 7


/******************************************************
Copyright (c) 2007,2008. Elena Efimova
predicate SuccessfullStep implementation
 
Copyright (c) 2007,2008. Prolog Development Center SPb
Written by: Victor Yukhtenko
 
Class computer1
*******************************************************/
class computer1:player
open core
 
predicates
    getPlayerDescriptor:(game::language_D)->string Descriptor.
 
end class computer1
 
implement computer1
    inherits genericComputer
open core
 
clauses
    new():-
        PolyLineBraneObj=polylineStrategy1::new(),
        setpolylineStrategy(PolyLineBraneObj).
 
clauses
   getPlayerDescriptor(game::en)=polylineStrategy1::playerDescriptorEn_C.
   getPlayerDescriptor(game::ru)=polylineStrategy1::playerDescriptorRu_C.
 
end implement computer1
 
/******************************************
  Class polylineStrategy1
******************************************/
class polylineStrategy1:polylineStrategy
open core
predicates
    classInfo : core::classInfo.
 
constants
    playerDescriptorEn_C="Computer1: Unlimited Depth. Despair move - random".
    playerDescriptorRu_C="Computer1: Неограниченный поиск. Ход отчаяния - случайный".
 
end class polylineStrategy1
 
implement polylineStrategy1
open core, exception
 
constants
    className = "polylineStrategy1".
    classVersion = "1.0".
 
clauses
    classInfo(className, classVersion).
 
facts
    genericComputer_V:genericComputer:=erroneous.
 
clauses
    setGenericComputer(GenericComputerObj):-
        genericComputer_V:=GenericComputerObj.
 
clauses
    successfulStep(PolyLine)=BestMove:-
        genericComputer_V:stepCandidate(PolyLine, _PolyLine1,BestMove),
        list::isMember(BestMove, PolyLine),
        !.
    successfulStep(PolyLine)=Cell:-
        genericComputer_V:stepCandidate(PolyLine, PolyLine1,Cell),
            not(_=successfulStep(PolyLine1)).
 
clauses
    randomStep()=Cell:-
        findAll(NewCell,genericComputer_V:stepCandidate(juniourJudge::polyline_P,_Polyline1, NewCell),CellCandidateListWithDuplicates),
        CellCandidateList=list::removeDuplicates(CellCandidateListWithDuplicates),
        not(CellCandidateList=[]),
        NoOfVariants=list::length(CellCandidateList),
        ChoiceNo=math::random(NoOfVariants-1),
        Cell=list::nth(ChoiceNo+1,CellCandidateList).
 
end implement polylineStrategy1