Update 'board'

dodanie funkcji z kosztem wejścia na pola
This commit is contained in:
Gabriela Piekarska 2022-04-29 00:38:42 +02:00
parent 1de4b34d8e
commit 302001e531

25
board
View File

@ -1,5 +1,6 @@
import sys
from queue import PriorityQueue
import numpy as np
import pygame
@ -165,6 +166,30 @@ def manhattan(node1, node2):
return distance
def f(state):#tablica z losowymi wagami(kosztami) pól, w astar trzeba zsumować wagę pola z heurystyką - f + manhattan
weights = np.array([
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 8],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 1],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 3],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 4],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 2],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 6],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 7],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 1],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 3],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 2],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 6],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 7],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 1],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 2],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 2]
])
pos_x = state[0]
pos_y = state[1]
#print(weights[pos_x][pos_y])
return weights[pos_x][pos_y]
class Node: #prawie jak Field w bfs
def __init__(self, state, parent, action):
self.state = state #position - (x, y, direction)