Teaching an AI agent to navigate through a maze using reinforcement learning
A simple reinforcement learning project where an AI agent learns to find the shortest path through an 11×11 maze using Q-Learning. The agent explores the maze, learns from rewards, and discovers the optimal route!
- Maze Environment - 11×11 grid with walls (-100), paths (-1), and goal (+100)
- Agent Exploration - Random start position, explores with epsilon-greedy strategy
- Learning - Updates Q-table based on rewards and future states
- Optimal Path - After 1000 episodes, finds shortest route to exit
- State: Current position in maze
- Action: Move up, down, left, or right
- Reward: +100 for goal, -1 for path, -100 for walls
- Q-Table: Learns value of each action at each position
python qlearning.pyThat's it! Watch the agent learn and find the optimal path.
lr = 0.9 # Learning rate
gamma = 0.9 # Discount factor
epsilon = 0.9 # Exploration rate
episodes = 1000 # Training iterationsThe agent successfully learns the shortest path from start [9,1] to goal [3,10] after training!
Bir yapay zeka ajanının Q-Learning kullanarak 11×11'lik bir labirentten en kısa yolu bulmasını öğrendiği basit bir pekiştirmeli öğrenme projesi. Ajan labirenti keşfeder, ödüllerden öğrenir ve optimal rotayı keşfeder!
- Labirent Ortamı - Duvarlar (-100), yollar (-1) ve hedef (+100) olan 11×11 ızgara
- Ajan Keşfi - Rastgele başlangıç, epsilon-greedy stratejisi ile keşif
- Öğrenme - Ödüllere ve gelecek durumlara göre Q-tablosunu günceller
- Optimal Yol - 1000 bölümden sonra çıkışa en kısa yolu bulur
- Durum (State): Labirentteki mevcut konum
- Eylem (Action): Yukarı, aşağı, sola veya sağa hareket
- Ödül (Reward): Hedef için +100, yol için -1, duvarlar için -100
- Q-Tablosu: Her konumdaki her eylemin değerini öğrenir
python qlearning.pyBu kadar! Ajanın öğrenmesini ve optimal yolu bulmasını izleyin.
lr = 0.9 # Öğrenme oranı
gamma = 0.9 # İndirim faktörü
epsilon = 0.9 # Keşif oranı
episodes = 1000 # Eğitim tekrarıAjan eğitim sonrası başlangıç [9,1] noktasından hedef [3,10] noktasına en kısa yolu başarıyla öğrenir!
