<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pacman | 정진영의 포트폴리오</title><link>https://wjdwlsdud.github.io/en/tags/pacman/</link><atom:link href="https://wjdwlsdud.github.io/en/tags/pacman/index.xml" rel="self" type="application/rss+xml"/><description>Pacman</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Sat, 01 Mar 2025 00:00:00 +0000</lastBuildDate><image><url>https://wjdwlsdud.github.io/media/sharing.jpg</url><title>Pacman</title><link>https://wjdwlsdud.github.io/en/tags/pacman/</link></image><item><title>Pacman</title><link>https://wjdwlsdud.github.io/en/projects/pacman/</link><pubDate>Sat, 01 Mar 2025 00:00:00 +0000</pubDate><guid>https://wjdwlsdud.github.io/en/projects/pacman/</guid><description>&lt;p&gt;This is the UC Berkeley Pacman AI project I completed as part of my Artificial Intelligence and Data Structures coursework. The core objective of this assignment was to implement fundamental Graph Search algorithms from scratch and apply them to solve tangible problems within the Pacman game environment.&lt;/p&gt;
&lt;p&gt;My work involved implementing generic search algorithms in &lt;strong&gt;search.py&lt;/strong&gt; and defining/solving specific Pacman problems in &lt;strong&gt;searchAgents.py&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="1-core-search-algorithm-implementation-searchpy"&gt;1. Core Search Algorithm Implementation (search.py)&lt;/h2&gt;
&lt;p&gt;First, I implemented four fundamental search algorithms that can be applied to any search problem.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DFS (Depth-First Search): Using a &lt;strong&gt;Stack&lt;/strong&gt;, this algorithm explores nodes as deeply as possible first. It was implemented as a graph search, using an &lt;strong&gt;explored&lt;/strong&gt; list to prevent cycles.&lt;/li&gt;
&lt;li&gt;BFS (Breadth-First Search): Using a &lt;strong&gt;Queue&lt;/strong&gt;, this algorithm explores the shallowest (closest) nodes first. It guarantees the shortest path when all edge costs are uniform.&lt;/li&gt;
&lt;li&gt;UCS (Uniform Cost Search): Using a &lt;strong&gt;PriorityQueue&lt;/strong&gt;, this algorithm prioritizes nodes by their total cumulative &amp;lsquo;cost&amp;rsquo;. It always explores the path with the lowest cost first, guaranteeing the shortest cost path.&lt;/li&gt;
&lt;li&gt;A* (A-Star) Search: Also uses a &lt;strong&gt;PriorityQueue&lt;/strong&gt;, but its priority is the sum of the &amp;lsquo;cumulative cost to date&amp;rsquo; ($g(n)$) and an &amp;rsquo;estimated cost to the goal&amp;rsquo; (heuristic, $h(n)$). This function is $f(n) = g(n) + h(n)$. As an informed search, it finds the optimal solution far more efficiently than UCS.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="2-defining-and-solving-pacman-problems-searchagentspy"&gt;2. Defining and Solving Pacman Problems (searchAgents.py)&lt;/h2&gt;
&lt;p&gt;Beyond just implementing the algorithms, I modeled complex problems Pacman faces as formal &amp;lsquo;search problems&amp;rsquo; and solved them.&lt;/p&gt;
&lt;p&gt;📍 The Corners Problem (CornersProblem)
The challenge is to find a path for Pacman to visit all four corners of the map.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;State Definition: To solve this, the state space couldn&amp;rsquo;t just be (x, y). I defined the state as &lt;strong&gt;(currentPosition, (visitedCornersTuple))&lt;/strong&gt;. For example, a state might be &lt;strong&gt;((5, 5), (True, False, False, True))&lt;/strong&gt;, tracking both the position and the visit-status of each corner.&lt;/li&gt;
&lt;li&gt;Goal Definition: The goal state is reached when all boolean values in the tuple state[1] are &lt;strong&gt;True&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Successor Function: As Pacman moves, the function checks if the new position is one of the corners. If it is, it generates a new state with the corresponding boolean in the tuple updated to &lt;strong&gt;True&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;💡 Corners Problem Heuristic (cornersHeuristic)&lt;/p&gt;
&lt;p&gt;I designed a heuristic for solving the Corners Problem using A* search.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Design: A heuristic must be admissible (never overestimates the true cost).&lt;/li&gt;
&lt;li&gt;Logic: The function calculates the Manhattan Distance from the &amp;lsquo;current position&amp;rsquo; to &amp;rsquo;every unvisited corner&amp;rsquo;. It then returns the maximum (max) value among these distances.&lt;/li&gt;
&lt;li&gt;Justification: This is admissible because Pacman must travel at least as far as the farthest remaining corner to complete the goal. This value serves as a safe lower bound on the true remaining cost.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;🍔 All Food Heuristic (foodHeuristic)&lt;/p&gt;
&lt;p&gt;This heuristic was for the &lt;strong&gt;FoodSearchProblem&lt;/strong&gt;, which involves finding a path to eat all the food dots on the map.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Logic: Similar to the corners heuristic, I calculated the actual maze distance (&lt;strong&gt;mazeDistance&lt;/strong&gt;) from the &amp;lsquo;current position&amp;rsquo; to &amp;rsquo;every remaining food dot&amp;rsquo; and returned the maximum (max) value.&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;mazeDistance&lt;/strong&gt;: Unlike Manhattan distance, &lt;strong&gt;mazeDistance&lt;/strong&gt; is a helper function that runs a BFS to find the true shortest path considering walls, providing a much more accurate (and still admissible) estimate.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;🎯 Closest Dot Search Agent&lt;/p&gt;
&lt;p&gt;Finding a path to eat all food is very complex (NP-hard). Therefore, I implemented a greedy algorithm that repeatedly finds and eats the closest food dot.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;findPathToClosestDot&lt;/strong&gt; Implementation: I defined a sub-problem called &lt;strong&gt;AnyFoodSearchProblem&lt;/strong&gt; (where the goal is to reach any single food dot).&lt;/li&gt;
&lt;li&gt;Using UCS: I applied &lt;strong&gt;UCS&lt;/strong&gt; to this sub-problem. This finds the path to the food dot with the lowest cost (i.e., the closest dot). (Since costs are uniform, &lt;strong&gt;BFS&lt;/strong&gt; would also have guaranteed the same result).&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>