cp2025 計算機程式

  • Home
    • SMap
    • reveal
    • blog
  • About
    • cs101
    • Computer
      • llama
      • nginx
    • AI
      • QandA
      • Teams
    • Homework
  • Topics
    • Git
      • Git_ex1
      • Git_ex2
    • Python
      • SE
      • CL
      • Loops
      • Recursion
      • SA
      • SST
      • Maze
      • Collect
      • GT
      • Python_ex1
    • Javascript
      • HTML and CSS
    • Project
      • Waitress
      • API
  • Brython
    • Brython_ex
    • Robot_ex
  • Ref
    • Reeborg
      • ex1
      • Otto_ninja
    • tkinter
    • Pyodide
    • Pyodide_ex
    • Pyodide2
      • robot.py
      • Example2
    • Pyodide3
      • png_files
      • Harvest
Collect << Previous Next >> Python_ex1

GT

Graph Theory

建構地圖或路徑(圖論基礎)
模擬圖的節點與邊,探索所有可能路徑。

# 範例 1:探索所有方向(模擬圖的鄰接節點)
for i in range(4):
    if not wall_in_front():
        move()
        # 模擬記錄節點
        turn_left()
        turn_left()
        move()
        turn_left()
        turn_left()
    turn_left()

# 範例 2:記錄路徑(用清單模擬)
path = []
while not wall_in_front():
    move()
    path.append("forward")

# 範例 3:模擬圖的 DFS
def dfs_graph():
    for i in range(4):
        if not wall_in_front():
            move()
            dfs_graph()
            turn_left()
            turn_left()
            move()
            turn_left()
            turn_left()
        turn_left()

dfs_graph()


Collect << Previous Next >> Python_ex1

Copyright © All rights reserved | This template is made with by Colorlib