if (knitr:::is_latex_output()) {
knitr::asis_output('\\url{....}')
} else {
knitr::include_graphics("fig/Token_01.gif")
}
move(), put(), take()if (knitr:::is_latex_output()) {
knitr::asis_output('\\url{....}')
} else {
knitr::include_graphics("fig/Token_01.gif")
}
move()
take()
move()
put()
move()move(), put(), take()move_until_done() 함수를 제작해서 if문을 사용하게 되면 조금더 깔끔하게 목적을 달성할 수 있다.if (knitr:::is_latex_output()) {
knitr::asis_output('\\url{....}')
} else {
knitr::include_graphics("fig/Token_02.gif")
}
def move_until_done():
move()
if object_here():
take()
move()
put()
repeat 5:
move_until_done()move(), put(), take()object_here(), at_goal()while 루프와 부정(negation)if (knitr:::is_latex_output()) {
knitr::asis_output('\\url{....}')
} else {
knitr::include_graphics("fig/Token_03.gif")
}
def move_until_done():
move()
if object_here():
take()
move()
put()
while not at_goal():
move_until_done()move(), put(), take()object_here(), carries_object(), at_goal()while 루프, if 문과 부정(negation)if (knitr:::is_latex_output()) {
knitr::asis_output('\\url{....}')
} else {
knitr::include_graphics("fig/Token_04.gif")
}
def collect_all():
if object_here():
take()
move()
def put_down_all_and_move():
while carries_object():
put()
move()
while not at_goal():
if object_here():
collect_all()
elif carries_object():
put_down_all_and_move()
else:
move()토큰 이동 5를 일반화하여 토큰이 있는 곳과 그렇지 않는 곳도 리보그가 이동하여 목적을 달성할 수 있도록 한다.
move(), put(), take()object_here(), carries_object(), at_goal()while 루프, if 문과 부정(negation)if (knitr:::is_latex_output()) {
knitr::asis_output('\\url{....}')
} else {
knitr::include_graphics("fig/Token_05.gif")
}
def collect_all():
if object_here():
take()
move()
def put_down_all_and_move():
while carries_object():
put()
move()
while not at_goal():
if object_here():
collect_all()
elif carries_object():
put_down_all_and_move()
else:
move()