ireapps / pycar

NICAR Python mini boot camp
https://ireapps.github.io/pycar/pycar_intro.html
MIT License
101 stars 36 forks source link

Tweak ending to solitaire example #55

Closed tommeagher closed 5 years ago

tommeagher commented 6 years ago

Everything went great until we got to the last command

for column in columns:
    if card_to_play == column["last_card"]["value"] - 1
        break

There's a big leap there, including a for loop for a list (columns) that we haven't created yet. We called an audible and instead added a conditional to check if the card is one less than the previous, and if the suit is the same.

 if play_card["value"] == first_column_card["value"] - 1:
        if play_card["suit"] != first_column_card["suit"]:
            if play_card["color"] != first_column_card["color"]: # or create another dict with suits and colors to lookup
                #run a function moving cards
                pass
            else:
                print("You can't play on the same color")
        else:
            print("you can't play on the same suit")
else:
    print("You can't play this card here")
tommeagher commented 5 years ago

@meli-lewis & @elainewong you should take a look at this issue in reference to https://github.com/ireapps/pycar/blob/master/completed/basics_complete_notebook.ipynb to see how you want to address it on Thursday, if you haven't already.

elainewong commented 5 years ago

For 2020,

When we create dictionaries for play_card and first_card, we also create second_card, third_card and fourth_card. We can add that to a list called columns = [first_card, second_card, third_card, fourth_card] where we can do a for loop for comparison at the end.

Let's make sure that the solitaire example would move the card off the top deck and when we create a dictionary, we have a color key. i.e.

         "value": 5,
         "suit": "spade",
         "color": "black"
}

So the example at the top can be done:


        if play_card["suit"] != first_column_card["suit"]:
            if play_card["color"] != first_column_card["color"]: # or create another dict with suits and colors to lookup
                #run a function moving cards
                pass
            else:
                print("You can't play on the same color")
        else:
            print("you can't play on the same suit")
else:
    print("You can't play this card here")```
tommeagher commented 5 years ago

closed by 4432e38