TRAFFIC JAM PROCEDURAL (or "Detailed") DESIGNNote: These algorithms are to be included in the "method" section of the corresponding Module Header.
PROCEDURE Play_Traffic_Jam Print Welcome Call Reset_Board Call Display_Board WHILE NOT Is_Win Call Take_Turn Call Display_Board END WHILE PROCEDURE Take_Turn REPEAT Show Prompt Call Get_Move UNTIL Is_Valid_Move Call Update_Board PROCEDURE Init_Board Set puzzle array to starting configuration Set empty position to 6. PROCEDURE Display_Board FOR position IN Rocks DO Convert the marker in Puzzle(pos) to a printable character. Print the marker character (>, <, or .) END LOOP; Put blank line Put row of dashes Put row of rock numbers 1 - 11 PROCEDURE Update_Board Swap markers in the puzzle at The_Move and Empty_Position Empty_Position becomes The_Move FUNCTION Is_Win RETURN (Puzzle = winning configuration) FUNCTION Is_Valid_Move IF The_Move out of bounds THEN RETURN FALSE IF Marker at The_Move is Empty THEN RETURN FALSE CASE Marker at The_Move Facing Right : IF the spot to its right is empty RETURN TRUE IF the spot to its right has a Left marker AND the "leapfrog" spot is empty RETURN TRUE Facing Left : IF the spot to its left is empty RETURN TRUE IF the spot to its left has a Right marker AND the "leapfrog" spot is empty RETURN TRUE END CASE