Newer
Older
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package GUI.game;
import java.util.ArrayList;
/**
*
* @author Dániel
*/
public class RecursiveNullFinder extends Thread
{
private Controller controller;
private int x;
private int y;
private ArrayList<int[]> nulls;
private ArrayList<int[]> wasThere;
private int depth = 0;
public RecursiveNullFinder(int x, int y,ArrayList<int[]> nulls,ArrayList<int[]> wasThere,Controller controller)
{
this.x =x;
this.y =y;
this.nulls = nulls;
this.wasThere = wasThere;
this.controller = controller;
}
private ArrayList<int[]> getNullFieldAround()
{
if( wasThere == null )
wasThere = new ArrayList<>();
ArrayList<int[]> nullsAround;
if( nulls != null )
nullsAround = nulls;
else
nullsAround = new ArrayList<>();
int pos[] = new int[2];
pos[0] = x;
pos[1] = y;
String[] neighbours = controller.model.getNeighbours(pos);
for (int i = 0; i < 9; i++)
{
int[] posN = this.controller.model.getPosFromString(neighbours[i]);
if( posN[0] == -1 || posN[1] == -1 )
{
int dummy = 10;
}
else if( this.controller.model.calculateMinesAround(posN[0], posN[1]) == 0 )
{
if( !this.isContains(wasThere, posN) )
{
nullsAround.add(posN);
wasThere.add(posN);
this.x = posN[0];
this.y = posN[1];
this.nulls = nullsAround;
this.depth++;
System.out.println(this.depth);
ArrayList<int[]> newNulls = this.getNullFieldAround();
// nullsAround.addAll(newNulls);
for( int[] actNull : newNulls )
{
this.addUnique(nullsAround, actNull);
}
}
}
}
return nullsAround;
}
public Boolean isContains(ArrayList<int[]> container, int[] position)
{
for( int[] act : container)
{
if( act[0] == position[0] && act[1] == position[1] )
return true;
}
return false;
}
public ArrayList<int[]> addUnique(ArrayList<int[]> to, int[] add)
{
for (int[] actTo : to )
{
if( actTo == add )
return to;
}
to.add(add);
return to;
}
@Override
public void run()
{
if( controller.model.nulls == null )
controller.model.nulls = new ArrayList<int[]>();
controller.model.nulls = this.getNullFieldAround();
controller.model.calculateDone = true;
}
}