-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndividual.py
108 lines (94 loc) · 3.85 KB
/
Individual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/bash
# -*- coding: utf-8 -*
import Cargo
import random
class Individual:
topLeftCorner_X = None
topLeftCorner_Y = None
isVisible = None
cargo = None
def __init__(self,x):
#super().__init__()
self.isVisible = random.choice([True, False])
self.topLeftCorner_X = random.randrange(0, 100, 1)
self.topLeftCorner_Y = random.randrange(0, 100, 1)
if x == 1:
self.cargo = Cargo.Cargo(1,1)
elif x == 2:
self.cargo = Cargo.Cargo(1,2)
elif x == 3:
self.cargo = Cargo.Cargo(2,1)
elif x == 4:
self.cargo = Cargo.Cargo(2,2)
elif x == 5:
self.cargo = Cargo.Cargo(2,3)
elif x == 6:
self.cargo = Cargo.Cargo(3,2)
elif x == 7:
self.cargo = Cargo.Cargo(5,5)
#nie dziala
#szkielet, mozna zmienic koncepcje, trzeba poprawic zeby nie wykraczac poza zakres, lub zmienic ladunek tak zeby nie mogl wykraczac poza zakres
def registerCargo(self, warehouse):
for i in range(self.topLeftCorner_Y, self.topLeftCorner_Y + self.cargo.height):
for j in range(self.topLeftCorner_X,self.topLeftCorner_X + self.cargo.width):
if i >= 0 and i <= 100 and j >= 0 and j <= 100:
if warehouse[i][j] <= -3:
warehouse[i][j] = warehouse[i][j] - 1
elif warehouse[i][j] >= 0:
warehouse[i][j] = warehouse[i][j] + 1
def isThereAPath(self, matrix):
result = False
for i in range(self.topLeftCorner_X, self.topLeftCorner_X + self.cargo.width, 1):
result = self.findPath(matrix, self.topLeftCorner_Y, i)
if result == True:
return True
if self.cargo.height > 1:
result = self.findPath(matrix, self.topLeftCorner_Y + self.cargo.height -1, i)
if result == True:
return True
if self.cargo.height > 1:
for i in range(self.topLeftCorner_Y, self.topLeftCorner_Y + self.cargo.height, 1):
result = self.findPath(matrix, i, self.topLeftCorner_X)
if result == True:
return True
if self.cargo.width > 1:
result = self.findPath(matrix, i, self.topLeftCorner_X + self.cargo.width - 1)
if result == True:
return True
def findPath(self, matrix, x, y):
if matrix[x][y] == -1:
return True
elif matrix[x-1][y] == 0:
top = self.findPath(matrix, x-1, y)
if top == True:
return top
elif matrix[x][y+1] == 0:
right = self.findPath(matrix, x, y+1)
if right == True:
return right
elif matrix[x+1][y] == 0:
down = self.findPath(matrix, x+1, y)
if down == True:
return down
elif matrix[x][y-1] == 0:
left = self.findPath(matrix, x, y-1)
if left == True:
return left
return False
def isFullyInBounds(self, matrix, height, width):
for i in range(self.topLeftCorner_Y, self.topLeftCorner_Y + self.cargo.height):
for j in range(self.topLeftCorner_X, self.topLeftCorner_X + self.cargo.width):
if i < height and j < width:
if matrix[i][j] < 0:
return False
return True
def mutate(self):
a = random.randrange(1, 11, 1)
if a == 1:
b = random.randrange(1, 4, 1)
if b == 1:
self.isVisible = random.choice([True, False])
elif b == 2:
self.topLeftCorner_X = random.randrange(0, 100, 1)
else:
self.topLeftCorner_Y = random.randrange(0, 100, 1)