Function successor(only east direction), start-end position

This commit is contained in:
Art-cyber520 2021-04-24 23:44:00 +02:00
parent d733270048
commit e767fb5e3f
3 changed files with 74 additions and 27 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>

View File

@ -1,3 +1,6 @@
#from bin.Main.main import player
class Node:
def __init__(self):
self.state = State()
@ -9,3 +12,45 @@ class State:
def __init__(self):
self.coord = []
self.direction = ""
def successor(state):
if state.direction == "east":
node_state_left = Node()
node_state_right = Node()
node_state_forward = Node()
#state_left = state.coord
node_state_left.state = State()
node_state_left.state.coord = state.coord
node_state_left.state.direction = "north"
node_state_left.parent = state
node_state_left.action = "Left"
#state_right = state.coord
node_state_right.state = State()
node_state_right.state.coord = state.coord
node_state_right.state.direction = "south"
node_state_right.parent = state
node_state_right.action = "Right"
#state_forward = state.coord
#state_forward[0] = 53
node_state_forward.state = State()
node_state_forward.state.coord = [state.coord[0] + 53, state.coord[1]]
node_state_forward.state.direction = state.direction
node_state_forward.parent = state
node_state_forward.action = "Up"
return [node_state_left, node_state_right, node_state_forward]
#elif state.direction == "west":
#elif state.direction == "north":
#elif state.direction == "south":
def hello():
print("Hello Node!")

View File

@ -2,10 +2,10 @@ import os
import random
from tkinter import *
from bin.classess.Field import Field
from bin.classess.Mine import Mine
from bin.classess.Player import Player
from bin.classess.Node import Node
from bin.Classess.Field import Field
from bin.Classess.Mine import Mine
from bin.Classess.Player import Player
import bin.Classess.Node as nd
WINDOW_X = 533 + 1200
WINDOW_Y = 950
@ -56,22 +56,6 @@ def DrawingLargeImage():
field.PuttingLargeImage(large_img_name)
# Drawing rectangle
# def Rectangle(bool, direction):
# if bool:
# field.rectangle = field.small_field_canvas.create_rectangle(player.current_x, player.current_y, player.current_x + player.step - 2,
# player.current_y + player.step - 2, width=3, outline='blue2')
# else:
# if direction == "East" and field.small_field_canvas.coords(field.rectangle)[0] + player.step < FRAME_WIDTH:
# field.small_field_canvas.move(field.rectangle, player.step, 0)
# elif direction == "West" and field.small_field_canvas.coords(field.rectangle)[0] > player.x_start:
# field.small_field_canvas.move(field.rectangle, -player.step, 0)
# elif direction == "North" and field.small_field_canvas.coords(field.rectangle)[1] > player.y_start:
# field.small_field_canvas.move(field.rectangle, 0, -player.step)
# elif direction == "South" and field.small_field_canvas.coords(field.rectangle)[1] + player.step < FRAME_HEIGHT:
# field.small_field_canvas.move(field.rectangle, 0, player.step)
def Next_direction(side):
# Define next direction
current_direction = player.direction
@ -181,15 +165,33 @@ def MouseClickEvent(event):
for i in range(0, len(field.canvas_small_images)):
print(field.small_field_canvas.coords(field.canvas_small_images[i]))
print("Lewy przycisk myszy zostal nacisniety!")
node = Node()
node = nd.Node()
print(node.state.coord, node.state.direction, node.action, node.parent)
node.state.coord = field.small_field_canvas.coords(field.canvas_small_images[5])
node.state.direction = "N"
node.action = "l"
node.parent = 1
print(node.state.coord, node.state.direction, node.parent, node.action)
node.state = nd.State()
node.state.coord = field.small_field_canvas.coords(player.image_canvas_id)
node.state.direction = "east"
#node.state.coord = field.small_field_canvas.coords(field.canvas_small_images[5])
start_position = field.small_field_canvas.coords(player.image_canvas_id)
end_position = []
print("Pierwsza pozycja: {} {}".format(start_position[0], start_position[1]))
#print(node.state.coord, node.state.direction, node.parent, node.action)
print("Pozycje myszy: {} {}".format(event.x, event.y))
for i in range(0, len(field.canvas_small_images)):
img_coords = field.small_field_canvas.coords(field.canvas_small_images[i])
if (img_coords[0] <= event.x and event.x <= img_coords[0] + IMAGE_SIZE) and (img_coords[1] <= event.y and event.y <= img_coords[1] + IMAGE_SIZE):
end_position = img_coords
if len(end_position) == 2:
print("Koncowa pozycja: {} {}".format(end_position[0], end_position[1]))
# Successor - only east
list_node_state = nd.successor(node.state)
for i in range(0, len(list_node_state)):
print('Node{} = State: {} {}, Parent: {} {}, Action: {}'.format(i + 1, list_node_state[i].state.coord, list_node_state[i].state.direction, list_node_state[i].parent.coord, list_node_state[i].parent.direction, list_node_state[i].action))
def PutMines(mines_array):
counter = 0