9/1/2023 0 Comments Names of tetris blocks![]() ![]() If you have some experience with GUI applications, you would think that we need to construct a frame and a canvas before we can draw the tetris blocks, but in Racket all this can be left until later. ( module+ test ( check-false ( valid-block-row? 1 )) not a string ( check-false ( valid-block-row? "." )) more than 4 characters ( check-false ( valid-block-row? "X." )) containing invalid characters ( check-false ( valid-block? "hello" )) not a list ( check-false ( valid-block? ( append L-Block T-Block ))) more than 4 items ( check-false ( valid-block? ( list "." "." "." 1 ))) not a list of strings ( check-false ( valid-block? ( list "X." "." "." "." ))) contains invalid characters Verify that all our blocks are correctly defined ( for () ( check-pred valid-block? block ))) Before we start writing functions which manipulate these blocks, it is useful to define two validation functions, valid-block-row? will check if a single string is valid for a block definition, while valid-block? will verify that a tetris block definition actually conforms to our conventions: Using lists of strings for our blocks has some disadvantages, since Racket cannot validate a correct block definition. Racket will also display strings directly, so the results of various functions can be inspected directly into the REPL, without the need to define separate functions to display the data structures. Using a string representation means that there is a visual cue about the shape of the blocks right in the program source.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |