Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions Algorithms/bfs.py

This file was deleted.

Empty file removed Sorts/__init__.py
Empty file.
36 changes: 5 additions & 31 deletions Visualiser.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
import pygame
import os
import sys

from Algorithms.nodes.nodes import *
from Algorithms.nodes.button import *
from Algorithms.prims import prims
from Algorithms.astar import astar
from Algorithms.dijkstra import dijkstra
from Algorithms.kruskal import kruskal
from Algorithms.sidewinder import sidewinder
from Algorithms.recursive_backtracking import backtrack
from Algorithms.ellers import ellers
from Algorithms.aldous_broder import aldous
from Algorithms.wilson import wilson
from Algorithms.hunt_and_kill import hunt
from Algorithms.growing_tree import tree
from Algorithms.binary_tree import binary
from Algorithms.recursive_division import division

FILEPATH = os.getcwd()

WIDTH = 1584
COLUMNS = 99

HEIGHT = 784
ROWS = 49

GREY = (128,128,128)
WHITE = (255,255,255)

from Visualiser import *

stage = 3
rainbow = [(255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 0, 255), (75, 0, 130), (150, 0, 255)]
Expand All @@ -38,7 +12,7 @@

WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Visualiser")
pygame.display.set_icon(pygame.image.load(os.path.join(FILEPATH, 'Fonts', 'icon.png')))
pygame.display.set_icon(pygame.image.load(ICON))

def make_grid():
grid = []
Expand Down Expand Up @@ -245,7 +219,7 @@ def helppage(k=False):
Quit = False
inv = False

background1 = pygame.image.load(os.path.join(FILEPATH, 'Fonts', 'Help1.png'))
background1 = pygame.image.load(HELP1)

nextpage = button((0, 0, 0), 1440, 350, 75, 100, FILEPATH, (0, 0, 0), text='>')
while not Quit:
Expand Down Expand Up @@ -281,7 +255,7 @@ def helppage2():
inv1 = False
page = 1

background2 = pygame.image.load(os.path.join(FILEPATH, 'Fonts', 'Help2.png'))
background2 = pygame.image.load(HELP2)

prevpage = button((0, 0, 0), 1440, 350, 75, 100, FILEPATH, (0, 0, 0), text='<')
while not Quit:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .aldous_broder import aldous
from .astar import astar
from .binary_tree import binary
from .dijkstra import dijkstra
from .ellers import ellers
from .growing_tree import tree
from .hunt_and_kill import hunt
from .kruskal import kruskal
from .prims import prims
from .kruskal import kruskal
from .sidewinder import sidewinder
from .recursive_backtracking import backtrack
from .nodes import *
from .ellers import ellers
from .aldous_broder import aldous
from .wilson import wilson
from .hunt_and_kill import hunt
from .growing_tree import tree
from .binary_tree import binary
from .recursive_division import division
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pygame

from random import randint, choice
from ...constants import MAZE_ABSOLUTE_ROWS, MAZE_ABSOLUTE_COLUMNS

extra_vis = False

row = 24
col = 49

clk = pygame.time.Clock()

