agwintertools 0.1.0__py3-none-any.whl
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.
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
ai/main.py,sha256=o_IIqYv3lmgPG0cPrdCXNHGDnhCvnxymd8ctc76VI3Y,10218
|
|
3
|
+
agwintertools-0.1.0.dist-info/METADATA,sha256=7iphpvsZGbC3y7vUk4D7c1KYR9qWBVqAkkJPKroP-uU,159
|
|
4
|
+
agwintertools-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
agwintertools-0.1.0.dist-info/top_level.txt,sha256=TJAp5TUfTUztZSUatbygths7CWRrFfnOMCtZ-DIcw6c,3
|
|
6
|
+
agwintertools-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ai
|
ai/__init__.py
ADDED
|
File without changes
|
ai/main.py
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
###############
|
|
2
|
+
#Program 1-BFS
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
from collections import deque
|
|
6
|
+
|
|
7
|
+
graph = {
|
|
8
|
+
'A': ['B', 'C'],
|
|
9
|
+
'B': ['D', 'E'],
|
|
10
|
+
'C': ['F'],
|
|
11
|
+
'D': [],
|
|
12
|
+
'E': ['F'],
|
|
13
|
+
'F': []
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def bfs(graph, start):
|
|
18
|
+
visited = set()
|
|
19
|
+
queue = deque([start])
|
|
20
|
+
visited.add(start)
|
|
21
|
+
|
|
22
|
+
while queue:
|
|
23
|
+
node = queue.popleft()
|
|
24
|
+
print(node, end=" ")
|
|
25
|
+
|
|
26
|
+
for neighbor in graph[node]:
|
|
27
|
+
if neighbor not in visited:
|
|
28
|
+
visited.add(neighbor)
|
|
29
|
+
queue.append(neighbor)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
bfs(graph, 'A')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
###############
|
|
36
|
+
#Program 2-DFS
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
graph = {
|
|
40
|
+
'A': ['B', 'C'],
|
|
41
|
+
'B': ['D', 'E'],
|
|
42
|
+
'C': ['F'],
|
|
43
|
+
'D': [],
|
|
44
|
+
'E': [],
|
|
45
|
+
'F': []
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
visited = set()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def dfs(node):
|
|
52
|
+
if node not in visited:
|
|
53
|
+
print(node, end=" ")
|
|
54
|
+
visited.add(node)
|
|
55
|
+
|
|
56
|
+
for neighbor in graph[node]:
|
|
57
|
+
dfs(neighbor)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
dfs('A')
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
###########
|
|
64
|
+
#Program 3- tic tac toe
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
board = [' ' for x in range(9)]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def display():
|
|
72
|
+
print(board[0], "|", board[1], "|", board[2])
|
|
73
|
+
print("--|---|--")
|
|
74
|
+
print(board[3], "|", board[4], "|", board[5])
|
|
75
|
+
print("--|---|--")
|
|
76
|
+
print(board[6], "|", board[7], "|", board[8])
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def check_winner(player):
|
|
80
|
+
win_positions = [
|
|
81
|
+
[0, 1, 2], [3, 4, 5], [6, 7, 8],
|
|
82
|
+
[0, 3, 6], [1, 4, 7], [2, 5, 8],
|
|
83
|
+
[0, 4, 8], [2, 4, 6]
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
for pos in win_positions:
|
|
87
|
+
if board[pos[0]] == board[pos[1]] == board[pos[2]] == player:
|
|
88
|
+
return True
|
|
89
|
+
|
|
90
|
+
return False
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
player = 'X'
|
|
94
|
+
|
|
95
|
+
for turn in range(9):
|
|
96
|
+
display()
|
|
97
|
+
move = int(input(f"Player {player}, enter position (0-8): "))
|
|
98
|
+
|
|
99
|
+
if board[move] == ' ':
|
|
100
|
+
board[move] = player
|
|
101
|
+
|
|
102
|
+
if check_winner(player):
|
|
103
|
+
display()
|
|
104
|
+
print(f"Player {player} wins!")
|
|
105
|
+
break
|
|
106
|
+
|
|
107
|
+
player = 'O' if player == 'X' else 'X'
|
|
108
|
+
|
|
109
|
+
else:
|
|
110
|
+
print("Position already filled")
|
|
111
|
+
|
|
112
|
+
else:
|
|
113
|
+
print("Game Draw")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
###########
|
|
119
|
+
#Program 4-8 puzzle game
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
from collections import deque
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def solve(b):
|
|
127
|
+
s = sum(b, [])
|
|
128
|
+
goal = list(range(9))
|
|
129
|
+
|
|
130
|
+
if s == goal:
|
|
131
|
+
print("Final Matrix:")
|
|
132
|
+
for i in range(0, 9, 3):
|
|
133
|
+
print(goal[i:i + 3])
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
m = [
|
|
137
|
+
[1, 3],
|
|
138
|
+
[0, 2, 4],
|
|
139
|
+
[1, 5],
|
|
140
|
+
[0, 4, 6],
|
|
141
|
+
[1, 3, 5, 7],
|
|
142
|
+
[2, 4, 8],
|
|
143
|
+
[3, 7],
|
|
144
|
+
[4, 6, 8],
|
|
145
|
+
[5, 7]
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
q = deque([(s, 0)])
|
|
149
|
+
v = set()
|
|
150
|
+
|
|
151
|
+
while q:
|
|
152
|
+
t, c = q.popleft()
|
|
153
|
+
|
|
154
|
+
if tuple(t) in v:
|
|
155
|
+
continue
|
|
156
|
+
|
|
157
|
+
v.add(tuple(t))
|
|
158
|
+
z = t.index(0)
|
|
159
|
+
|
|
160
|
+
for i in m[z]:
|
|
161
|
+
n = t[:]
|
|
162
|
+
n[z], n[i] = n[i], n[z]
|
|
163
|
+
|
|
164
|
+
if n == goal:
|
|
165
|
+
print("Final Matrix:")
|
|
166
|
+
for j in range(0, 9, 3):
|
|
167
|
+
print(n[j:j + 3])
|
|
168
|
+
return c + 1
|
|
169
|
+
|
|
170
|
+
q.append((n, c + 1))
|
|
171
|
+
|
|
172
|
+
return -1
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
moves = solve([[3, 1, 2], [4, 7, 5], [6, 8, 0]])
|
|
176
|
+
|
|
177
|
+
print("Minimum moves:", moves)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
###########
|
|
182
|
+
# Program 5 – Water Jug Problem
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
jug1 = 4
|
|
187
|
+
jug2 = 3
|
|
188
|
+
x = 0
|
|
189
|
+
y = 0
|
|
190
|
+
|
|
191
|
+
print("Initial State:", x, y)
|
|
192
|
+
|
|
193
|
+
y = jug2
|
|
194
|
+
print("Fill Jug2:", x, y)
|
|
195
|
+
|
|
196
|
+
x = y
|
|
197
|
+
y = 0
|
|
198
|
+
print("Pour Jug2 into Jug1:", x, y)
|
|
199
|
+
|
|
200
|
+
y = jug2
|
|
201
|
+
print("Fill Jug2 again:", x, y)
|
|
202
|
+
|
|
203
|
+
y = y - (jug1 - x)
|
|
204
|
+
x = jug1
|
|
205
|
+
|
|
206
|
+
print("Final State:", x, y)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
############
|
|
212
|
+
##Program 6 - Travelling Salesman Problem (TSP)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
from itertools import permutations
|
|
216
|
+
|
|
217
|
+
graph = {
|
|
218
|
+
'A': {'B': 10, 'C': 15, 'D': 20},
|
|
219
|
+
'B': {'A': 10, 'C': 35, 'D': 25},
|
|
220
|
+
'C': {'A': 15, 'B': 35, 'D': 30},
|
|
221
|
+
'D': {'A': 20, 'B': 25, 'C': 30}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
cities = list(graph.keys())
|
|
225
|
+
|
|
226
|
+
min_path = None
|
|
227
|
+
min_cost = float('inf')
|
|
228
|
+
|
|
229
|
+
for path in permutations(cities):
|
|
230
|
+
cost = 0
|
|
231
|
+
|
|
232
|
+
for i in range(len(path) - 1):
|
|
233
|
+
cost += graph[path[i]][path[i + 1]]
|
|
234
|
+
|
|
235
|
+
cost += graph[path[-1]][path[0]]
|
|
236
|
+
|
|
237
|
+
if cost < min_cost:
|
|
238
|
+
min_cost = cost
|
|
239
|
+
min_path = path
|
|
240
|
+
|
|
241
|
+
print("Minimum Path:", min_path)
|
|
242
|
+
print("Minimum Cost:", min_cost)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
#############
|
|
247
|
+
#
|
|
248
|
+
# Program 7 – Tower of Hanoi
|
|
249
|
+
|
|
250
|
+
def tower(n, source, auxiliary, destination):
|
|
251
|
+
if n == 1:
|
|
252
|
+
print("Move disk 1 from", source, "to", destination)
|
|
253
|
+
return
|
|
254
|
+
|
|
255
|
+
tower(n - 1, source, destination, auxiliary)
|
|
256
|
+
print("Move disk", n, "from", source, "to", destination)
|
|
257
|
+
tower(n - 1, auxiliary, source, destination)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
tower(3, 'A', 'B', 'C')
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
# Program 8 - MONKEY BANANA PROBLEM
|
|
266
|
+
|
|
267
|
+
def monkey_banana_problem(n):
|
|
268
|
+
climb = 0
|
|
269
|
+
bananas = 0
|
|
270
|
+
hungry = True
|
|
271
|
+
|
|
272
|
+
for i in range(n):
|
|
273
|
+
if hungry:
|
|
274
|
+
climb += 1
|
|
275
|
+
bananas += 1
|
|
276
|
+
hungry = False
|
|
277
|
+
else:
|
|
278
|
+
climb += 1
|
|
279
|
+
|
|
280
|
+
return climb, bananas
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
n = 10
|
|
284
|
+
climb, bananas = monkey_banana_problem(n)
|
|
285
|
+
|
|
286
|
+
print(f"The monkey made {climb} climbs and get {bananas} bananas.")
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# Program 9 – ALPHA-BETA PRUNING
|
|
291
|
+
|
|
292
|
+
MAX, MIN = 1000, -1000
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def alphabeta(depth, nodeIndex, maximizingPlayer, values, alpha, beta):
|
|
296
|
+
if depth == 3:
|
|
297
|
+
return values[nodeIndex]
|
|
298
|
+
|
|
299
|
+
if maximizingPlayer:
|
|
300
|
+
best = MIN
|
|
301
|
+
|
|
302
|
+
for i in range(2):
|
|
303
|
+
val = alphabeta(
|
|
304
|
+
depth + 1,
|
|
305
|
+
nodeIndex * 2 + i,
|
|
306
|
+
False,
|
|
307
|
+
values,
|
|
308
|
+
alpha,
|
|
309
|
+
beta
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
best = max(best, val)
|
|
313
|
+
alpha = max(alpha, best)
|
|
314
|
+
|
|
315
|
+
if beta <= alpha:
|
|
316
|
+
break
|
|
317
|
+
|
|
318
|
+
return best
|
|
319
|
+
|
|
320
|
+
else:
|
|
321
|
+
best = MAX
|
|
322
|
+
|
|
323
|
+
for i in range(2):
|
|
324
|
+
val = alphabeta(
|
|
325
|
+
depth + 1,
|
|
326
|
+
nodeIndex * 2 + i,
|
|
327
|
+
True,
|
|
328
|
+
values,
|
|
329
|
+
alpha,
|
|
330
|
+
beta
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
best = min(best, val)
|
|
334
|
+
beta = min(beta, best)
|
|
335
|
+
|
|
336
|
+
if beta <= alpha:
|
|
337
|
+
break
|
|
338
|
+
|
|
339
|
+
return best
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
values = [3, 5, 6, 9, 1, 2, 0, -1]
|
|
343
|
+
|
|
344
|
+
print(
|
|
345
|
+
"Optimal Value:",
|
|
346
|
+
alphabeta(0, 0, True, values, MIN, MAX)
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
# Program 10 – 8 Queen's Problem
|
|
353
|
+
|
|
354
|
+
N = 8
|
|
355
|
+
board = [[0] * N for _ in range(N)]
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def is_safe(board, row, col):
|
|
359
|
+
for i in range(col):
|
|
360
|
+
if board[row][i] == 1:
|
|
361
|
+
return False
|
|
362
|
+
|
|
363
|
+
i, j = row, col
|
|
364
|
+
while i >= 0 and j >= 0:
|
|
365
|
+
if board[i][j] == 1:
|
|
366
|
+
return False
|
|
367
|
+
i -= 1
|
|
368
|
+
j -= 1
|
|
369
|
+
|
|
370
|
+
i, j = row, col
|
|
371
|
+
while j >= 0 and i < N:
|
|
372
|
+
if board[i][j] == 1:
|
|
373
|
+
return False
|
|
374
|
+
i += 1
|
|
375
|
+
j -= 1
|
|
376
|
+
|
|
377
|
+
return True
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def solve(board, col):
|
|
381
|
+
if col >= N:
|
|
382
|
+
return True
|
|
383
|
+
|
|
384
|
+
for i in range(N):
|
|
385
|
+
if is_safe(board, i, col):
|
|
386
|
+
board[i][col] = 1
|
|
387
|
+
|
|
388
|
+
if solve(board, col + 1):
|
|
389
|
+
return True
|
|
390
|
+
|
|
391
|
+
board[i][col] = 0
|
|
392
|
+
|
|
393
|
+
return False
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
solve(board, 0)
|
|
397
|
+
|
|
398
|
+
for row in board:
|
|
399
|
+
print(row)
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
# Program 11 - SIMPLE CHATBOT
|
|
405
|
+
|
|
406
|
+
import random
|
|
407
|
+
|
|
408
|
+
responses = [
|
|
409
|
+
"Hello,how can I help you?",
|
|
410
|
+
"What do you want to talk about?",
|
|
411
|
+
"I'm not sure what you mean.",
|
|
412
|
+
"Can you repeat that?",
|
|
413
|
+
"I'm sorry,I don't understand.",
|
|
414
|
+
"Goodbye!"
|
|
415
|
+
]
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def get_response():
|
|
419
|
+
return random.choice(responses)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def start_chatbot():
|
|
423
|
+
print("Hello,I'm a chatbot.What do you want to talk about?")
|
|
424
|
+
|
|
425
|
+
while True:
|
|
426
|
+
user_input = input()
|
|
427
|
+
response = get_response()
|
|
428
|
+
print(response)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
start_chatbot()
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
# Program 12 – HANGMAN GAME
|
|
436
|
+
|
|
437
|
+
import random
|
|
438
|
+
import string
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def choose_word():
|
|
442
|
+
words = [
|
|
443
|
+
"python",
|
|
444
|
+
"hangman",
|
|
445
|
+
"programming",
|
|
446
|
+
"developer",
|
|
447
|
+
"artificial",
|
|
448
|
+
"intelligence"
|
|
449
|
+
]
|
|
450
|
+
|
|
451
|
+
return random.choice(words)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def get_available_letters(letters_guessed):
|
|
455
|
+
return ''.join([
|
|
456
|
+
ch for ch in string.ascii_lowercase
|
|
457
|
+
if ch not in letters_guessed
|
|
458
|
+
])
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def get_guessed_word(secret_word, letters_guessed):
|
|
462
|
+
return ''.join([
|
|
463
|
+
ch if ch in letters_guessed else '_'
|
|
464
|
+
for ch in secret_word
|
|
465
|
+
])
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def is_word_guessed(secret_word, letters_guessed):
|
|
469
|
+
return all(ch in letters_guessed for ch in secret_word)
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def hangman(secret_word):
|
|
473
|
+
guesses_left = 8
|
|
474
|
+
letters_guessed = []
|
|
475
|
+
|
|
476
|
+
print("Welcome to the game Hangman!")
|
|
477
|
+
print(f"I am thinking of a word that is {len(secret_word)} letters long.")
|
|
478
|
+
print("-------------")
|
|
479
|
+
|
|
480
|
+
while guesses_left > 0:
|
|
481
|
+
print(f"You have {guesses_left} guesses left.")
|
|
482
|
+
print(
|
|
483
|
+
"Available letters:",
|
|
484
|
+
get_available_letters(letters_guessed)
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
guess = input("Please guess a letter: ").lower()
|
|
488
|
+
|
|
489
|
+
if guess in letters_guessed:
|
|
490
|
+
print(
|
|
491
|
+
"Oops! You've already guessed that letter:",
|
|
492
|
+
get_guessed_word(secret_word, letters_guessed)
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
elif guess in secret_word:
|
|
496
|
+
letters_guessed.append(guess)
|
|
497
|
+
print(
|
|
498
|
+
"Good guess:",
|
|
499
|
+
get_guessed_word(secret_word, letters_guessed)
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
else:
|
|
503
|
+
letters_guessed.append(guess)
|
|
504
|
+
guesses_left -= 1
|
|
505
|
+
print(
|
|
506
|
+
"Oops! That letter is not in my word:",
|
|
507
|
+
get_guessed_word(secret_word, letters_guessed)
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
print("-------------")
|
|
511
|
+
|
|
512
|
+
if is_word_guessed(secret_word, letters_guessed):
|
|
513
|
+
print("Congratulations, you won!")
|
|
514
|
+
break
|
|
515
|
+
|
|
516
|
+
else:
|
|
517
|
+
print(
|
|
518
|
+
f"Sorry, you ran out of guesses. "
|
|
519
|
+
f"The word was '{secret_word}'."
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
word = choose_word()
|
|
524
|
+
hangman(word)
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
# Program 13 – REMOVE STOP WORDS USING NLTK
|
|
532
|
+
|
|
533
|
+
import nltk
|
|
534
|
+
from nltk.corpus import stopwords
|
|
535
|
+
from nltk.tokenize import word_tokenize
|
|
536
|
+
|
|
537
|
+
nltk.download('punkt')
|
|
538
|
+
nltk.download('stopwords')
|
|
539
|
+
|
|
540
|
+
file = open("sample.txt", "r")
|
|
541
|
+
|
|
542
|
+
text = file.read()
|
|
543
|
+
|
|
544
|
+
words = word_tokenize(text)
|
|
545
|
+
|
|
546
|
+
stop_words = set(stopwords.words('english'))
|
|
547
|
+
|
|
548
|
+
filtered_words = []
|
|
549
|
+
|
|
550
|
+
for word in words:
|
|
551
|
+
if word.lower() not in stop_words:
|
|
552
|
+
filtered_words.append(word)
|
|
553
|
+
|
|
554
|
+
print("Filtered Words:")
|
|
555
|
+
print(filtered_words)
|