My friend and I are making a Text-Based Baseball game in Python. We are trying to figure out how to manage the runners on base. We were thinking if the best way would be to have a list of booleans and flip them based on if the play was a single, double, etc. Any help would be appreciated!
bases = [False,False,False]
if hit == single:
bases = [True,False,False]
from collections import deque bases = [False, False, True] playing_field = deque(bases) print(playing_field) #deque([False, False, True]) playing_field.rotate(-1) print(playing_field) #deque([False, True, False]) #can use it like a list: print(playing_field) #False
collections is perfect for what you want to do. You can basically shift the list and add a member to first base.
rotate() takes an integer, positive or negative, and shifts the list that many times left or right.
If I were you, make it include a home plate, so you can pop it off and score or what not. IF you need
popright() methods to literally take the left or right most item off the list.