You will build a command decoder with a small set of commands; you will expand it later to accommodate commands required for future parts.
The following is a list of commands you should support for part 2 and a description of
the output you should give for each one. Note that for all functions, you should
print ''*****\n'' followed by a '' ==> `` and an echo of the command given.
For instance, the entire valid output to a hypothtical *wink wink* CLEAR_ALL() command
would be:
***** ==> CLEAR_ALL() All structures are cleared.
This is done to negate the effects of input redirection and to assist in grading. Note that although it is done in the samples that will appear later, you are not required to reformat the original command (fixing spacing, for instance) in any way.
The definitions below will use the following standard BNF definitions.
<dotlist>:=<dot><nl><dotlist>|<dot><nl>
<dot>:= <name> at (<int>,<int>) color:<color>
<color>:= RED|GREEN|BLUE|BLACK|WHITE
<DNE>:=Error: The specified dot does not exist.<nl>
<framelist>:<frame>|<frame><framelist>
<frame>:Frame <int><nl><seglist>
<seglist>:<segment><nl>|<segment><nl><seglist>
<segment>:= (<name1>,<name2>)
Whenever a <double> appears, it means a floating
point decimal number printed with
exactly three digits after the decimal place
(including trailing zeros as necessary). To do this in java check out the NumberFormat class.
This <int> in a frame is the 0 based frame number for teh current drawing command. For instance, if you are drawing the 300th frame of ANIMATE_PATH, then the int should be 299. In the <segment> the names should be in increasing alphabetical order. The segments of the segment list. when printed, should be printed in increasing alphabetical order as well based on the alphabetically lowest endpoint of each segment. Break ties with the second endpoint. For instance:
Frame 7:
(a,b)
(a,c)
(a,d)
(b,d)
(c,d)
Also, when looking at the list of errors, eg.
<error>:= <DNE>|<NR>|<AI>|<DC>|<NZ>
the leftmost applicable error should always be the one printed.
The order will never be less than 3. You should check for this condition to avoid crashing horribly on a bad input, but I won't add a specific error for this part.
Note that the following rules apply to B+ tree nodes:
Internal: must always contain between floor(
)
and
keys, with exactly one more child than the number of keys
at all times. (this implies between ceiling(
)
and
children per node, inclusive).
Leaf: must always contain between ceiling(
)
and
keys, inclusive. Must not contain
keys! This
is to force consistency between our projects so that I have some chance
of grading.
Remember the root is an exception, in that it never has a
lower bound on the number of keys it contains.
Also, whenever a value is equal to a key it must go to that key's RIGHT child. This is mandatory, meaning no credit will be given for the B+ tree if this rule is not observed.
Even if you do not implement the b+ tree you must still implement this function!
Default to printing the correct <success> message. Because this is always
the first command and diff is used in grading, if you skip this function your
project will fail every test!
Output summary:
<output>:=<success>|<error>
<success>:= Order set to <btree_order>.<nl>
<error>:=Error: B+ tree already initialized.<nl>
Full information is in the newsgroup, but to be clear- when this function is used the only other commands tested will be CREATE_DOT, COLOR_DOT< and PRINT_QUADTREE. There will be no delete, or any other functions tested.
When you print the order in the output, just print whichever order you selected. Remember,
"Not Implemented
n" + System.exit(0); is worth a few points here.
Output summary:
<output>:=<success>|<error>
<success>:= Order set to <btree_order>.<nl>
<error>:=Not Implemented.<nl>
Output summary:
<output>:=<success>|<error>
<success>:=<dotlist>
<error>:= No matching dots found.<nl>
{(bar)}
{(DOT3),(foo)}
{(DOT1,DOT2),(DOT3),(bar),(foo)}
Note the leaf DOT3 is to the RIGHT of the key DOT3:)
Even at the leaves print only the key (the dotname). If the tree is empty, print "Tree is empty." Your tree is not expected to match mine exactly. Your grade will be based on your tree displaying the properties described above in the SET_BPTREE_ORDER command.
See SET_BPTREE_ORDER for rules on the number of keys in a node. Remember that there must be one fewer guides than children (no 'extra' key on the far left should be printed, even if you used one in your implementation). Your tree, of course, must also contain the correct data at the leaves!
Output summary:
<output>:=<success>|<error>
<success>:=<b+rows><nl>
<b+rows>:=<b+row><nl><b+rows>|<b+row>
<b+row>:={<nodes>}
<nodes>:=<node>,<nodes>|<node>
<node>:=(<keys>)
<keys>:=<key>,<keys>|<key>
<key>:=<dotname>
<error>:= Tree is empty.<nl>
xsize and ysize will specify the size of the view window used on the map. When animating the path along a line, the line should always be at the center of the view window, xsize units above and below the center and ysize units to the left and right, so that the actual window is 2*xsize by 2*ysize. The step says how far to move each frame in the current direction of travel(always east now). If you are following a particular line and the next step will cause you to pass the end of that line then you should have a frame exactly at that endpoint (don't try to advance some fractional step into the next line segment you might be drawing). Some discourse on the use of parametric representations of lines will probably be necessary if we stick with this.
Output summary:
<output>:=<success>
<success>:=Drawing mode changed to <mode>.<nl>
There is no such thing as failure (I promise (x,y) will be in bounds). If the current mode is BOTH or TEXT then each frame should also have a textual version printed according to the BNF and explanatory side comments ;)
Output summary:
<output>:=<optional textoutput><nl><success>
<success>:=Animation Complete.<nl>
<optional textoutput>:=<framelist>
Coordinates will be non-negative. This should be an O(logn) operation where n is the number of dots already in the dictionary. The dots should be stored in an asciibetically sorted B+ Tree.
If a dot with the same name already exists print an error. If a dot already exists at the specified coordinates print an error.
Output summary:
<output>:=<success>|<error>
<success>:=Created dot <dot>.<nl>
<error>:=<AE>|<DC>
<AE>:=Error: Dot <name> already exists.<nl>
<DC>:=Error: Dot <other\_dot\_name> already exists at the specified coordinates.
Output summary:
<output>:=<success>|<error>
<success>:=Deleted dot <name>.<nl>
<error>:=<DNE>|<ZZ>
<ZZ>:=Error: Dot <name> has already been added to the Quadtree.
This command will always precede the first command which requires the quadtree. This command is only valid the first time it is successfully called (out of range is not a successful call). If an attempt is made to reinitialize the tree, print an error.
Output summary:
<output>:=<success>|<error>
<success>:=Quadtree initialized.<nl>
<error>:=<OOR>|<INIT>
<OOR>:=Error: size out of range.<nl>
<INIT>:=Error: The Quadtree has already been initialized.<nl>
Output summary:
<output>:=<success>|<error>
<success>:=<dotlist>
<error>:= Dictionary is empty.<nl>
Output summary:
<output>:=<success>|<error>
<success>:=Color of <name> changed from <oldcolor> to <color>.<nl>
<error>:=<DNE>
Output summary:
<output>:=<success>|<error>
<success>:=Created segment (name1,name2).<nl>
<error>:=<DNE>|<AI>
<AI>:=Error: The specified segment already exists.
Output summary:
<output>:=<success>|<error>
<success>:=Mapped segment (name1,name2).<nl>
<error>:=<DNE>|<ID>
<ID>:=Error: Intersection detected.
Output summary:
<output>:=<success>|<error>
<success>:=Unmapped Segment (name1,name2).<nl>
<error>:=<DNE>|<SNF>
<SNF>:=Error: The specified segment was not found on the map.
A:A
IE., a one element tree should look like a leaf, even if not implemented that way.
Output summary:
<output>:=<success>|<error>
<success>:= <pmtree><nl>
<pmtree>:=<black_node><nl>|<white_node><nl>|<nl><grey_node>
<grey_node>:= NW <pmtree> NE <pmtree> SW <pmtree> SE <pmtree>
<black_node>:=<name>:<namelist>|<segment><nl>
<white_node>:=
<namelist>:= <name><namelist>|<name>
<segment>:= (<name1>,<name2>)
<error>:= Tree is empty.<nl>
Output summary:
<output>:=<success>
<success>:=Drawing complete.
Output summary:
<output>:=<success>
<success>:=Drawing complete.
Output summary:
<output>:=<success>|<error>
<success>:= Nearest segment: <segment>. Distance: <double>.<nl>
<segment>:= (<name1>,<name2>)
<error>:= Tree is empty.<nl>
Output summary:
<output>:=<success>
<success>:=Update complete. Found <int> segments.
Output summary:
<output>:=<success>|<error>
<success>:=Deleted Segment (name1,name2).<nl>
<error>:=<DNE>|<SDNE>|<AM>
<SDNE>:=Error: The specified segment does not exist.
Output summary:
<output>:=<success>|<error>
<success>:= <name1> -> <moredots> <nl>Total length:<double>.<nl>
<moredots>:= <dotname> -> <moredots>| <name2>
<error>:= <DNE>|<NP>
<NP>:= Error: No path exists.