4.26: Creating the Board Data Structure- Step 1 – Get All Possible Icons

Making Games with Python and Pygame · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    4.26: Creating the Board Data Structure- Step 1 – Get All Possible Icons
    def getRandomizedBoard():
        # Get a list of every possible shape in every possible color.
        icons = []
        for color in ALLCOLORS:
            for shape in ALLSHAPES:
                icons.append( (shape, color) )
    

    The board data structure is just a list of lists of tuples, where each tuple has a two values: one for the icon’s shape and one for the icon’s color. But creating this data structure is a little complicated. We need to be sure to have exactly as many icons for the number of boxes on the board and also be sure there are two and only two icons of each type.

    The first step to do this is to create a list with every possible combination of shape and color. Recall that we have a list of each color and shape in ALLCOLORS and ALLSHAPES, so nested for loops on lines 4 [135] and 5 [136] will go through every possible shape for every possible color. These are each added to the list in the icons variable on line 6 [137].


    This page titled 4.26: Creating the Board Data Structure- Step 1 – Get All Possible Icons was last modified on Wed, 13 Nov 2019 02:47:35 GMT and is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Al Sweigart via source content that was edited to the style and standards of the LibreTexts platform.