@@ -122,32 +122,30 @@ def dartmouth_jump_shot(self) -> None:
122122 if random .random () > 0.782 * self .defense / 8 :
123123 if random .random () > 0.843 * self .defense / 8 :
124124 print ("Charging foul. Dartmouth loses ball.\n " )
125- self .opponent_ball ()
126125 else :
127126 # player is fouled
128127 self .foul_shots (1 )
129- self .opponent_ball ()
128+ self .opponent_ball ()
129+ elif random .random () > 0.5 :
130+ print (
131+ "Shot is blocked. Ball controlled by "
132+ + self .opponent
133+ + ".\n "
134+ )
135+ self .opponent_ball ()
130136 else :
131- if random .random () > 0.5 :
132- print (
133- "Shot is blocked. Ball controlled by "
134- + self .opponent
135- + ".\n "
136- )
137- self .opponent_ball ()
138- else :
139- print ("Shot is blocked. Ball controlled by Dartmouth." )
140- self .dartmouth_ball ()
137+ print ("Shot is blocked. Ball controlled by Dartmouth." )
138+ self .dartmouth_ball ()
141139 else :
142140 print ("Shot is off target." )
143141 if self .defense / 6 * random .random () > 0.45 :
144- print ("Rebound to " + self .opponent + "\n " )
142+ print (f "Rebound to { self .opponent } " + "\n " )
145143 self .opponent_ball ()
146144 else :
147145 print ("Dartmouth controls the rebound." )
148146 if random .random () > 0.4 :
149147 if self .defense == 6 and random .random () > 0.6 :
150- print ("Pass stolen by " + self .opponent + " , easy lay up" )
148+ print (f "Pass stolen by { self .opponent } , easy lay up" )
151149 self .add_points (0 , 2 )
152150 self .dartmouth_ball ()
153151 else :
@@ -186,13 +184,11 @@ def dartmouth_non_jump_shot(self) -> None:
186184 if 7 / self .defense * random .random () > 0.875 :
187185 if 7 / self .defense * random .random () > 0.925 :
188186 print ("Charging foul. Dartmouth loses the ball.\n " )
189- self .opponent_ball ()
190187 else :
191- print ("Shot blocked. " + self .opponent + "'s ball.\n " )
192- self .opponent_ball ()
188+ print (f"Shot blocked. { self .opponent } " + "'s ball.\n " )
193189 else :
194190 self .foul_shots (1 )
195- self .opponent_ball ()
191+ self .opponent_ball ()
196192 else :
197193 print ("Shot is off the rim." )
198194 if random .random () > 2 / 3 :
@@ -216,35 +212,35 @@ def dartmouth_ball(self) -> None:
216212 self .shot = shot
217213
218214 if self .time < 100 or random .random () < 0.5 :
219- if self .shot == 1 or self . shot == 2 :
215+ if self .shot in [ 1 , 2 ] :
220216 self .dartmouth_jump_shot ()
221217 else :
222218 self .dartmouth_non_jump_shot ()
219+ elif self .score [0 ] == self .score [1 ]:
220+ print ("\n ***** End Of Second Half *****" )
221+ print ("Score at end of regulation time:" )
222+ print (
223+ " Dartmouth: "
224+ + str (self .score [1 ])
225+ + " "
226+ + self .opponent
227+ + ": "
228+ + str (self .score [0 ])
229+ )
230+ print ("Begin two minute overtime period" )
231+ self .time = 93
232+ self .start_of_period ()
233+
223234 else :
224- if self .score [0 ] != self .score [1 ]:
225- print ("\n ***** End Of Game *****" )
226- print (
227- "Final Score: Dartmouth: "
228- + str (self .score [1 ])
229- + " "
230- + self .opponent
231- + ": "
232- + str (self .score [0 ])
233- )
234- else :
235- print ("\n ***** End Of Second Half *****" )
236- print ("Score at end of regulation time:" )
237- print (
238- " Dartmouth: "
239- + str (self .score [1 ])
240- + " "
241- + self .opponent
242- + ": "
243- + str (self .score [0 ])
244- )
245- print ("Begin two minute overtime period" )
246- self .time = 93
247- self .start_of_period ()
235+ print ("\n ***** End Of Game *****" )
236+ print (
237+ "Final Score: Dartmouth: "
238+ + str (self .score [1 ])
239+ + " "
240+ + self .opponent
241+ + ": "
242+ + str (self .score [0 ])
243+ )
248244
249245 def opponent_jumpshot (self ) -> None :
250246 """Simulate the opponents jumpshot"""
@@ -253,32 +249,35 @@ def opponent_jumpshot(self) -> None:
253249 if 8 / self .defense * random .random () > 0.75 :
254250 if 8 / self .defense * random .random () > 0.9 :
255251 print ("Offensive foul. Dartmouth's ball.\n " )
256- self .dartmouth_ball ()
257252 else :
258253 self .foul_shots (0 )
259- self .dartmouth_ball ()
254+ self .dartmouth_ball ()
260255 else :
261256 print ("Shot is off the rim." )
262257 if self .defense / 6 * random .random () > 0.5 :
263- print (self .opponent + " controls the rebound." )
264- if self .defense == 6 :
265- if random .random () > 0.75 :
266- print ("Ball stolen. Easy lay up for Dartmouth." )
267- self .add_points (1 , 2 )
268- self .opponent_ball ()
269- else :
270- if random .random () > 0.5 :
271- print ()
272- self .opponent_non_jumpshot ()
273- else :
274- print ("Pass back to " + self .opponent + " guard.\n " )
275- self .opponent_ball ()
258+ print (f"{ self .opponent } controls the rebound." )
259+ if (
260+ self .defense == 6
261+ and random .random () <= 0.75
262+ and random .random () > 0.5
263+ ):
264+ print ()
265+ self .opponent_non_jumpshot ()
266+ elif (
267+ self .defense == 6
268+ and random .random () <= 0.75
269+ and random .random () <= 0.5
270+ or self .defense != 6
271+ and random .random () <= 0.5
272+ ):
273+ print (f"Pass back to { self .opponent } " + " guard.\n " )
274+ self .opponent_ball ()
275+ elif self .defense == 6 and random .random () > 0.75 :
276+ print ("Ball stolen. Easy lay up for Dartmouth." )
277+ self .add_points (1 , 2 )
278+ self .opponent_ball ()
276279 else :
277- if random .random () > 0.5 :
278- self .opponent_non_jumpshot ()
279- else :
280- print ("Pass back to " + self .opponent + " guard.\n " )
281- self .opponent_ball ()
280+ self .opponent_non_jumpshot ()
282281 else :
283282 print ("Dartmouth controls the rebound.\n " )
284283 self .dartmouth_ball ()
@@ -296,26 +295,30 @@ def opponent_non_jumpshot(self) -> None:
296295 if 7 / self .defense * random .random () > 0.413 :
297296 print ("Shot is missed." )
298297 if self .defense / 6 * random .random () > 0.5 :
299- print (self .opponent + " controls the rebound." )
300- if self .defense == 6 :
301- if random .random () > 0.75 :
302- print ("Ball stolen. Easy lay up for Dartmouth." )
303- self .add_points (1 , 2 )
304- self .opponent_ball ()
305- else :
306- if random .random () > 0.5 :
307- print ()
308- self .opponent_non_jumpshot ()
309- else :
310- print ("Pass back to " + self .opponent + " guard.\n " )
311- self .opponent_ball ()
298+ print (f"{ self .opponent } controls the rebound." )
299+ if (
300+ self .defense == 6
301+ and random .random () <= 0.75
302+ and random .random () > 0.5
303+ or self .defense != 6
304+ and random .random () > 0.5
305+ ):
306+ print ()
307+ self .opponent_non_jumpshot ()
308+ elif (
309+ self .defense == 6
310+ and random .random () <= 0.75
311+ and random .random () <= 0.5
312+ ):
313+ print (f"Pass back to { self .opponent } " + " guard.\n " )
314+ self .opponent_ball ()
315+ elif self .defense == 6 and random .random () > 0.75 :
316+ print ("Ball stolen. Easy lay up for Dartmouth." )
317+ self .add_points (1 , 2 )
318+ self .opponent_ball ()
312319 else :
313- if random .random () > 0.5 :
314- print ()
315- self .opponent_non_jumpshot ()
316- else :
317- print ("Pass back to " + self .opponent + " guard\n " )
318- self .opponent_ball ()
320+ print (f"Pass back to { self .opponent } " + " guard\n " )
321+ self .opponent_ball ()
319322 else :
320323 print ("Dartmouth controls the rebound.\n " )
321324 self .dartmouth_ball ()
0 commit comments