From 302001e53115a25854704361e96410ebf6ce474e Mon Sep 17 00:00:00 2001 From: Gabriela Piekarska Date: Fri, 29 Apr 2022 00:38:42 +0200 Subject: [PATCH] Update 'board' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dodanie funkcji z kosztem wejścia na pola --- board | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/board b/board index f5d2a20..70951f9 100644 --- a/board +++ b/board @@ -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)