https://github.com/hlfshell/ai_playground
Playground repos while playing with artificial intelligence algorithms
https://github.com/hlfshell/ai_playground
Last synced: 12 months ago
JSON representation
Playground repos while playing with artificial intelligence algorithms
- Host: GitHub
- URL: https://github.com/hlfshell/ai_playground
- Owner: hlfshell
- Created: 2020-10-18T19:57:04.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-01T03:18:47.000Z (almost 5 years ago)
- Last Synced: 2025-02-09T17:14:47.623Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 2.69 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AI Playground
Playground repos while playing with AI algorithms
## Search Algorithms
Search algorithms can be found in the `search` folder. Within, you'll find these files:
* `test.py` - will generate a random map and attempt to traverse it with each of the available algorithms. IF the map generated can't be solved, it'll error out.
- `searcher.py` - A generic `Searcher` class that sets up and manages basics a searcher would need. Expects children to implement a `step` function which expans the robot's consideration of a path by one "step" in its search algorithm.
- `grid.py` - a `Grid` class with internal functions that provide utility functions that include:
- The ability to read and write grids to a text file with any CSV support (default is space delimited). This means a simple spreadsheet app can be used to easily generate maps.
- The ability to draw the map out to an image
- Controlled moving of a "robot" around the map, neighbor finding, obstacle awareness, goal awareness, etc.
Within the `grid.py` file there is also a `GridGIFMaker` class which accepts a grid and can generate a gif of a given `Searcher` class. There is also a `grid_generator` that makes random `Grid` objects.
- `breadth_first_search.py` - implements a `BFS` breadth first search `Searcher`
- `depth_first_search.py` - implements a `DFS` depth first search `Searcher`
- `a_star.py` - this implements an A* searcher that uses simple euclidean distance for its cost function.
### Search Examples
#### Breadth First Search

#### Depth First Search

#### A* Search

## Min Max
To experiment with the `min max` algorithm I coded up a **Connect 4** game. The files of note here are:
- `connect_four_board.py` - this is similar to `grid.py` before - it implements the connect four board of any given size, handles placing a piece (and having it "fall" to the correct place), has built in checks to determine a winner, and image drawing/gif writing capabilities.
- `play_connect_four.py` - is a file that will have an in-terminal game of connect four against a bot as specified in the code.
- `random_connect_four.py` - as a quick test and comparison bot, this bot literally just picks a random legal move each turn
- `min_max_connect_four.py` - implements a minmax bot that plays connect four. It has a specifiable depth (defaults to 4) for how many turns ahead it must view.
- `random_vs_minmax_connect_four.py` - pits the minmax bot against the random bot for 100 matches of Connect 4
### Example GIFs
#### Random (Red) vs Minmax (Blue) - 100 Games
*minmax bot won 99 of 100 games against the random bot*
