# GESP等级：一级 | GESP Python 二级考点
# ============================================
# 第4节：continue —— while + continue 随机漫步
# 醉酒乌龟乱走，但有自己的"怪癖"——跳过不想去的方向
# ============================================
import turtle
import random

t = turtle.Turtle()
t.shape("turtle")
t.speed(5)
t.color("green")
t.pensize(2)

# ========== 基础版：纯随机漫步 ==========
print("===== 纯随机漫步（没怪癖）=====")
t.penup()
t.goto(0, 0)
t.pendown()

while -200 < t.xcor() < 200 and -200 < t.ycor() < 200:
    angle = random.randint(0, 360)     # 随机方向
    t.setheading(angle)                # 转向
    t.forward(20)                      # 走一步

print("碰到边界了！漫步结束。")

t.clear()

# ========== 进阶版：随机漫步 + continue 怪癖 ==========
print()
print("===== 有怪癖：绝不往右上走（0~90度跳过）=====")
t.penup()
t.goto(0, 0)
t.pendown()
t.color("purple")

while -200 < t.xcor() < 200 and -200 < t.ycor() < 200:
    angle = random.randint(0, 360)

    # ⭐ 怪癖！如果角度在 0~90 之间（右上方向），跳过！
    if 0 <= angle <= 90:
        continue                     # ← continue！跳过后面，重新随机方向

    t.setheading(angle)
    t.forward(20)

print("碰到边界了！漫步结束。")

# ========== 动手试试 ==========
# TODO ①：把怪癖条件改成 if 180 <= angle <= 270: continue（不往下走）
#         观察路线有什么变化？
#
# TODO ②：试试 if angle % 2 != 0: continue（只走偶数角度）
#         乌龟会怎么走？
#
# TODO ③：自定义你的怪癖！
#         if ________: continue
#

# ========== 拓展思考 ==========
# Q: 删掉 continue 那两行 → 纯随机漫步（所有方向等概率）
# Q: 加上 continue → 乌龟有了"偏好"
#    这就是游戏 AI 的基础——"有些方向怪物不愿意走"

t.hideturtle()
turtle.done()
