[练习]--solveMaze

Practice:

  Although Euclid’s algorithm and the problem of finding perfect numbers from the preceding exercise are both drawn from the domain of mathematics, the Greeks were fascinated with algorithms of other kinds as well.  In Greek mythology, for example, Theseus of Athens escapes from the Minotaur’s labyrinth by taking in a ball of string, unwinding it as he goes along, and then following the path of string back to the exit.  Theseus’s strategy represents an algorithm for escaping from a maze, but it is not the only algorithm he could have used to solve this problem.  For example, if a maze has no internal loops, you can always escape by keeping your right hand against a wall at all times.  This algorithm is called the right-hand rule.

For example, imagine that Theseus is in the maze shown below at the position marked by the Greek letter theta (Θ):2011040816571713.jpg

  To get out, Theseus walks along the path shown by the dotted line in the next diagram, which he can do without taking his right hand off the wall.

  2011040816580041.jpg

  Suppose you have been asked to write a program for a robot named Theseus to escape from a maze.  You have access to a library that contains these methods:

void moveForward();     /* Move forward to the next square   */

void turnRight();       /* Turn right without moving         */

void turnLeft();        /* Turn left without moving          */

boolean isFacingWall(); /* True if Theseus is facing a wall  */

boolean isOutside();    /* True if Theseus has left the maze */

Use these methods to write an algorithmic method solveMaze that implements the right-hand rule.

转载于:https://www.cnblogs.com/nzyjlr/archive/2011/04/08/2009684.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值