heapplot 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- heapplot-1.0.0/LICENSE +21 -0
- heapplot-1.0.0/PKG-INFO +168 -0
- heapplot-1.0.0/README.md +142 -0
- heapplot-1.0.0/heapplot/__init__.py +143 -0
- heapplot-1.0.0/heapplot/alphabeta.py +57 -0
- heapplot-1.0.0/heapplot/astar.py +47 -0
- heapplot-1.0.0/heapplot/bayesian.py +49 -0
- heapplot-1.0.0/heapplot/bestfirst.py +43 -0
- heapplot-1.0.0/heapplot/bfs.py +39 -0
- heapplot-1.0.0/heapplot/dfs.py +34 -0
- heapplot-1.0.0/heapplot/dls.py +37 -0
- heapplot-1.0.0/heapplot/forwardchaining.py +54 -0
- heapplot-1.0.0/heapplot/goalstack.py +91 -0
- heapplot-1.0.0/heapplot/hillclimbing.py +42 -0
- heapplot-1.0.0/heapplot/missionarycannibals.py +63 -0
- heapplot-1.0.0/heapplot/nqueens.py +65 -0
- heapplot-1.0.0/heapplot/puzzle8.py +57 -0
- heapplot-1.0.0/heapplot.egg-info/PKG-INFO +168 -0
- heapplot-1.0.0/heapplot.egg-info/SOURCES.txt +21 -0
- heapplot-1.0.0/heapplot.egg-info/dependency_links.txt +1 -0
- heapplot-1.0.0/heapplot.egg-info/top_level.txt +1 -0
- heapplot-1.0.0/pyproject.toml +42 -0
- heapplot-1.0.0/setup.cfg +4 -0
heapplot-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 heapplot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
heapplot-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: heapplot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: AI Lab Code Reference Package — Automation toolkit for AI game engine logic in VR headset development. Instantly print complete source code for classic AI algorithms: BFS, DFS, DLS, Best First Search, A*, 8-Puzzle, N-Queens, Hill Climbing, Alpha-Beta Pruning, Missionaries & Cannibals, Goal Stack Planning, Forward Chaining, and Bayesian Networks.
|
|
5
|
+
Author: heapplot
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/heapplot/
|
|
8
|
+
Keywords: ai,artificial-intelligence,algorithms,search,bfs,dfs,astar,a-star,alpha-beta,alphabeta,minimax,hill-climbing,bayesian,forward-chaining,n-queens,csp,8-puzzle,goal-stack,missionaries-cannibals,vr,game-engine,education
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Education
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# heapplot
|
|
28
|
+
|
|
29
|
+
> **AI Lab Code Reference Package** — Automation toolkit for AI game engine logic in VR headset development.
|
|
30
|
+
|
|
31
|
+
`heapplot` was born out of the need to rapidly prototype and reference classic AI decision-making algorithms for an automation layer powering game engine AI in VR headsets. Each function in this package prints the complete, ready-to-run source code of a specific AI algorithm directly to your terminal — making it a lightning-fast reference for AI developers and students alike.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 📦 Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install heapplot
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🚀 Usage
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import heapplot
|
|
47
|
+
|
|
48
|
+
# See all available functions
|
|
49
|
+
heapplot.help()
|
|
50
|
+
|
|
51
|
+
# Print the code for any algorithm
|
|
52
|
+
heapplot.bfs()
|
|
53
|
+
heapplot.alphabeta()
|
|
54
|
+
heapplot.bayesian()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 📚 Available Functions
|
|
60
|
+
|
|
61
|
+
| Function | Assignment | Concept |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `heapplot.bfs()` | 1 | Breadth First Search |
|
|
64
|
+
| `heapplot.dfs()` | 1 | Depth First Search |
|
|
65
|
+
| `heapplot.dls()` | 1 | Depth Limited Search |
|
|
66
|
+
| `heapplot.bestfirst()` | 2 | Best First Search |
|
|
67
|
+
| `heapplot.astar()` | 2 | A* Algorithm |
|
|
68
|
+
| `heapplot.puzzle8()` | 3 | 8-Puzzle Problem (A* with misplaced tiles heuristic) |
|
|
69
|
+
| `heapplot.nqueens()` | 4 | N-Queens (Constraint Satisfaction / Backtracking) |
|
|
70
|
+
| `heapplot.hillclimbing()` | 5 | Hill Climbing Algorithm |
|
|
71
|
+
| `heapplot.alphabeta()` | 6 | Alpha-Beta Pruning (Minimax Game Trees) |
|
|
72
|
+
| `heapplot.missionarycannibals()` | 7 | Missionaries & Cannibals (A*) |
|
|
73
|
+
| `heapplot.goalstack()` | 8 | Goal Stack Planning (Blocks World / STRIPS) |
|
|
74
|
+
| `heapplot.forwardchaining()` | 9 | Forward Chaining Inference Engine |
|
|
75
|
+
| `heapplot.bayesian()` | 10 | Bayesian Network (Student Exam Performance) |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🧠 Algorithm Details
|
|
80
|
+
|
|
81
|
+
### Assignment 1 — Search Algorithms
|
|
82
|
+
|
|
83
|
+
#### `heapplot.bfs()` — Breadth First Search
|
|
84
|
+
Level-by-level graph traversal using a deque queue. Guarantees shortest path in unweighted graphs.
|
|
85
|
+
|
|
86
|
+
#### `heapplot.dfs()` — Depth First Search
|
|
87
|
+
Recursive depth-first traversal. Explores as far as possible before backtracking.
|
|
88
|
+
|
|
89
|
+
#### `heapplot.dls()` — Depth Limited Search
|
|
90
|
+
DFS with a depth limit to prevent infinite loops in deep/cyclic graphs.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Assignment 2 — Heuristic Search
|
|
95
|
+
|
|
96
|
+
#### `heapplot.bestfirst()` — Best First Search
|
|
97
|
+
Greedy search that expands the node with the lowest heuristic value using a priority queue.
|
|
98
|
+
|
|
99
|
+
#### `heapplot.astar()` — A* Algorithm
|
|
100
|
+
Optimal search combining path cost `g` and heuristic `h` → `f = g + h`.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### Assignment 3 — Puzzle Solving
|
|
105
|
+
|
|
106
|
+
#### `heapplot.puzzle8()` — 8-Puzzle Problem
|
|
107
|
+
A* solution for the 8-tile sliding puzzle using misplaced tiles as the heuristic.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### Assignment 4 — Constraint Satisfaction
|
|
112
|
+
|
|
113
|
+
#### `heapplot.nqueens()` — N-Queens Problem
|
|
114
|
+
Backtracking CSP solver that places N non-attacking queens on an N×N chessboard.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### Assignment 5 — Local Search
|
|
119
|
+
|
|
120
|
+
#### `heapplot.hillclimbing()` — Hill Climbing
|
|
121
|
+
Greedy local search that always moves to the neighbour with the best heuristic.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### Assignment 6 — Game Tree Search
|
|
126
|
+
|
|
127
|
+
#### `heapplot.alphabeta()` — Alpha-Beta Pruning
|
|
128
|
+
Minimax algorithm with alpha-beta pruning to eliminate branches that cannot affect the result. Core to adversarial AI in game engines.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### Assignment 7 — Planning with Search
|
|
133
|
+
|
|
134
|
+
#### `heapplot.missionarycannibals()` — Missionaries & Cannibals
|
|
135
|
+
A* solution to the classic river-crossing puzzle with safety constraints.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### Assignment 8 — AI Planning
|
|
140
|
+
|
|
141
|
+
#### `heapplot.goalstack()` — Goal Stack Planning
|
|
142
|
+
STRIPS-style planning using a goal stack and operators (STACK, UNSTACK, PICKUP, PUTDOWN) in a blocks world domain.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### Assignment 9 — Knowledge Representation
|
|
147
|
+
|
|
148
|
+
#### `heapplot.forwardchaining()` — Forward Chaining
|
|
149
|
+
Data-driven inference engine that repeatedly applies rules to derive new facts until a query is satisfied.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### Assignment 10 — Probabilistic AI
|
|
154
|
+
|
|
155
|
+
#### `heapplot.bayesian()` — Bayesian Network
|
|
156
|
+
Joint probability computation over a student exam performance Bayesian Network using Conditional Probability Tables (CPTs).
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🎮 Why heapplot?
|
|
161
|
+
|
|
162
|
+
`heapplot` was originally developed as an automation reference layer for an AI game engine powering VR headsets. The core algorithms — from minimax and alpha-beta pruning for adversarial NPC behaviour, to A* and BFS for pathfinding, to Bayesian networks for probabilistic decision-making — form the backbone of intelligent behaviour in VR environments.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 📄 License
|
|
167
|
+
|
|
168
|
+
MIT License
|
heapplot-1.0.0/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# heapplot
|
|
2
|
+
|
|
3
|
+
> **AI Lab Code Reference Package** — Automation toolkit for AI game engine logic in VR headset development.
|
|
4
|
+
|
|
5
|
+
`heapplot` was born out of the need to rapidly prototype and reference classic AI decision-making algorithms for an automation layer powering game engine AI in VR headsets. Each function in this package prints the complete, ready-to-run source code of a specific AI algorithm directly to your terminal — making it a lightning-fast reference for AI developers and students alike.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install heapplot
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🚀 Usage
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import heapplot
|
|
21
|
+
|
|
22
|
+
# See all available functions
|
|
23
|
+
heapplot.help()
|
|
24
|
+
|
|
25
|
+
# Print the code for any algorithm
|
|
26
|
+
heapplot.bfs()
|
|
27
|
+
heapplot.alphabeta()
|
|
28
|
+
heapplot.bayesian()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 📚 Available Functions
|
|
34
|
+
|
|
35
|
+
| Function | Assignment | Concept |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `heapplot.bfs()` | 1 | Breadth First Search |
|
|
38
|
+
| `heapplot.dfs()` | 1 | Depth First Search |
|
|
39
|
+
| `heapplot.dls()` | 1 | Depth Limited Search |
|
|
40
|
+
| `heapplot.bestfirst()` | 2 | Best First Search |
|
|
41
|
+
| `heapplot.astar()` | 2 | A* Algorithm |
|
|
42
|
+
| `heapplot.puzzle8()` | 3 | 8-Puzzle Problem (A* with misplaced tiles heuristic) |
|
|
43
|
+
| `heapplot.nqueens()` | 4 | N-Queens (Constraint Satisfaction / Backtracking) |
|
|
44
|
+
| `heapplot.hillclimbing()` | 5 | Hill Climbing Algorithm |
|
|
45
|
+
| `heapplot.alphabeta()` | 6 | Alpha-Beta Pruning (Minimax Game Trees) |
|
|
46
|
+
| `heapplot.missionarycannibals()` | 7 | Missionaries & Cannibals (A*) |
|
|
47
|
+
| `heapplot.goalstack()` | 8 | Goal Stack Planning (Blocks World / STRIPS) |
|
|
48
|
+
| `heapplot.forwardchaining()` | 9 | Forward Chaining Inference Engine |
|
|
49
|
+
| `heapplot.bayesian()` | 10 | Bayesian Network (Student Exam Performance) |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 🧠 Algorithm Details
|
|
54
|
+
|
|
55
|
+
### Assignment 1 — Search Algorithms
|
|
56
|
+
|
|
57
|
+
#### `heapplot.bfs()` — Breadth First Search
|
|
58
|
+
Level-by-level graph traversal using a deque queue. Guarantees shortest path in unweighted graphs.
|
|
59
|
+
|
|
60
|
+
#### `heapplot.dfs()` — Depth First Search
|
|
61
|
+
Recursive depth-first traversal. Explores as far as possible before backtracking.
|
|
62
|
+
|
|
63
|
+
#### `heapplot.dls()` — Depth Limited Search
|
|
64
|
+
DFS with a depth limit to prevent infinite loops in deep/cyclic graphs.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### Assignment 2 — Heuristic Search
|
|
69
|
+
|
|
70
|
+
#### `heapplot.bestfirst()` — Best First Search
|
|
71
|
+
Greedy search that expands the node with the lowest heuristic value using a priority queue.
|
|
72
|
+
|
|
73
|
+
#### `heapplot.astar()` — A* Algorithm
|
|
74
|
+
Optimal search combining path cost `g` and heuristic `h` → `f = g + h`.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### Assignment 3 — Puzzle Solving
|
|
79
|
+
|
|
80
|
+
#### `heapplot.puzzle8()` — 8-Puzzle Problem
|
|
81
|
+
A* solution for the 8-tile sliding puzzle using misplaced tiles as the heuristic.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
### Assignment 4 — Constraint Satisfaction
|
|
86
|
+
|
|
87
|
+
#### `heapplot.nqueens()` — N-Queens Problem
|
|
88
|
+
Backtracking CSP solver that places N non-attacking queens on an N×N chessboard.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### Assignment 5 — Local Search
|
|
93
|
+
|
|
94
|
+
#### `heapplot.hillclimbing()` — Hill Climbing
|
|
95
|
+
Greedy local search that always moves to the neighbour with the best heuristic.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
### Assignment 6 — Game Tree Search
|
|
100
|
+
|
|
101
|
+
#### `heapplot.alphabeta()` — Alpha-Beta Pruning
|
|
102
|
+
Minimax algorithm with alpha-beta pruning to eliminate branches that cannot affect the result. Core to adversarial AI in game engines.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### Assignment 7 — Planning with Search
|
|
107
|
+
|
|
108
|
+
#### `heapplot.missionarycannibals()` — Missionaries & Cannibals
|
|
109
|
+
A* solution to the classic river-crossing puzzle with safety constraints.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
### Assignment 8 — AI Planning
|
|
114
|
+
|
|
115
|
+
#### `heapplot.goalstack()` — Goal Stack Planning
|
|
116
|
+
STRIPS-style planning using a goal stack and operators (STACK, UNSTACK, PICKUP, PUTDOWN) in a blocks world domain.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### Assignment 9 — Knowledge Representation
|
|
121
|
+
|
|
122
|
+
#### `heapplot.forwardchaining()` — Forward Chaining
|
|
123
|
+
Data-driven inference engine that repeatedly applies rules to derive new facts until a query is satisfied.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### Assignment 10 — Probabilistic AI
|
|
128
|
+
|
|
129
|
+
#### `heapplot.bayesian()` — Bayesian Network
|
|
130
|
+
Joint probability computation over a student exam performance Bayesian Network using Conditional Probability Tables (CPTs).
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🎮 Why heapplot?
|
|
135
|
+
|
|
136
|
+
`heapplot` was originally developed as an automation reference layer for an AI game engine powering VR headsets. The core algorithms — from minimax and alpha-beta pruning for adversarial NPC behaviour, to A* and BFS for pathfinding, to Bayesian networks for probabilistic decision-making — form the backbone of intelligent behaviour in VR environments.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 📄 License
|
|
141
|
+
|
|
142
|
+
MIT License
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""
|
|
2
|
+
heapplot - AI Lab Assignment Code Reference Package
|
|
3
|
+
====================================================
|
|
4
|
+
|
|
5
|
+
A Python package that prints the complete source code of classic AI algorithms
|
|
6
|
+
from university lab assignments directly to your terminal.
|
|
7
|
+
|
|
8
|
+
Built to automate AI game engine logic references for VR headset development.
|
|
9
|
+
|
|
10
|
+
Available Functions
|
|
11
|
+
-------------------
|
|
12
|
+
Assignment 1 - Search Algorithms:
|
|
13
|
+
heapplot.bfs() - Breadth First Search
|
|
14
|
+
heapplot.dfs() - Depth First Search
|
|
15
|
+
heapplot.dls() - Depth Limited Search
|
|
16
|
+
|
|
17
|
+
Assignment 2 - Heuristic Search:
|
|
18
|
+
heapplot.bestfirst() - Best First Search
|
|
19
|
+
heapplot.astar() - A* Algorithm (graph)
|
|
20
|
+
|
|
21
|
+
Assignment 3 - Puzzle Solving:
|
|
22
|
+
heapplot.puzzle8() - 8-Puzzle Problem (A* with misplaced tiles)
|
|
23
|
+
|
|
24
|
+
Assignment 4 - Constraint Satisfaction:
|
|
25
|
+
heapplot.nqueens() - N-Queens Problem (CSP with Backtracking)
|
|
26
|
+
|
|
27
|
+
Assignment 5 - Local Search:
|
|
28
|
+
heapplot.hillclimbing() - Hill Climbing Algorithm
|
|
29
|
+
|
|
30
|
+
Assignment 6 - Game Tree Search:
|
|
31
|
+
heapplot.alphabeta() - Alpha-Beta Pruning (Minimax)
|
|
32
|
+
|
|
33
|
+
Assignment 7 - Planning with Search:
|
|
34
|
+
heapplot.missionarycannibals() - Missionaries & Cannibals (A*)
|
|
35
|
+
|
|
36
|
+
Assignment 8 - AI Planning:
|
|
37
|
+
heapplot.goalstack() - Goal Stack Planning (Blocks World)
|
|
38
|
+
|
|
39
|
+
Assignment 9 - Knowledge Representation:
|
|
40
|
+
heapplot.forwardchaining() - Forward Chaining Inference
|
|
41
|
+
|
|
42
|
+
Assignment 10 - Probabilistic AI:
|
|
43
|
+
heapplot.bayesian() - Bayesian Network (Student Exam Performance)
|
|
44
|
+
|
|
45
|
+
Usage
|
|
46
|
+
-----
|
|
47
|
+
import heapplot
|
|
48
|
+
|
|
49
|
+
heapplot.bfs()
|
|
50
|
+
heapplot.alphabeta()
|
|
51
|
+
heapplot.bayesian()
|
|
52
|
+
# ... etc
|
|
53
|
+
|
|
54
|
+
Or use heapplot.help() to list all available functions.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
from .bfs import bfs
|
|
58
|
+
from .dfs import dfs
|
|
59
|
+
from .dls import dls
|
|
60
|
+
from .bestfirst import bestfirst
|
|
61
|
+
from .astar import astar
|
|
62
|
+
from .puzzle8 import puzzle8
|
|
63
|
+
from .nqueens import nqueens
|
|
64
|
+
from .hillclimbing import hillclimbing
|
|
65
|
+
from .alphabeta import alphabeta
|
|
66
|
+
from .missionarycannibals import missionarycannibals
|
|
67
|
+
from .goalstack import goalstack
|
|
68
|
+
from .forwardchaining import forwardchaining
|
|
69
|
+
from .bayesian import bayesian
|
|
70
|
+
|
|
71
|
+
__version__ = "1.0.0"
|
|
72
|
+
__author__ = "heapplot"
|
|
73
|
+
__description__ = (
|
|
74
|
+
"AI Lab Assignment Code Reference Package - "
|
|
75
|
+
"Automation toolkit for AI game engine logic in VR headset development"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
__all__ = [
|
|
79
|
+
"bfs",
|
|
80
|
+
"dfs",
|
|
81
|
+
"dls",
|
|
82
|
+
"bestfirst",
|
|
83
|
+
"astar",
|
|
84
|
+
"puzzle8",
|
|
85
|
+
"nqueens",
|
|
86
|
+
"hillclimbing",
|
|
87
|
+
"alphabeta",
|
|
88
|
+
"missionarycannibals",
|
|
89
|
+
"goalstack",
|
|
90
|
+
"forwardchaining",
|
|
91
|
+
"bayesian",
|
|
92
|
+
"help",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def help():
|
|
97
|
+
"""
|
|
98
|
+
Print all available heapplot functions with their descriptions.
|
|
99
|
+
Usage: heapplot.help()
|
|
100
|
+
"""
|
|
101
|
+
print("""
|
|
102
|
+
╔══════════════════════════════════════════════════════════════════════════╗
|
|
103
|
+
║ heapplot - AI Lab Code Reference ║
|
|
104
|
+
║ Automation Toolkit for VR Headset AI Game Engine Logic ║
|
|
105
|
+
╚══════════════════════════════════════════════════════════════════════════╝
|
|
106
|
+
|
|
107
|
+
Assignment 1 - Search Algorithms:
|
|
108
|
+
heapplot.bfs() Breadth First Search
|
|
109
|
+
heapplot.dfs() Depth First Search
|
|
110
|
+
heapplot.dls() Depth Limited Search
|
|
111
|
+
|
|
112
|
+
Assignment 2 - Heuristic Search:
|
|
113
|
+
heapplot.bestfirst() Best First Search
|
|
114
|
+
heapplot.astar() A* Algorithm
|
|
115
|
+
|
|
116
|
+
Assignment 3 - Puzzle Solving:
|
|
117
|
+
heapplot.puzzle8() 8-Puzzle Problem (A* search)
|
|
118
|
+
|
|
119
|
+
Assignment 4 - Constraint Satisfaction:
|
|
120
|
+
heapplot.nqueens() N-Queens Problem (CSP / Backtracking)
|
|
121
|
+
|
|
122
|
+
Assignment 5 - Local Search:
|
|
123
|
+
heapplot.hillclimbing() Hill Climbing Algorithm
|
|
124
|
+
|
|
125
|
+
Assignment 6 - Game Tree Search:
|
|
126
|
+
heapplot.alphabeta() Alpha-Beta Pruning (Minimax)
|
|
127
|
+
|
|
128
|
+
Assignment 7 - Planning with Search:
|
|
129
|
+
heapplot.missionarycannibals() Missionaries & Cannibals (A*)
|
|
130
|
+
|
|
131
|
+
Assignment 8 - AI Planning:
|
|
132
|
+
heapplot.goalstack() Goal Stack Planning (Blocks World)
|
|
133
|
+
|
|
134
|
+
Assignment 9 - Knowledge Representation:
|
|
135
|
+
heapplot.forwardchaining() Forward Chaining Inference Engine
|
|
136
|
+
|
|
137
|
+
Assignment 10 - Probabilistic AI:
|
|
138
|
+
heapplot.bayesian() Bayesian Network
|
|
139
|
+
|
|
140
|
+
──────────────────────────────────────────────────────────────────────────
|
|
141
|
+
Call any function to print its full source code to the terminal.
|
|
142
|
+
Example: heapplot.alphabeta()
|
|
143
|
+
""")
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Assignment 6: Alpha-Beta Pruning"""
|
|
2
|
+
|
|
3
|
+
CODE = '''# Tree from the example: A (MAX) -> B, C (MIN) -> D, E, F, G (MAX) -> leaves
|
|
4
|
+
tree = {
|
|
5
|
+
'A': ['B', 'C'],
|
|
6
|
+
'B': ['D', 'E'],
|
|
7
|
+
'C': ['F', 'G'],
|
|
8
|
+
'D': [3, 5],
|
|
9
|
+
'E': [6, 9],
|
|
10
|
+
'F': [1, 2],
|
|
11
|
+
'G': [0, -1],
|
|
12
|
+
}
|
|
13
|
+
INF = float('inf')
|
|
14
|
+
|
|
15
|
+
def alphabeta(node, is_max, alpha, beta):
|
|
16
|
+
best = -INF if is_max else INF
|
|
17
|
+
for child in tree[node]:
|
|
18
|
+
# a child is either another node (string) or a leaf value (number)
|
|
19
|
+
value = alphabeta(child, not is_max, alpha, beta) if isinstance(child, str) else child
|
|
20
|
+
if is_max:
|
|
21
|
+
best = max(best, value)
|
|
22
|
+
alpha = max(alpha, best)
|
|
23
|
+
else:
|
|
24
|
+
best = min(best, value)
|
|
25
|
+
beta = min(beta, best)
|
|
26
|
+
if beta <= alpha: # pruning condition
|
|
27
|
+
print(f" Pruned remaining children of {node} (alpha={alpha}, beta={beta})")
|
|
28
|
+
break
|
|
29
|
+
print(f"Node {node} (\'MAX\' if is_max else \'MIN\') value = {best}")
|
|
30
|
+
return best
|
|
31
|
+
|
|
32
|
+
print("Alpha-Beta Pruning")
|
|
33
|
+
result = alphabeta('A', True, -INF, INF)
|
|
34
|
+
print("Value of root A =", result)
|
|
35
|
+
|
|
36
|
+
# Output
|
|
37
|
+
# Alpha-Beta Pruning
|
|
38
|
+
# Node D (MAX) value = 5
|
|
39
|
+
# Pruned remaining children of E (alpha=6, beta=5)
|
|
40
|
+
# Node E (MAX) value = 6
|
|
41
|
+
# Node B (MIN) value = 5
|
|
42
|
+
# Node F (MAX) value = 2
|
|
43
|
+
# Pruned remaining children of C (alpha=5, beta=2)
|
|
44
|
+
# Node C (MIN) value = 2
|
|
45
|
+
# Node A (MAX) value = 5
|
|
46
|
+
# Value of root A = 5
|
|
47
|
+
'''
|
|
48
|
+
|
|
49
|
+
def alphabeta():
|
|
50
|
+
"""
|
|
51
|
+
Assignment 6 - Alpha-Beta Pruning
|
|
52
|
+
|
|
53
|
+
Prints the Alpha-Beta Pruning algorithm code for minimax game trees.
|
|
54
|
+
Optimizes the minimax algorithm by pruning branches that cannot affect the result.
|
|
55
|
+
Usage: heapplot.alphabeta()
|
|
56
|
+
"""
|
|
57
|
+
print(CODE)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Assignment 2: A* Algorithm"""
|
|
2
|
+
|
|
3
|
+
CODE = '''import heapq
|
|
4
|
+
|
|
5
|
+
graph = {
|
|
6
|
+
'A': [('B', 1), ('C', 4)],
|
|
7
|
+
'B': [('D', 2), ('E', 5)],
|
|
8
|
+
'C': [('F', 1)],
|
|
9
|
+
'D': [], 'E': [], 'F': []
|
|
10
|
+
}
|
|
11
|
+
heuristic = {'A': 6, 'B': 4, 'C': 5, 'D': 2, 'E': 0, 'F': 3}
|
|
12
|
+
|
|
13
|
+
def a_star(start, goal):
|
|
14
|
+
pq = [(heuristic[start], 0, start)]
|
|
15
|
+
visited = set()
|
|
16
|
+
while pq:
|
|
17
|
+
f, g, node = heapq.heappop(pq)
|
|
18
|
+
if node in visited:
|
|
19
|
+
continue
|
|
20
|
+
print(node, "|| g =", g, "|| f =", f)
|
|
21
|
+
visited.add(node)
|
|
22
|
+
if node == goal:
|
|
23
|
+
print("Goal reached with total cost", g)
|
|
24
|
+
return
|
|
25
|
+
for neighbour, cost in graph[node]:
|
|
26
|
+
if neighbour not in visited:
|
|
27
|
+
new_g = g + cost
|
|
28
|
+
heapq.heappush(pq, (new_g + heuristic[neighbour], new_g, neighbour))
|
|
29
|
+
|
|
30
|
+
a_star('A', 'E')
|
|
31
|
+
|
|
32
|
+
# Output
|
|
33
|
+
# A || g = 0 || f = 6
|
|
34
|
+
# B || g = 1 || f = 5
|
|
35
|
+
# D || g = 3 || f = 5
|
|
36
|
+
# E || g = 6 || f = 6
|
|
37
|
+
# Goal reached with total cost 6
|
|
38
|
+
'''
|
|
39
|
+
|
|
40
|
+
def astar():
|
|
41
|
+
"""
|
|
42
|
+
Assignment 2 - A* Algorithm
|
|
43
|
+
|
|
44
|
+
Prints the A* search algorithm code that finds the optimal path using f = g + h.
|
|
45
|
+
Usage: heapplot.astar()
|
|
46
|
+
"""
|
|
47
|
+
print(CODE)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Assignment 10: Bayesian Network"""
|
|
2
|
+
|
|
3
|
+
CODE = '''# Practical 10: Bayesian Network - student exam performance
|
|
4
|
+
# Variables: e = exam level, i = IQ level, s = aptitude score, m = marks, a = admission
|
|
5
|
+
# Each value is 0 or 1. CPTs list [P(x=0), P(x=1)].
|
|
6
|
+
|
|
7
|
+
P_e = [0.7, 0.3]
|
|
8
|
+
P_i = [0.8, 0.2]
|
|
9
|
+
P_s_given_i = {0: [0.75, 0.25], 1: [0.4, 0.6]}
|
|
10
|
+
P_m_given_ie = {(0, 0): [0.6, 0.4], (0, 1): [0.9, 0.1],
|
|
11
|
+
(1, 0): [0.5, 0.5], (1, 1): [0.8, 0.2]}
|
|
12
|
+
P_a_given_m = {0: [0.6, 0.4], 1: [0.9, 0.1]}
|
|
13
|
+
|
|
14
|
+
def joint(a, m, i, e, s):
|
|
15
|
+
"""P(a,m,i,e,s) = P(a|m) * P(m|i,e) * P(i) * P(e) * P(s|i)"""
|
|
16
|
+
return (P_a_given_m[m][a] * P_m_given_ie[(i, e)][m] *
|
|
17
|
+
P_i[i] * P_e[e] * P_s_given_i[i][s])
|
|
18
|
+
|
|
19
|
+
print("Case 1: difficult exam, low IQ, low aptitude, passes and gets admission")
|
|
20
|
+
print("P(a=1, m=1, i=0, e=1, s=0) =", round(joint(1, 1, 0, 1, 0), 4))
|
|
21
|
+
print("\\nCase 2: easy exam, high IQ, high aptitude, fails and no admission")
|
|
22
|
+
print("P(a=0, m=0, i=1, e=0, s=1) =", round(joint(0, 0, 1, 0, 1), 4))
|
|
23
|
+
|
|
24
|
+
# Extra: add up the joint over all 32 combinations
|
|
25
|
+
combos = [(a, m, i, e, s) for a in (0, 1) for m in (0, 1)
|
|
26
|
+
for i in (0, 1) for e in (0, 1) for s in (0, 1)]
|
|
27
|
+
print("\\nSum of the joint over all 32 combinations =", round(sum(joint(*c) for c in combos), 4))
|
|
28
|
+
print("P(Admission = 1) =", round(sum(joint(*c) for c in combos if c[0] == 1), 4))
|
|
29
|
+
|
|
30
|
+
# Output
|
|
31
|
+
# Case 1: difficult exam, low IQ, low aptitude, passes and gets admission
|
|
32
|
+
# P(a=1, m=1, i=0, e=1, s=0) = 0.0018
|
|
33
|
+
#
|
|
34
|
+
# Case 2: easy exam, high IQ, high aptitude, fails and no admission
|
|
35
|
+
# P(a=0, m=0, i=1, e=0, s=1) = 0.0252
|
|
36
|
+
#
|
|
37
|
+
# Sum of the joint over all 32 combinations = 1.0
|
|
38
|
+
# P(Admission = 1) = 0.301
|
|
39
|
+
'''
|
|
40
|
+
|
|
41
|
+
def bayesian():
|
|
42
|
+
"""
|
|
43
|
+
Assignment 10 - Bayesian Network
|
|
44
|
+
|
|
45
|
+
Prints the Bayesian Network code modelling student exam performance
|
|
46
|
+
using Conditional Probability Tables (CPTs).
|
|
47
|
+
Usage: heapplot.bayesian()
|
|
48
|
+
"""
|
|
49
|
+
print(CODE)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Assignment 2: Best First Search"""
|
|
2
|
+
|
|
3
|
+
CODE = '''import heapq
|
|
4
|
+
|
|
5
|
+
graph = {
|
|
6
|
+
'A': [('B', 1), ('C', 1)],
|
|
7
|
+
'B': [('D', 1), ('E', 1)],
|
|
8
|
+
'C': [('F', 1)],
|
|
9
|
+
'D': [], 'E': [], 'F': []
|
|
10
|
+
}
|
|
11
|
+
heuristic = {'A': 6, 'B': 4, 'C': 5, 'D': 7, 'E': 3, 'F': 0}
|
|
12
|
+
|
|
13
|
+
def best_first_search(start, goal):
|
|
14
|
+
visited = set()
|
|
15
|
+
pq = [(heuristic[start], start)]
|
|
16
|
+
while pq:
|
|
17
|
+
h, node = heapq.heappop(pq)
|
|
18
|
+
if node in visited:
|
|
19
|
+
continue
|
|
20
|
+
print(node, end=" ")
|
|
21
|
+
visited.add(node)
|
|
22
|
+
if node == goal:
|
|
23
|
+
print("\\nGoal reached!")
|
|
24
|
+
return
|
|
25
|
+
for neighbour, cost in graph[node]:
|
|
26
|
+
if neighbour not in visited:
|
|
27
|
+
heapq.heappush(pq, (heuristic[neighbour], neighbour))
|
|
28
|
+
|
|
29
|
+
best_first_search('A', 'F')
|
|
30
|
+
|
|
31
|
+
# Output
|
|
32
|
+
# A B E C F
|
|
33
|
+
# Goal reached!
|
|
34
|
+
'''
|
|
35
|
+
|
|
36
|
+
def bestfirst():
|
|
37
|
+
"""
|
|
38
|
+
Assignment 2 - Best First Search
|
|
39
|
+
|
|
40
|
+
Prints the Best First Search algorithm code using a priority queue with heuristics.
|
|
41
|
+
Usage: heapplot.bestfirst()
|
|
42
|
+
"""
|
|
43
|
+
print(CODE)
|