adding again everything after deleting whole repository (my mistake...)

This commit is contained in:
Adam Cherek 2022-05-27 11:34:00 +02:00
commit e07ab2a955
2278 changed files with 1011 additions and 0 deletions

33
agent.py Normal file
View File

@ -0,0 +1,33 @@
import pygame
import os
import sys
class Agent(pygame.sprite.Sprite):
def __init__(self, width, height, pos_x, pos_y, pos):
pygame.sprite.Sprite.__init__(self)
self.view = 5 # ile pól przed sobą widzi saper
self.image = pygame.image.load(os.path.join('images', 'ratAvatar.png')).convert_alpha()
self.image_scaled = pygame.transform.scale(self.image, (width, height))
self.rect = self.image_scaled.get_rect(center = (pos_x, pos_y))
self.pos_field = pos
def move(self, window_size, margin, distance, direction, poschanger):
if self.rect.right <= int(window_size) - margin*2 and direction == "RIGHT":
self.pos_field += poschanger
self.rect.centerx += distance
if self.rect.left >= margin*2 and direction == "LEFT":
self.pos_field += poschanger
self.rect.centerx -= distance
if self.rect.bottom <= int(window_size) - margin*2 and direction == "DOWN":
self.pos_field += poschanger
self.rect.centery += distance
if self.rect.top >= margin*2 and direction == "UP":
self.pos_field += poschanger
self.rect.centery -= distance

215
board.py Normal file
View File

