changed bfs to start at top neighbour and proceed against the clock
This commit is contained in:
parent
5ac5fd9aea
commit
995dd6860e
30
src/BFS.py
30
src/BFS.py
@ -1,6 +1,5 @@
|
||||
import queue
|
||||
from typing import List
|
||||
import pygame as pg
|
||||
|
||||
from node import Node
|
||||
from tile import Tile
|
||||
@ -8,36 +7,31 @@ from const import DIRECTIONS_X, DIRECTIONS_Y, DIRECTIONS_SIDE, ACTIONS
|
||||
|
||||
|
||||
def successor(x: int, y: int, direction: int):
|
||||
"""
|
||||
kody klawiszy:
|
||||
:a -> 97
|
||||
:d -> 100
|
||||
:w -> 119
|
||||
1 direction -> prawo
|
||||
neighbour side 1 -> po prawej 1-1 = 0 -> W
|
||||
neighbour side 2 -> na gorze 2-1 = 1 -> D + W
|
||||
neighbour side 3 -> po lewej 3-1 = 2 -> D + D + W
|
||||
neighbour side 0 -> na dole 0-1 = -1 -> A + W
|
||||
zwraca listę krotek, które zawierają x, y, kierunek i akcje dla sąsiada
|
||||
"""
|
||||
neighbours = []
|
||||
for i in range(4):
|
||||
# TODO
|
||||
# naprawić by zaczął od prawej i szedł zgodnie z zegarem
|
||||
# prawo -> góra -> lewo -> dół
|
||||
# chcemy: prawo -> dół -> lewo -> góra
|
||||
neighbour_x = x + DIRECTIONS_X[i]
|
||||
neighbour_y = y + DIRECTIONS_Y[i]
|
||||
neighbour_side = DIRECTIONS_SIDE[i]
|
||||
# print(neighbour_x, neighbour_y, neighbour_side)
|
||||
|
||||
if 0 <= neighbour_x <= 9 and 0 <= neighbour_y <= 9:
|
||||
# TODO
|
||||
# wymyśleć sposób by dla każdej strony odnaleźć akcje w ACTIONS
|
||||
neighbours.append((neighbour_x, neighbour_y, neighbour_side, ACTIONS[neighbour_side-direction]))
|
||||
|
||||
return neighbours
|
||||
# kody klawiszy
|
||||
# a 97
|
||||
# d 100
|
||||
# w 119
|
||||
# 1 direction -> prawo
|
||||
# neighbour side 1 -> po prawej 1-1 = 0 -> W
|
||||
# neighbour side 2 -> na gorze 2-1 = 1 -> D + W
|
||||
# neighbour side 3 -> po lewej 3-1 = 2 -> D + D + W
|
||||
# neighbour side 0 -> na dole 0-1 = -1 -> A + W
|
||||
|
||||
|
||||
def breadth_first_search(field: List[List[Tile]], start_x: int, start_y: int, start_direction: int):
|
||||
pg.time.delay(50)
|
||||
explored = [(start_x, start_y)]
|
||||
node_queue = queue.SimpleQueue()
|
||||
node_queue.put(Node(start_x, start_y, start_direction))
|
||||
|
18
src/const.py
18
src/const.py
@ -61,8 +61,6 @@ DEFAULT_FIELD = [
|
||||
[5, 2, 0, 1, 3, 1, 2, 1, 0, 0],
|
||||
[2, 5, 1, 4, 5, 1, 0, 5, 4, 0],
|
||||
]
|
||||
# TODO
|
||||
# to poprawić
|
||||
|
||||
# -1 -> prawo, ruch
|
||||
# 0 -> ruch
|
||||
@ -72,15 +70,15 @@ DEFAULT_FIELD = [
|
||||
# -3 -> lewo, ruch
|
||||
# 3 -> prawo, ruch
|
||||
ACTIONS = {
|
||||
-1: [pg.K_d, pg.K_w],
|
||||
-1: [pg.K_a, pg.K_w],
|
||||
0: [pg.K_w],
|
||||
1: [pg.K_a, pg.K_w],
|
||||
1: [pg.K_d, pg.K_w],
|
||||
2: [pg.K_d, pg.K_d, pg.K_w],
|
||||
-2: [pg.K_d, pg.K_d, pg.K_w],
|
||||
-3: [pg.K_a, pg.K_w],
|
||||
3: [pg.K_d, pg.K_w]
|
||||
-3: [pg.K_d, pg.K_w],
|
||||
3: [pg.K_a, pg.K_w]
|
||||
}
|
||||
# TODO
|
||||
DIRECTIONS_X = (1, 0, -1, 0)
|
||||
DIRECTIONS_Y = (0, 1, 0, -1)
|
||||
DIRECTIONS_SIDE = (1, 2, 3, 0)
|
||||
|
||||
DIRECTIONS_X = (-1, 0, 1, 0)
|
||||
DIRECTIONS_Y = (0, -1, 0, 1)
|
||||
DIRECTIONS_SIDE = (3, 0, 1, 2)
|
||||
|
Loading…
Reference in New Issue
Block a user