Sup fellow coders! π€ Dumping my AI algorithm collection from those loooong college nights when coffee was my best friend and sleep was just a concept.
- π οΈ What's Inside
- βοΈ Installation
- π How to Run
- πΎ Algorithm Breakdown
- β Java Version
- π€ Contributing
β οΈ Disclaimer
Here's the AI stuff I survived implementing:
π Search Algorithms - Finding paths through problems
Algorithm | Description | File |
---|---|---|
DFS | Depth-First Search - Goes as deep as possible before backtracking | DFS_DLS_DFID.py |
DLS | Depth-Limited Search - Like DFS but with a "that's deep enough, I'm out" limit | DFS_DLS_DFID.py |
DFID | Depth-First Iterative Deepening - Combines BFS's completeness with DFS's memory efficiency | DFS_DLS_DFID.py |
BFS | Breadth-First Search - Explores all neighbors before going deeper | BFS_UCS.py |
UCS | Uniform Cost Search - Like BFS but considers path costs | BFS_UCS.py |
GBFS | Greedy Best-First Search - The impatient algorithm that always chases what looks good | GBFS_Astar.py |
A* | A-Star - Uses heuristics to find optimal paths efficiently | GBFS_Astar.py |
β°οΈ Hill Climbing - Just keeps going up until it can't anymore
Simple optimization algorithm that:
- Starts at a random solution
- Iteratively makes small improvements
- Stops when no better neighbor exists
- Often gets stuck in local maxima
def hill_climbing(problem):
current = problem.initial()
while True:
neighbor = problem.best_neighbor(current)
if problem.value(neighbor) <= problem.value(current):
return current
current = neighbor
𧬠Genetic Algorithms - Digital Darwin stuff where code evolves and the fittest survives
Evolution-inspired approach that:
- Creates a population of potential solutions
- Evaluates their fitness
- Selects the best individuals
- Creates new solutions through crossover and mutation
- Repeats until convergence
π§ Prolog - Logic programming that'll make you question your life choices π€
Python implementations of logic programming concepts:
- Knowledge representation
- Rule-based systems
- Logical inference
# Clone this repository
git clone https://github.com/Jia2005/AI-codes-in-Python.git
# Navigate into the directory
cd AI-codes-in-Python
# No external dependencies required - just Python 3.6+
# Run any algorithm (example with BFS/UCS)
python3 BFS_UCS.py
# Run other algorithms
python3 DFS.py
python3 DFID.py
python3 A_star.py
BFS DFS
ββββββββββββ ββββββββββββ
[1] [1]
β β β β
[2] [3] [2] [3]
β β β β β β β
4 5 6 7 4 6 7
β
5
- BFS/DFS: Think of these as different ways to explore a maze - BFS goes wide, DFS goes deep
- A*: The overachiever that finds optimal paths while being smart about it
- Genetic Algorithms: Digital survival of the fittest - letting solutions evolve through generations
- Hill Climbing: Like hiking with no map - just keep going up and hope for the best
More of a Java person? No judgment (ok maybe a little π)
Found a bug? Have a better way to implement something? Open a pull request!
1. Fork the repository
2. Create your feature branch: git checkout -b amazing-feature
3. Commit your changes: git commit -m 'Add some amazing feature'
4. Push to the branch: git push origin amazing-feature
5. Open a pull request
If this helped you with your assignments or understanding AI concepts, a star β would be awesome.
No pressure... (but seriously, it takes like 2 seconds)
Fair warning: This is college-assignment-level code. It works, it's readable, but it's not winning any optimization awards.