def drawedge(draw, edge, grid, mode):
Expand Down Expand Up @@ -81,11 +79,11 @@ def getnextnode(node):
"""
x, y = node
neighbours = []
if x < row:
if x < MAZE_ABSOLUTE_ROWS:
neighbours.append((x+1, y))
if x > 0:
neighbours.append((x-1, y))
if y < col:
if y < MAZE_ABSOLUTE_COLUMNS:
neighbours.append((x, y+1))
if y > 0:
neighbours.append((x, y-1))
Expand All @@ -107,13 +105,13 @@ def getrandom(node, visited):
except:
return []
neighbours = []
if x < row:
if x < MAZE_ABSOLUTE_ROWS:
if (x+1, y) not in visited:
neighbours.append((x+1, y))
if x > 0:
if (x-1, y) not in visited:
neighbours.append((x-1, y))
if y < col:
if y < MAZE_ABSOLUTE_COLUMNS:
if (x, y+1) not in visited:
neighbours.append((x, y+1))
if y > 0:
Expand Down Expand Up @@ -144,8 +142,8 @@ def aldous(draw, grid, mode):
c = len(grid[0])
run = True
global extra_vis
for row in grid:
for node in row:
for rows in grid:
for node in rows:
node.reset()
node.invert()

Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions Visualiser/Algorithms/Maze/bfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# import pygame
# from queue import PriorityQueue

# def reconstruct(came, end, draw):
# while end in came:
# end = came[end]
# end.make_path()
# draw()


# def astar(draw, grid, start, end, mode):
# pygame.init()
# run = True

# while run:
# for event in pygame.event.get():
# if event.type == pygame.QUIT:
# return False
# if event.type == pygame.KEYDOWN:
# if event.key == pygame.K_BACKSPACE:
# if mode == 0:
# mode = 1
# else:
# mode = 0

# return True
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pygame
from random import randint

# clk = pygame.time.Clock()
row = 24
col = 49
from random import randint
from ...constants import MAZE_ABSOLUTE_ROWS, MAZE_ABSOLUTE_COLUMNS

def rand():
return randint(0,1)
Expand All @@ -24,7 +22,7 @@ def binary(draw, grid, mode):
draw()

i = 1
while run and i != row + 1:
while run and i != MAZE_ABSOLUTE_ROWS + 1:
# clk.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
Expand All @@ -37,7 +35,7 @@ def binary(draw, grid, mode):
mode = 1
else:
mode = 0
for j in range(col+ 1):
for j in range(MAZE_ABSOLUTE_COLUMNS+ 1):

current = (i, j)
if rand() == 1:
Expand All @@ -56,16 +54,16 @@ def binary(draw, grid, mode):

def movewest(node):
x, y = node
if y < col:
if y < MAZE_ABSOLUTE_COLUMNS:
return True
return False

def drawedge(draw, grid, current, mode, direc):
def drawedge(draw, grid, current, mode, direction):
x, y = current
grid[x*2][y*2].remove_barrier()
if direc == 'north':
if direction == 'north':
grid[x*2-1][y*2].remove_barrier()
elif direc == 'west':
elif direction == 'west':
grid[x*2][y*2+1].remove_barrier()
if mode == 0:
draw()
11 changes: 5 additions & 6 deletions Algorithms/ellers.py → Visualiser/Algorithms/Maze/ellers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pygame

from random import randint, choice
from ...constants import MAZE_ABSOLUTE_ROWS, MAZE_ABSOLUTE_COLUMNS

clk = pygame.time.Clock()
row = 24
col = 49


def getboolean():
if randint(0, 1) == 0:
Expand Down Expand Up @@ -111,15 +110,15 @@ def ellers(draw, grid, mode):

s = 1
celllist = []
for b in range(row+1):
for b in range(MAZE_ABSOLUTE_ROWS+1):
celllist.append([])
for j in range(col+1):
for j in range(MAZE_ABSOLUTE_COLUMNS+1):
celllist[b].append(Cell(b, j, s))
s += 1

i = 0
currrow = celllist[i]
while i < row:
while i < MAZE_ABSOLUTE_ROWS:
clk.tick(30)
# i += 1
for event in pygame.event.get():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import pygame

from random import randint, choice
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col

# clk = pygame.time.Clock()
row = 24
col = 49

def noneb(stack, visited):
# x, y = node
neighbours = []
for node in stack:
count = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pygame

from random import randint, choice, shuffle
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col

row = 24
col = 49
clk = pygame.time.Clock()

def update(node, visited):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pygame
from random import randint, choice, shuffle
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col

row = 24
col = 49
GREEN = (0,255,0)
# clk = pygame.time.Clock()

def findparent(v, parent):
Expand Down
5 changes: 2 additions & 3 deletions Algorithms/prims.py → Visualiser/Algorithms/Maze/prims.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pygame
from random import choice, shuffle, randint

row = 24
col = 49
from random import choice, shuffle, randint
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col

def getneighbour(node, visited):
x, y = node
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pygame

from random import randint, choice

row = 24
col = 49
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col

clk = pygame.time.Clock()

def update(node, visited):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pygame

from random import shuffle, randint, choice
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col

row = 24
col = 49

def rand():
return randint(0,1)
Expand Down
6 changes: 2 additions & 4 deletions Algorithms/wilson.py → Visualiser/Algorithms/Maze/wilson.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pygame

from random import randint, shuffle, choice

row = 24
col = 49
LIGHTGREEN = (55,205,55)
LIGHTRED = (255, 130, 130)
from ...constants import MAZE_ABSOLUTE_ROWS as row, MAZE_ABSOLUTE_COLUMNS as col, LIGHTGREEN, LIGHTRED

d = ['n', 's', 'e', 'w']
clk = pygame.time.Clock()
Expand Down
2 changes: 2 additions & 0 deletions Visualiser/Algorithms/Path/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .astar import astar
from .dijkstra import dijkstra
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions Visualiser/Algorithms/Sort/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from .bead import bead
from .bitonic import bitonic
from .bogo import bogo
from .bubble import bubble
from .bucket import bucket
from .cocktail import cocktail
from .comb import comb
from .counting import counting
from .cycle import cycle
from .double import double
from .gnome import gnome
from .heap import heap
from .insertion import insertion
from .merge import iterativemerge
from .oddeven import oddeven
from .pancake import pancake
from .pigeon import pigeon
from .quick import quick
from .radix import radix
from .shell import shell
from .selection import selection
from .sleep import sleepsort
from .stooge import stooge
from .wiggle import wiggle
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Visualiser/Algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .Maze import *
from .Sort import *
from .Path import *
File renamed without changes.
File renamed without changes.
Loading