-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (53 loc) · 1.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pygame
import colors
from params import *
from Environment import Board
from Agent import Agent
import numpy as np
# initialize:
FPS = 60
pygame.init()
WIN = pygame.display.set_mode((width, height))
pygame.display.set_caption("Search Game")
# setting start and end point :
start = {'x': 6, 'y': 0}
end = {'x': 12, 'y': 0}
gameBoard = Board(start, end)
agent = Agent(gameBoard)
def saveNewBoard(name):
array = []
for i in range(rows):
array.append([])
for j in range(cols):
if gameBoard.boardArray[j][i].isBlocked:
array[i].append(0)
else:
array[i].append(1)
array = np.array(array)
np.save('Mazes/' + name + '.npy', array)
def main():
run = True
clock = pygame.time.Clock()
WIN.fill(colors.black)
# agent.dfs(gameBoard) # dfs
# agent.bfs(gameBoard) # bfs
agent.a_star(gameBoard, end) # a star
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
gameBoard.draw_world(WIN)
# pos = pygame.mouse.get_pos() # gets the current mouse coords
# if event.type == pygame.MOUSEBUTTONDOWN:
# for i in range(rows):
# for j in range(cols):
# rect = gameBoard.boardArray[i][j]
# if rect.is_inside_me(pos):
# if event.button == 1:
# gameBoard.boardArray[i][j].block()
# if event.button == 3:
# gameBoard.boardArray[i][j].unblock()
# saveNewBoard('New 2')
pygame.quit()
main()