import random

# given an input list of cards, shuffle them and return a new shuffled list
def shuffle(deck):
random.shuffle(deck)
return deck

# ensure the human player picks a valid spade from the remaining cards in hand
def p1_algorithm(p1_spades):
bid = int(input("Enter player 1 bid: "))
while bid not in p1_spades:
print("Invalid bid. Choose a valid card from your hand.")
bid = int(input("Enter player 1 bid: "))
return bid

# given the complete state of the game, this AI algorithm will make a choice
# for the computer player and return the resulting selection.
def p2_algorithm(middle_cards, diamonds, p1_spades, p2_clubs):
return random.choice(p2_clubs)

def play_round(diamonds, p1_spades, p2_clubs, p1_capture, p2_capture, middle_cards):
middle_card = diamonds.pop(0)
middle_cards.append(middle_card)
print(f"Middle card(s): {middle_cards}")
print(f"Player 1 available: {p1_spades}")
player1_bid = p1_algorithm(p1_spades)
p1_spades.remove(player1_bid)
player2_bid = p2_algorithm(middle_cards, diamonds, p1_spades, p2_clubs)
p2_clubs.remove(player2_bid)
print(f"Player 2 bid: {player2_bid}")
if player1_bid > player2_bid:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p1_capture.append(value)
print(f"Player 1 wins bid, has captured {p1_capture}")
elif player2_bid > player1_bid:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p2_capture.append(value)
print(f"Player 2 wins bid, has captured {p2_capture}")

def determine_winner(p1_capture, p2_capture):
p1_score = sum(p1_capture)
p2_score = sum(p2_capture)
print("===GAME OVER===")
print(f"Player 1 captured: {p1_capture}")
print(f"Player 2 captured: {p2_capture}")
print(f"Player 1 scored {p1_score}, Player 2 scored {p2_score}")
if p1_score > p2_score:
print("PLAYER 1 WINNER")
elif p2_score > p1_score:
print("PLAYER 2 WINNER")
else:
print("IT'S A TIE!")

# MAIN PROGRAM LOGIC
# NO STUDENT CHANGES BELOW THIS POINT

# randomize random number generator with a known seed for repeatability
seed = int(input("Enter random seed: "))
random.seed(seed)

# initialize 3 hands, each with cards 2 - 10
diamonds = [2, 3, 4, 5, 6, 7, 8, 9, 10]
p1_spades = [2, 3, 4, 5, 6, 7, 8, 9, 10]
p2_clubs = [2, 3, 4, 5, 6, 7, 8, 9, 10]

# shuffle the deck of diamonds
diamonds = shuffle(diamonds)

# initialize empty lists of cards that each player captures or that are in the middle
p1_capture = []
p2_capture = []
middle_cards = []

# game continues while diamonds are left
while len(diamonds) > 0:
play_round(diamonds, p1_spades, p2_clubs, p1_capture, p2_capture, middle_cards)

ERROR!
Traceback (most recent call last):
File "<main.py>", line 36
elif player2_bid > player1_bid:
IndentationError: unexpected indent

=== Code Exited With Errors ===

Bot GPT 3.5 Bot GPT 3.5 answered
1 month ago

It looks like there was an indentation error in the code. The `elif` statement should be on the same level as the preceding `if` statement. Here is the corrected section of the code:

```python
if player1_bid > player2_bid:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p1_capture.append(value)
print(f"Player 1 wins bid, has captured {p1_capture}")
elif player2_bid > player1_bid:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p2_capture.append(value)
print(f"Player 2 wins bid, has captured {p2_capture}")
```

You can make this change in your code and try running it again. Let me know if you need any further assistance!

anonymous anonymous answered
1 month ago

invalid syntax elif

Bot GPT 3.5 Bot GPT 3.5 answered
1 month ago

I apologize for the oversight. It seems that the `elif` statement was used incorrectly in this context. You can change it to an `else` statement instead since there are only two possibilities in this scenario. Here is the revised section of the code:

```python
if player1_bid > player2_bid:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p1_capture.append(value)
print(f"Player 1 wins bid, has captured {p1_capture}")
else:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p2_capture.append(value)
print(f"Player 2 wins bid, has captured {p2_capture}")
```

By replacing `elif` with `else`, the code should now run without syntax errors. Feel free to incorporate this change into your code and let me know if you encounter any further issues.

anonymous anonymous answered
1 month ago

ERROR!

Traceback (most recent call last):
File "<main.py>", line 36
else:
^^^^
SyntaxError: invalid syntax

=== Code Exited With Errors ===

Bot GPT 3.5 Bot GPT 3.5 answered
1 month ago

It seems like the issue may be due to the positioning of the `else` statement. Let's modify the code to ensure proper indentation and syntax. Here is the revised section of the code:

```python
if player1_bid > player2_bid:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p1_capture.append(value)
print(f"Player 1 wins bid, has captured {p1_capture}")
else:
while len(middle_cards) > 0:
value = middle_cards.pop(0)
p2_capture.append(value)
print(f"Player 2 wins bid, has captured {p2_capture}")
```

Please check the updated code snippet above, adjust it in your program, and try running it again. Let me know if you encounter any further issues.

🤔 🤔 Ask a New Question 🤔 🤔