@ -0,0 +1,215 @@
import random
import pygame
import sys
import pathfinder
import time
from decisiontree import DecisionTree
from imagerecognizer import ImageRecognizer
from objects import Grass
from objects import Mine
from objects import Rock
from objects import Puddle
MARGIN = 20 # marginesy - odległość kraty od końca okna
SQUARE_HEIGHT = 35
SQUARE_WIDTH = 35
CENTER_DIST = 38 # odległość pomiędzy środkami kwadratów
BOARDCOLS = 15 # liczba kolumn planszy
BOARDROWS = BOARDCOLS # liczba wierszy planszy
WINDOW_HEIGHT = BOARDCOLS * CENTER_DIST + (2 * MARGIN)
WINDOW_WIDTH = BOARDROWS * CENTER_DIST + (2 * MARGIN)
class Field: # obiekt clasy field jest pojedynczym polem planszy
def __init__(self, coordinates, color, fieldty):
Board.fields.append(self)
self.rect = pygame.Rect(coordinates[0], coordinates[1], SQUARE_WIDTH, SQUARE_HEIGHT)
self.color = color
self.type = fieldty
self.object = self.assign_object()
self.deley_value = self.object.deley
self.redisp = True
def assign_object(self):
if self.type == 'T':
object = Grass(self.rect.center[0],self.rect.center[1], SQUARE_WIDTH, SQUARE_HEIGHT)
return object
if self.type == 'P':
object = Puddle(self.rect.center[0],self.rect.center[1],SQUARE_WIDTH, SQUARE_HEIGHT)
return object
if self.type == 'R':
object = Rock(self.rect.center[0],self.rect.center[1],SQUARE_WIDTH, SQUARE_HEIGHT)
return object
if self.type == 'B':
object = Mine(self.rect.center[0],self.rect.center[1],SQUARE_WIDTH, SQUARE_HEIGHT)
return object
class Board:
fields = [] # tablica obiektów klasy filed, czyli po prostu tablica pól planszy gotowych do wizualizacji
bombs = 0
def __init__(self):
self.margin = MARGIN
self.square_high = SQUARE_HEIGHT
self.square_width = SQUARE_WIDTH
self.center_dist = CENTER_DIST
self.window_height = WINDOW_HEIGHT
self.window_widhth = WINDOW_WIDTH
self.boardcols = BOARDCOLS # liczba kolumn planszy
self.boardrows = BOARDROWS # liczba wierszy planszy
self.board = [[0 for i in range(self.boardcols)] for j in range(self.boardrows)]
self.firstwinner = True
pygame.display.set_caption("Saper")
self.game_display = pygame.display.set_mode((self.window_height, self.window_widhth)) # wielkość okna adaptująca się do wielkości planszy
self.load_board()
self.first_ground = self.board[0].index('T')
self.show_board()
self.init_board()
self.bombfield = pathfinder.find_bomb(self.fields, self.first_ground)
print(self.bombfield)
self.pathf = pathfinder.Pathfind(self.fields, self.bombfield, self.first_ground)
self.ir = ImageRecognizer()
self.dt = DecisionTree()
def load_board(self): # funkcja tworząca tablicę opisującą planszę
for i in range(self.boardrows):
for j in range(self.boardcols):
chance = random.randint(1,100) # prawdopodobieństwo że dane pole będzie terenem (T), przeszkodą (O) lub bombą (B)
if chance >= 1 and chance < 80:
self.board[i][j] = 'T'
if chance >= 80 and chance < 95:
chance = random.randint(1,2)
if chance == 1:
self.board[i][j] = 'R'
if chance == 2:
self.board[i][j] = 'P'
if chance >= 95 and chance <= 100:
self.board[i][j] = 'B'
self.bombs += 1
def show_board(self): # funkcja pomocnicza wypisująca tablicę opisującą planszę
for i in range(self.boardrows):
for j in range(self.boardcols):
print(self.board[i][j], end=' ')
print("")
print("")
print("bomby:",self.bombs)
def init_board(self): # funkcja inicjująca planszę
x = self.margin
y = self.margin
for i in range(self.boardrows):
for j in range(self.boardcols):
if self.board[i][j] == 'T':
Field((x, y), (0, 128,0), 'T') # tworzony jest obiekt clasy field zawierający współżędne oraz kolor danego pola planszy
if self.board[i][j] == 'R':
Field((x, y), (255, 255, 0), 'R')
if self.board[i][j] == 'P':
Field((x, y), (255, 255, 0), 'P')
if self.board[i][j] == 'B':
Field((x, y), (165, 42, 42), 'B')
x += self.center_dist
y += self.center_dist
x = self.margin
def objects_display(self,i):
objecttype = self.fields[i].object
self.game_display.blit(objecttype.image_scaled, objecttype.rect)
def board_events(self, agent):
for event in pygame.event.get():
self.agent_field_update(agent)
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: # klawisz esc zamyka program
sys.exit(0)
#if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT and agent.pos_field+1 < len(self.fields):
# if self.fields[agent.pos_field+1].object.walkable == 0:
# self.fields[agent.pos_field].redisp = True
# agent.move(self.window_height, self.margin, self.center_dist, "RIGHT", 1)
#if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT and agent.pos_field-1 >= 0:
# if self.fields[agent.pos_field - 1].object.walkable == 0:
# self.fields[agent.pos_field].redisp = True
# agent.move(self.window_height, self.margin, self.center_dist, "LEFT", -1)
#if event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN and agent.pos_field+BOARDROWS < len(self.fields):
# if self.fields[agent.pos_field + BOARDROWS].object.walkable == 0:
# self.fields[agent.pos_field].redisp = True
# agent.move(self.window_height, self.margin, self.center_dist, "DOWN", BOARDROWS)
#if event.type == pygame.KEYDOWN and event.key == pygame.K_UP and agent.pos_field-BOARDROWS >= 0:
# if self.fields[agent.pos_field - BOARDROWS].object.walkable == 0:
# self.fields[agent.pos_field].redisp = True
# agent.move(self.window_height,self.margin,self.center_dist,"UP", -BOARDROWS)
def agent_field_update(self,agent):
agent.cooldown = 100
if self.fields[agent.pos_field].type == 'B' and self.fields[agent.pos_field].object.defused == False:
if self.ir.recognize(self.fields[agent.pos_field].object.itr) == "stones":
print("to kamień!")
self.fields[agent.pos_field].object.its_rock(SQUARE_WIDTH, SQUARE_HEIGHT)
self.fields[agent.pos_field].redisp = True
self.bombs -= 1
else:
print("to bomba!")
wtd = self.dt.make_decision(((self.bombs*100)//(BOARDCOLS**2))+1, self.fields[agent.pos_field].object.time, self.fields[agent.pos_field].object.reach)
if wtd == "Defuse":
self.fields[agent.pos_field].object.defuse(SQUARE_WIDTH, SQUARE_HEIGHT)
self.fields[agent.pos_field].redisp = True
if wtd == "Move away":
self.fields[agent.pos_field].object.move_away(SQUARE_WIDTH, SQUARE_HEIGHT)
self.fields[agent.pos_field].redisp = True
self.bombs -= 1
if self.bombs > 0:
self.bombfield = pathfinder.find_bomb(self.fields, agent.pos_field)
#print(self.bombfield)
self.pathf = pathfinder.Pathfind(self.fields, self.bombfield, agent.pos_field)
def automove_agent(self,agent):
self.agent_field_update(agent)
if len(self.pathf.way) > 0:
wayfield = self.pathf.way[0]
self.pathf.way.remove(wayfield)
if agent.pos_field - BOARDCOLS == wayfield:
self.fields[agent.pos_field].redisp = True
agent.move(self.window_height, self.margin, self.center_dist, "UP", -BOARDCOLS)
if agent.pos_field + BOARDCOLS == wayfield:
self.fields[agent.pos_field].redisp = True
agent.move(self.window_height, self.margin, self.center_dist, "DOWN", BOARDCOLS)
if agent.pos_field - 1 == wayfield:
self.fields[agent.pos_field].redisp = True
agent.move(self.window_height, self.margin, self.center_dist, "LEFT", -1)
if agent.pos_field + 1 == wayfield:
self.fields[agent.pos_field].redisp = True
agent.move(self.window_height, self.margin, self.center_dist, "RIGHT", 1)
def full_board_display(self,first): # funkcja pomocnicza wywołująca program, w celu wizualizacji planszy możną ją wywołać
if self.bombs <= 0 and self.firstwinner == True:
print("wszystkie miny rozbrojone!")
self.firstwinner = False
if first == True:
self.game_display.fill((0, 0, 0))
i=0
for square in self.fields:
if square.redisp == True:
pygame.draw.rect(self.game_display, square.color, square.rect)
self.objects_display(i)
square.redisp = False
i=i+1

391
decisiontree.csv Normal file
View File

@ -0,0 +1,391 @@
Percent of mines;Time to explosion;Range of explosion;What to do
1;1;1;Defuse
1;2;1;Defuse
1;3;1;Move away
1;4;1;Move away
1;5;1;Move away
1;6;1;Move away
1;7;1;Move away
1;8;1;Move away
1;9;1;Move away
1;10;1;Move away
1;1;2;Defuse
1;2;2;Defuse
1;3;2;Move away
1;4;2;Move away
1;5;2;Move away
1;6;2;Move away
1;7;2;Move away
1;8;2;Move away
1;9;2;Move away
1;10;2;Move away
1;1;3;Defuse
1;2;3;Defuse
1;3;3;Move away
1;4;3;Move away
1;5;3;Move away
1;6;3;Move away
1;7;3;Move away
1;8;3;Move away
1;9;3;Move away
2;10;3;Move away
2;1;1;Defuse
2;2;1;Defuse
2;3;1;Move away
2;4;1;Move away
2;5;1;Move away
2;6;1;Move away
2;7;1;Move away
2;8;1;Move away
2;9;1;Move away
2;10;1;Move away
2;1;2;Defuse
2;2;2;Defuse
2;3;2;Move away
2;4;2;Move away
2;5;2;Move away
2;6;2;Move away
2;7;2;Move away
2;8;2;Move away
2;9;2;Move away
2;10;2;Move away
2;1;3;Defuse
2;2;3;Defuse
2;3;3;Move away
2;4;3;Move away
2;5;3;Move away
2;6;3;Move away
2;7;3;Move away
2;8;3;Move away
2;9;3;Move away
2;10;3;Move away
3;1;1;Defuse
3;2;1;Defuse
3;3;1;Move away
3;4;1;Move away
3;5;1;Move away
3;6;1;Move away
3;7;1;Move away
3;8;1;Move away
3;9;1;Move away
3;10;1;Move away
3;1;2;Defuse
3;2;2;Defuse
3;3;2;Move away
3;4;2;Move away
3;5;2;Move away
3;6;2;Move away
3;7;2;Move away
3;8;2;Move away
3;9;2;Move away
3;10;2;Move away
3;1;3;Defuse
3;2;3;Defuse
3;3;3;Move away
3;4;3;Move away
3;5;3;Move away
3;6;3;Move away
3;7;3;Move away
3;8;3;Move away
3;9;3;Move away
3;10;3;Move away
4;1;1;Defuse
4;2;1;Defuse
4;3;1;Defuse
4;4;1;Defuse
4;5;1;Defuse
4;6;1;Defuse
4;7;1;Defuse
4;8;1;Defuse
4;9;1;Defuse
4;10;1;Defuse
4;1;2;Defuse
4;2;2;Defuse
4;3;2;Move away
4;4;2;Move away
4;5;2;Move away
4;6;2;Move away
4;7;2;Move away
4;8;2;Move away
4;9;2;Move away
4;10;2;Move away
4;1;3;Defuse
4;2;3;Defuse
4;3;3;Move away
4;4;3;Move away
4;5;3;Move away
4;6;3;Move away
4;7;3;Move away
4;8;3;Move away
4;9;3;Move away
4;10;3;Move away
5;1;1;Defuse
5;2;1;Defuse
5;3;1;Defuse
5;4;1;Defuse
5;5;1;Defuse
5;6;1;Defuse
5;7;1;Defuse
5;8;1;Defuse
5;9;1;Defuse
5;10;1;Defuse
5;1;2;Defuse
5;2;2;Defuse
5;3;2;Defuse
5;4;2;Defuse
5;5;2;Defuse
5;6;2;Move away
5;7;2;Move away
5;8;2;Move away
5;9;2;Move away
5;10;2;Move away
5;1;3;Defuse
5;2;3;Defuse
5;3;3;Move away
5;4;3;Move away
5;5;3;Move away
5;6;3;Move away
5;7;3;Move away
5;8;3;Move away
5;9;3;Move away
5;10;3;Move away
6;1;1;Defuse
6;2;1;Defuse
6;3;1;Defuse
6;4;1;Defuse
6;5;1;Defuse
6;6;1;Defuse
6;7;1;Defuse
6;8;1;Defuse
6;9;1;Defuse
6;10;1;Defuse
6;1;2;Defuse
6;2;2;Defuse
6;3;2;Defuse
6;4;2;Defuse
6;5;2;Defuse
6;6;2;Move away
6;7;2;Move away
6;8;2;Move away
6;9;2;Move away
6;10;2;Move away
6;1;3;Defuse
6;2;3;Defuse
6;3;3;Move away
6;4;3;Move away
6;5;3;Move away
6;6;3;Move away
6;7;3;Move away
6;8;3;Move away
6;9;3;Move away
6;10;3;Move away
7;1;1;Defuse
7;2;1;Defuse
7;3;1;Defuse
7;4;1;Defuse
7;5;1;Defuse
7;6;1;Defuse
7;7;1;Defuse
7;8;1;Defuse
7;9;1;Defuse
7;10;1;Defuse
7;1;2;Defuse
7;2;2;Defuse
7;3;2;Defuse
7;4;2;Defuse
7;5;2;Defuse
7;6;2;Defuse
7;7;2;Defuse
7;8;2;Defuse
7;9;2;Defuse
7;10;2;Defuse
7;1;3;Defuse
7;2;3;Defuse
7;3;3;Move away
7;4;3;Move away
7;5;3;Move away
7;6;3;Move away
7;7;3;Move away
7;8;3;Move away
7;9;3;Move away
7;10;3;Move away
8;1;1;Defuse
8;2;1;Defuse
8;3;1;Defuse
8;4;1;Defuse
8;5;1;Defuse
8;6;1;Defuse
8;7;1;Defuse
8;8;1;Defuse
8;9;1;Defuse
8;10;1;Defuse
8;1;2;Defuse
8;2;2;Defuse
8;3;2;Defuse
8;4;2;Defuse
8;5;2;Defuse
8;6;2;Defuse
8;7;2;Defuse
8;8;2;Defuse
8;9;2;Defuse
8;10;2;Defuse
8;1;3;Defuse
8;2;3;Defuse
8;3;3;Move away
8;4;3;Move away
8;5;3;Move away
8;6;3;Move away
8;7;3;Move away
8;8;3;Move away
8;9;3;Move away
8;10;3;Move away
9;1;1;Defuse
9;2;1;Defuse
9;3;1;Defuse
9;4;1;Defuse
9;5;1;Defuse
9;6;1;Defuse
9;7;1;Defuse
9;8;1;Defuse
9;9;1;Defuse
9;10;1;Defuse
9;1;2;Defuse
9;2;2;Defuse
9;3;2;Defuse
9;4;2;Defuse
9;5;2;Defuse
9;6;2;Defuse
9;7;2;Defuse
9;8;2;Defuse
9;9;2;Defuse
9;10;2;Defuse
9;1;3;Defuse
9;2;3;Defuse
9;3;3;Defuse
9;4;3;Defuse
9;5;3;Defuse
9;6;3;Move away
9;7;3;Move away
9;8;3;Move away
9;9;3;Move away
9;10;3;Move away
10;1;1;Defuse
10;2;1;Defuse
10;3;1;Defuse
10;4;1;Defuse
10;5;1;Defuse
10;6;1;Defuse
10;7;1;Defuse
10;8;1;Defuse
10;9;1;Defuse
10;10;1;Defuse
10;1;2;Defuse
10;2;2;Defuse
10;3;2;Defuse
10;4;2;Defuse
10;5;2;Defuse
10;6;2;Defuse
10;7;2;Defuse
10;8;2;Defuse
10;9;2;Defuse
10;10;2;Defuse
10;1;3;Defuse
10;2;3;Defuse
10;3;3;Defuse
10;4;3;Defuse
10;5;3;Defuse
10;6;3;Defuse
10;7;3;Defuse
10;8;3;Defuse
10;9;3;Defuse
10;10;3;Defuse
20;1;1;Defuse
20;2;1;Defuse
20;3;1;Defuse
20;4;1;Defuse
20;5;1;Defuse
20;6;1;Defuse
20;7;1;Defuse
20;8;1;Defuse
20;9;1;Defuse
20;10;1;Defuse
20;1;2;Defuse
20;2;2;Defuse
20;3;2;Defuse
20;4;2;Defuse
20;5;2;Defuse
20;6;2;Defuse
20;7;2;Defuse
20;8;2;Defuse
20;9;2;Defuse
20;10;2;Defuse
20;1;3;Defuse
20;2;3;Defuse
20;3;3;Defuse
20;4;3;Defuse
20;5;3;Defuse
20;6;3;Defuse
20;7;3;Defuse
20;8;3;Defuse
20;9;3;Defuse
20;10;3;Defuse
40;1;1;Defuse
40;2;1;Defuse
40;3;1;Defuse
40;4;1;Defuse
40;5;1;Defuse
40;6;1;Defuse
40;7;1;Defuse
40;8;1;Defuse
40;9;1;Defuse
40;10;1;Defuse
40;1;2;Defuse
40;2;2;Defuse
40;3;2;Defuse
40;4;2;Defuse
40;5;2;Defuse
60;6;2;Defuse
60;7;2;Defuse
60;8;2;Defuse
60;9;2;Defuse
60;10;2;Defuse
60;1;3;Defuse
60;2;3;Defuse
60;3;3;Defuse
60;4;3;Defuse
60;5;3;Defuse
60;6;3;Defuse
60;7;3;Defuse
60;8;3;Defuse
60;9;3;Defuse
60;10;3;Defuse
80;1;1;Defuse
80;2;1;Defuse
80;3;1;Defuse
80;4;1;Defuse
80;5;1;Defuse
80;6;1;Defuse
80;7;1;Defuse
80;8;1;Defuse
80;9;1;Defuse
80;10;1;Defuse
80;1;2;Defuse
80;2;2;Defuse
80;3;2;Defuse
80;4;2;Defuse
80;5;2;Defuse
100;6;2;Defuse
100;7;2;Defuse
100;8;2;Defuse
100;9;2;Defuse
100;10;2;Defuse
100;1;3;Defuse
100;2;3;Defuse
100;3;3;Defuse
100;4;3;Defuse
100;5;3;Defuse
100;6;3;Defuse
100;7;3;Defuse
100;8;3;Defuse
100;9;3;Defuse
100;10;3;Defuse
1 Percent of mines Time to explosion Range of explosion What to do
2 1 1 1 Defuse
3 1 2 1 Defuse
4 1 3 1 Move away
5 1 4 1 Move away
6 1 5 1 Move away
7 1 6 1 Move away
8 1 7 1 Move away
9 1 8 1 Move away
10 1 9 1 Move away
11 1 10 1 Move away
12 1 1 2 Defuse
13 1 2 2 Defuse
14 1 3 2 Move away
15 1 4 2 Move away
16 1 5 2 Move away
17 1 6 2 Move away
18 1 7 2 Move away
19 1 8 2 Move away
20 1 9 2 Move away
21 1 10 2 Move away
22 1 1 3 Defuse
23 1 2 3 Defuse
24 1 3 3 Move away
25 1 4 3 Move away
26 1 5 3 Move away
27 1 6 3 Move away
28 1 7 3 Move away
29 1 8 3 Move away
30 1 9 3 Move away
31 2 10 3 Move away
32 2 1 1 Defuse
33 2 2 1 Defuse
34 2 3 1 Move away
35 2 4 1 Move away
36 2 5 1 Move away
37 2 6 1 Move away
38 2 7 1 Move away
39 2 8 1 Move away
40 2 9 1 Move away
41 2 10 1 Move away
42 2 1 2 Defuse
43 2 2 2 Defuse
44 2 3 2 Move away
45 2 4 2 Move away
46 2 5 2 Move away
47 2 6 2 Move away
48 2 7 2 Move away
49 2 8 2 Move away
50 2 9 2 Move away
51 2 10 2 Move away
52 2 1 3 Defuse
53 2 2 3 Defuse
54 2 3 3 Move away
55 2 4 3 Move away
56 2 5 3 Move away
57 2 6 3 Move away
58 2 7 3 Move away
59 2 8 3 Move away
60 2 9 3 Move away
61 2 10 3 Move away
62 3 1 1 Defuse
63 3 2 1 Defuse
64 3 3 1 Move away
65 3 4 1 Move away
66 3 5 1 Move away
67 3 6 1 Move away
68 3 7 1 Move away
69 3 8 1 Move away
70 3 9 1 Move away
71 3 10 1 Move away
72 3 1 2 Defuse
73 3 2 2 Defuse
74 3 3 2 Move away
75 3 4 2 Move away
76 3 5 2 Move away
77 3 6 2 Move away
78 3 7 2 Move away
79 3 8 2 Move away
80 3 9 2 Move away
81 3 10 2 Move away
82 3 1 3 Defuse
83 3 2 3 Defuse
84 3 3 3 Move away
85 3 4 3 Move away
86 3 5 3 Move away
87 3 6 3 Move away
88 3 7 3 Move away
89 3 8 3 Move away
90 3 9 3 Move away
91 3 10 3 Move away
92 4 1 1 Defuse
93 4 2 1 Defuse
94 4 3 1 Defuse
95 4 4 1 Defuse
96 4 5 1 Defuse
97 4 6 1 Defuse
98 4 7 1 Defuse
99 4 8 1 Defuse
100 4 9 1 Defuse
101 4 10 1 Defuse
102 4 1 2 Defuse
103 4 2 2 Defuse
104 4 3 2 Move away
105 4 4 2 Move away
106 4 5 2 Move away
107 4 6 2 Move away
108 4 7 2 Move away
109 4 8 2 Move away
110 4 9 2 Move away
111 4 10 2 Move away
112 4 1 3 Defuse
113 4 2 3 Defuse
114 4 3 3 Move away
115 4 4 3 Move away
116 4 5 3 Move away
117 4 6 3 Move away
118 4 7 3 Move away
119 4 8 3 Move away
120 4 9 3 Move away
121 4 10 3 Move away
122 5 1 1 Defuse
123 5 2 1 Defuse
124 5 3 1 Defuse
125 5 4 1 Defuse
126 5 5 1 Defuse
127 5 6 1 Defuse
128 5 7 1 Defuse
129 5 8 1 Defuse
130 5 9 1 Defuse
131 5 10 1 Defuse
132 5 1 2 Defuse
133 5 2 2 Defuse
134 5 3 2 Defuse
135 5 4 2 Defuse
136 5 5 2 Defuse
137 5 6 2 Move away
138 5 7 2 Move away
139 5 8 2 Move away
140 5 9 2 Move away
141 5 10 2 Move away
142 5 1 3 Defuse
143 5 2 3 Defuse
144 5 3 3 Move away
145 5 4 3 Move away
146 5 5 3 Move away
147 5 6 3 Move away
148 5 7 3 Move away
149 5 8 3 Move away
150 5 9 3 Move away
151 5 10 3 Move away
152 6 1 1 Defuse
153 6 2 1 Defuse
154 6 3 1 Defuse
155 6 4 1 Defuse
156 6 5 1 Defuse
157 6 6 1 Defuse
158 6 7 1 Defuse
159 6 8 1 Defuse
160 6 9 1 Defuse
161 6 10 1 Defuse
162 6 1 2 Defuse
163 6 2 2 Defuse
164 6 3 2 Defuse
165 6 4 2 Defuse
166 6 5 2 Defuse
167 6 6 2 Move away
168 6 7 2 Move away
169 6 8 2 Move away
170 6 9 2 Move away
171 6 10 2 Move away
172 6 1 3 Defuse
173 6 2 3 Defuse
174 6 3 3 Move away
175 6 4 3 Move away
176 6 5 3 Move away
177 6 6 3 Move away
178 6 7 3 Move away
179 6 8 3 Move away
180 6 9 3 Move away
181 6 10 3 Move away
182 7 1 1 Defuse
183 7 2 1 Defuse
184 7 3 1 Defuse
185 7 4 1 Defuse
186 7 5 1 Defuse
187 7 6 1 Defuse
188 7 7 1 Defuse
189 7 8 1 Defuse
190 7 9 1 Defuse
191 7 10 1 Defuse
192 7 1 2 Defuse
193 7 2 2 Defuse
194 7 3 2 Defuse
195 7 4 2 Defuse
196 7 5 2 Defuse
197 7 6 2 Defuse
198 7 7 2 Defuse
199 7 8 2 Defuse
200 7 9 2 Defuse
201 7 10 2 Defuse
202 7 1 3 Defuse
203 7 2 3 Defuse
204 7 3 3 Move away
205 7 4 3 Move away
206 7 5 3 Move away
207 7 6 3 Move away
208 7 7 3 Move away
209 7 8 3 Move away
210 7 9 3 Move away
211 7 10 3 Move away
212 8 1 1 Defuse
213 8 2 1 Defuse
214 8 3 1 Defuse
215 8 4 1 Defuse
216 8 5 1 Defuse
217 8 6 1 Defuse
218 8 7 1 Defuse
219 8 8 1 Defuse
220 8 9 1 Defuse
221 8 10 1 Defuse
222 8 1 2 Defuse
223 8 2 2 Defuse
224 8 3 2 Defuse
225 8 4 2 Defuse
226 8 5 2 Defuse
227 8 6 2 Defuse
228 8 7 2 Defuse
229 8 8 2 Defuse
230 8 9 2 Defuse
231 8 10 2 Defuse
232 8 1 3 Defuse
233 8 2 3 Defuse
234 8 3 3 Move away
235 8 4 3 Move away
236 8 5 3 Move away
237 8 6 3 Move away
238 8 7 3 Move away
239 8 8 3 Move away
240 8 9 3 Move away
241 8 10 3 Move away
242 9 1 1 Defuse
243 9 2 1 Defuse
244 9 3 1 Defuse
245 9 4 1 Defuse
246 9 5 1 Defuse
247 9 6 1 Defuse
248 9 7 1 Defuse
249 9 8 1 Defuse
250 9 9 1 Defuse
251 9 10 1 Defuse
252 9 1 2 Defuse
253 9 2 2 Defuse
254 9 3 2 Defuse
255 9 4 2 Defuse
256 9 5 2 Defuse
257 9 6 2 Defuse
258 9 7 2 Defuse
259 9 8 2 Defuse
260 9 9 2 Defuse
261 9 10 2 Defuse
262 9 1 3 Defuse
263 9 2 3 Defuse
264 9 3 3 Defuse
265 9 4 3 Defuse
266 9 5 3 Defuse
267 9 6 3 Move away
268 9 7 3 Move away
269 9 8 3 Move away
270 9 9 3 Move away
271 9 10 3 Move away
272 10 1 1 Defuse
273 10 2 1 Defuse
274 10 3 1 Defuse
275 10 4 1 Defuse
276 10 5 1 Defuse
277 10 6 1 Defuse
278 10 7 1 Defuse
279 10 8 1 Defuse
280 10 9 1 Defuse
281 10 10 1 Defuse
282 10 1 2 Defuse
283 10 2 2 Defuse
284 10 3 2 Defuse
285 10 4 2 Defuse
286 10 5 2 Defuse
287 10 6 2 Defuse
288 10 7 2 Defuse
289 10 8 2 Defuse
290 10 9 2 Defuse
291 10 10 2 Defuse
292 10 1 3 Defuse
293 10 2 3 Defuse
294 10 3 3 Defuse
295 10 4 3 Defuse
296 10 5 3 Defuse
297 10 6 3 Defuse
298 10 7 3 Defuse
299 10 8 3 Defuse
300 10 9 3 Defuse
301 10 10 3 Defuse
302 20 1 1 Defuse
303 20 2 1 Defuse
304 20 3 1 Defuse
305 20 4 1 Defuse
306 20 5 1 Defuse
307 20 6 1 Defuse
308 20 7 1 Defuse
309 20 8 1 Defuse
310 20 9 1 Defuse
311 20 10 1 Defuse
312 20 1 2 Defuse
313 20 2 2 Defuse
314 20 3 2 Defuse
315 20 4 2 Defuse
316 20 5 2 Defuse
317 20 6 2 Defuse
318 20 7 2 Defuse
319 20 8 2 Defuse
320 20 9 2 Defuse
321 20 10 2 Defuse
322 20 1 3 Defuse
323 20 2 3 Defuse
324 20 3 3 Defuse
325 20 4 3 Defuse
326 20 5 3 Defuse
327 20 6 3 Defuse
328 20 7 3 Defuse
329 20 8 3 Defuse
330 20 9 3 Defuse
331 20 10 3 Defuse
332 40 1 1 Defuse
333 40 2 1 Defuse
334 40 3 1 Defuse
335 40 4 1 Defuse
336 40 5 1 Defuse
337 40 6 1 Defuse
338 40 7 1 Defuse
339 40 8 1 Defuse
340 40 9 1 Defuse
341 40 10 1 Defuse
342 40 1 2 Defuse
343 40 2 2 Defuse
344 40 3 2 Defuse
345 40 4 2 Defuse
346 40 5 2 Defuse
347 60 6 2 Defuse
348 60 7 2 Defuse
349 60 8 2 Defuse
350 60 9 2 Defuse
351 60 10 2 Defuse
352 60 1 3 Defuse
353 60 2 3 Defuse
354 60 3 3 Defuse
355 60 4 3 Defuse
356 60 5 3 Defuse
357 60 6 3 Defuse
358 60 7 3 Defuse
359 60 8 3 Defuse
360 60 9 3 Defuse
361 60 10 3 Defuse
362 80 1 1 Defuse
363 80 2 1 Defuse
364 80 3 1 Defuse
365 80 4 1 Defuse
366 80 5 1 Defuse
367 80 6 1 Defuse
368 80 7 1 Defuse
369 80 8 1 Defuse
370 80 9 1 Defuse
371 80 10 1 Defuse
372 80 1 2 Defuse
373 80 2 2 Defuse
374 80 3 2 Defuse
375 80 4 2 Defuse
376 80 5 2 Defuse
377 100 6 2 Defuse
378 100 7 2 Defuse
379 100 8 2 Defuse
380 100 9 2 Defuse
381 100 10 2 Defuse
382 100 1 3 Defuse
383 100 2 3 Defuse
384 100 3 3 Defuse
385 100 4 3 Defuse
386 100 5 3 Defuse
387 100 6 3 Defuse
388 100 7 3 Defuse
389 100 8 3 Defuse
390 100 9 3 Defuse
391 100 10 3 Defuse

29
decisiontree.py Normal file
View File

@ -0,0 +1,29 @@
import random
import pandas
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
decision = {'Defuse': 0, 'Move away': 1}
variables = {'Percent of mines', 'Time to explosion', 'Range of explosion'}
class DecisionTree:
def __init__(self):
self.data = pandas.read_csv("decisiontree.csv", sep=';')
#print(self.data)
self.data['What to do'] = self.data['What to do'].map(decision)
self.treevariables = self.data[variables]
self.treeresault = self.data['What to do']
self.decisiontree = DecisionTreeClassifier(random_state=0)
self.decisiontree = self.decisiontree.fit(self.treevariables.values, self.treeresault.values)
def make_decision(self, minespercent, exptime, exprange):
wtd = self.decisiontree.predict([[minespercent, exptime, exprange]])
#print("zmienne:", minespercent, exptime, exprange)
#print("wdt:", wtd)
if wtd == [0]:
return "Defuse"
if wtd == [1]:
return "Move away"

54
imagerecognizer.py Normal file
View File

@ -0,0 +1,54 @@
import tensorflow
from tensorflow import keras
from keras import layers as ls
import numpy as np
image_height = 64
image_width = 64
batch_size = 32
sets_path = "./learning_sets"
model_path="./IR.model"
train_new_model=True
class ImageRecognizer():
def __init__(self):
if train_new_model == True:
# deklarowanie setów treningowych i testowych
self.trainset = keras.utils.image_dataset_from_directory(sets_path, validation_split=0.2, subset="training",seed=0, image_size=(image_height, image_width),batch_size=batch_size)
self.testset = keras.utils.image_dataset_from_directory(sets_path, validation_split=0.2,subset="validation", seed=0,image_size=(image_height, image_width),atch_size=batch_size)
self.class_names = self.trainset.class_names
self.trainset = self.trainset.cache().shuffle(1000).prefetch(buffer_size=tensorflow.data.AUTOTUNE)
self.testset = self.testset.cache().prefetch(buffer_size=tensorflow.data.AUTOTUNE)
#tworzenie modelu
self.model = keras.models.Sequential()
self.model.add(ls.Rescaling(1. / 255, input_shape=(image_height, image_width, 3)))
self.model.add(ls.Conv2D(16, (3,3), activation='relu'))
self.model.add(ls.MaxPooling2D((2,2)))
self.model.add(ls.Conv2D(32, (3,3), activation='relu'))
self.model.add(ls.MaxPooling2D((2,2)))
self.model.add(ls.Conv2D(64, (3,3), activation='relu'))
self.model.add(ls.MaxPooling2D(2,2))
self.model.add(ls.Flatten())
self.model.add(ls.Dense(128, activation='relu'))
self.model.add(ls.Dense(2))
#kompilacja modelu
self.model.compile(optimizer='adam',loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),metrics=['accuracy'])
#epochowanie
self.model.fit(self.trainset,validation_data=self.testset,epochs=10)
self.model.save(model_path)
else:
self.class_names = ("bombs","stones")
self.model = tensorflow.keras.models.load_model(model_path)
def recognize(self,image_path):
#wybor obrazu do rekognizacji
image = keras.utils.load_img(image_path, target_size=(image_height, image_width))
image_array = keras.utils.img_to_array(image)
image_array = tensorflow.expand_dims(image_array, 0)
#predykcja
prediction = self.model.predict(image_array)
classification = tensorflow.nn.softmax(prediction[0])
#wynik predykcji
print("Image: ",image_path," is classified as: ",format(self.class_names[np.argmax(classification)])," with: ", 100 * np.max(classification), " accuracy")
return format(self.class_names[np.argmax(classification)])

BIN
images/mine.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
images/mine_defused.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
images/mine_moved.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
images/puddle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

BIN
images/ratAvatar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
images/rock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
images/testAvatar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
images/tile.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Some files were not shown because too many files have changed in this diff Show More