Jed Rembold
February 11, 2026

x and y
coordinates. This is your robots current location.from pgl import GWindow, GRect, GOval
import random
WIDTH = 800
HEIGHT = 800
SIZE = 700
DART_SIZE = 10
gw = GWindow(WIDTH, HEIGHT)
background = GRect(
WIDTH / 2 - SIZE / 2,
HEIGHT / 2 - SIZE / 2,
SIZE,
SIZE
)
background.set_filled(True)
background.set_color('gray')
gw.add(background)
target = GOval(
WIDTH / 2 - SIZE / 2,
HEIGHT / 2 - SIZE / 2,
SIZE,
SIZE
)
target.set_filled(True)
target.set_color('darkgray')
gw.add(target)
attempts = 1000
successful_strikes = 0
for i in range(attempts):
x = random.uniform(WIDTH / 2 - SIZE / 2, WIDTH / 2 + SIZE / 2)
y = random.uniform(HEIGHT / 2 - SIZE / 2, HEIGHT / 2 + SIZE / 2)
dart = GOval(
x - DART_SIZE / 2,
y - DART_SIZE / 2,
DART_SIZE,
DART_SIZE
)
dart.set_filled(True)
distance_to_center = (
(x - WIDTH / 2)**2 + (y - HEIGHT / 2)**2
) ** (1/2)
if distance_to_center < SIZE / 2:
dart.set_fill_color('red')
successful_strikes += 1
else:
dart.set_fill_color('blue')
gw.add(dart)
# I forgot this extra factor of 4 in class! That is why it wasn't working initially
print(successful_strikes / attempts * 4 )