0

The pseudo code is in notes but I need to define a function that checks the valid moves left in my peg game. The game pretty much randoms two die and it takes the sum of those two numbers and the person pegs the numbers in the list from 1-10 that they roll. In this portion of it I need to return the portion of the list that has not been pegged. Obviously my code is not right but I do not know how to do this part of the game so any help fixing my code would be appreciated, thanks.

PEGGED = "X"

# This function will return a list of numbers, which are free (don't
# have pegs in them), a.k.a., a list of valid moves


def valid_moves(pegholes):
   validMoves = item in len(range(0, pegholes, 1)) != PEGGED

   return validMoves

1 Answer 1

3

This logic might work:

validMoves = [item for item in pegholes if item != PEGGED]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this seems to work well and helped me understand it more :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.