Swisseducs Kara의 항구 인 패키지 (독일어의 페이지). 카라는 프로그래밍 세계에 쉽게 접근 할 수있는 개념입니다. 카라는 버섯, 나무 및 잎이있는 숲에 사는 작은 무당 벌레입니다. 카라는 단일 버섯을 움직이고, 잎을 놓고 잎을 제거하고, 나무를 움직일 수 없으며 줄리아 코드를 사용하여 완전히 제어 할 수 있습니다. 원래 카라와 비교할 때 Manly는 REPL 사용에 중점을 둡니다.
PKG Repl-Mode를 사용하여 Julia 내에 설치하십시오
add JuliaKara또는 Julia 0.6에서 Repl-Mode 사용을 사용합니다
Pkg . add ( " JuliaKara " ) 줄리아를 열고 줄리아 카라를 using JuliaKara 사용을 시작하십시오. 다음으로 @World (10,10) 입력하여 글로벌 범위의 함수 바인딩을 사용하여 크기 10x10의 새로운 세계를 만듭니다.
이제 사용할 수 있습니다
move(kara) ,turnLeft(kara) ,turnRight(kara) ,putLeaf(kara)removeLeaf(kara)그리고
treeFront(kara) ,treeLeft(kara) 카라의 나무가 남은지 확인하기 위해treeRight(kara)onLeaf(kara) 카라 아래에 잎이 있는지 확인하고mushroomFront(kara) Kara가 버섯 앞에 있는지 확인합니다. Juliakara는 원래 Kara가 세계를 파일에 저장하는 데 사용하는 XML 구문을 알고 있습니다. GUI를 통해 또는 @World [path] 를 통해 세상을로드 할 수 있습니다. GUI 버전 @World [path] 와 달리 새 창을 열고 world 와 kara 글로벌 범위를 참조로 등록합니다.
@World " file1.world "
move (kara) # moves Kara in world from file1.world
@World " file2.world "
# kara and world referencing elements from file1.world
# are now overwritten with references to elements from file2.world
move (kara) # moves Kara in world from file2.world
# Create additional references to world and kara
world_save = world
kara_save = kara
@World " file3.world "
# kara and world referencing elements from file2.world
# are now overwritten with references to elements from file3.world
move (kara) # moves Kara in world from file3.world
# Access stored references
move (world_save,kara_save) # moves Kara in world from file2.worldGUI를 통해 세상을로드하고 위의 행동을 원하는 경우 카라에 대한 참조는 다음과 같이 복원해야합니다.
kara = get_kara (world) Juliakara는 여러 세계와 다중 카라를 지원합니다. 예제를 재현하려면 Juliakara의 테스트 디렉토리, 즉 ~/.Julia/v0.6/JuliaKara/test 에서 실행을 재현하려는 경우.
# Load the world contained in example.world.
# This also creates a macro @w1 in global scope to interact with
# the world
@World w1 " example.world "
# Create an empty world w2
@World w2 ( 10 , 2 )
# Place kara in the empty world.
# place_kara() returns a reference to the placed kara.
# @w2 place_kara(1,1) is just syntactic sugar for place_kara(w2,1,1)
kara = @w2 place_kara ( 1 , 1 )
# Kara is already placed in world w1, therefore we fetch it with get_kara()
# Since we can't create two kara references we use lara instead.
lara = @w1 get_kara ()
# Move lara a step in world w1
@w1 move (lara)
# Alternatively:
move (w1,lara)
# Move kara a step in world w2
@w2 move (kara)
# It's even possible to allow kara from world w2 to
# place something in world w1
@w1 putLeaf (kara)
reset!(world) : 로딩 후 또는 마지막으로 저장 한 후 세계에 world 재설정하십시오 store!(world) .store!(world) : 현재 world 상태를 저장합니다.place_kara(world,X,Y,orientation) : world 를 X , Y 방향 orientation 에 배치합니다. 유효한 오리엔테이션은 다음과 같습니다. :NORTH , :EAST , :SOUTH 및 :WEST . orientation 은 선택 사항이며 기본값 :NORTH .place_mushroom(world,X,Y) : X , Y 에 world 에 버섯을 배치합니다.place_tree(world,X,Y) : X , Y 에 world 를 세우는 것입니다.place_leaf(world,X,Y) : X , Y 에서 world 에 잎을 배치합니다. 위의 상호 작용에 사용 된 매크로는 기본적으로 @w1 f(args...) @w1 f(w1,args...) 로 변환합니다. 따라서 위의 모든 방법은 world 매크로를 사용하여 세계를 사용하여 세계를 가지고 있기 때문에 세계를 사용합니다. 이것은 또한 사용자 정의 방법에 대해 작동합니다.
function turnAround (wo,ka)
turnLeft (wo,ka)
turnLeft (wo,ka)
end
@w1 turnAround (lara)Juliakara의 예제 페이지에는 Juliakara의 사용을 보여주는 추가 자료가 포함되어 있습니다.