8
2
Most of you have probably heard of the famous Turtle Graphics program, initially made popular by Logo. This challenge is to implement a Turtle Graphics program in your language of choice.
Rules:
The floor must be a diagonal with dimensions input by the user through std-in in the form
x/y
, representing thex
andy
length, respectively.x
may not be more than 20 andy
may not be more than 45,When the pen is in the down state, it must draw in both the square (the x/y coordinate) the turtle leaves and the square the turtle enters. This is what would happen in real life, so that is what your program should do.
Initial position and direction of the turtle must be input by the user in the form
x,y,d
, wherex
andy
are the positions on the x- and y-axis, respectively, andd
is the direction, entered asU
,D
,R
, orL
(up, down, right, and left, respectively).You must stop the turtle and display an error message if the turtle hits the wall. In other words, the turtle cannot walk through the wall.
The turtle must include these commands:
RESET - Resets board to blank - turtle goes back to initial position and direction.
DRAW and ERASE - These commands set the turtle to drawing and erasing, respectively.
UP and DOWN - These two commands set the active tool (pen or eraser) position to up and down, respectively.
DIRECTION x - This command turns the turtle to any direction North, Northeast, East, Southeast, South, Southwest, West, or Northwest, represented as the digits 1-8, with North (up) being 1, Northeast being 2...
FORWARD xx - Advances turtle xx squares; FORWARD 15 advances the turtle 15 squares. If the turtle is facing N, E, S, of W, it will draw in
x
squares in that direction only. If the turtle is facing NE, NW, SE, or SW, it will draw inx
squares in both directions; i.e. in FORWARD 1 while facing NE, it will draw this:X X
DISPLAY - Displays board, using
X
for filled squares (x/y coordinates) and a blank spacefor empty squares.
POSITION - Prints turtle's x/y coordinate on the board.
SETPOS x y d - Sets the turtle to the x/y coordinate facing direction
d
, using the same notation as the DIRECTION command.STOP - Displays the board, and terminates the program after the user enters the character
~
.
Example commands:
DIRECTION 2 FORWARD 1 DIRECTION 4 FORWARD 1:
X X X
DIRECTION 2 FORWARD 1 DIRECTION 4 FORWARD 4:
X X X X X
DIRECTION 3 FORWARD 5:
XXXXX
This program will use standard atomic-code-golf scoring rules to try to allow non-esoteric programming languages, such as Java and C++, to compete.
Version 1 is here. It did not require user input of board size and turtle start point, nor did it require diagonal movements.
Nice. I guess you win. – None – 2014-05-02T15:55:10.400