Skip to content

Commit 3cad23f

Browse files
committed
Mid-work commit
Changed workstation and I don't remember all the changed I made => Commit Everything and fix it in latter commits.
1 parent dbeed45 commit 3cad23f

File tree

8 files changed

+34
-31
lines changed

8 files changed

+34
-31
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Generated files
2525
bin/
26-
gen/
26+
taskClass/
2727

2828
# Gradle files
2929
.gradle/
@@ -40,7 +40,7 @@ proguard/
4040
*.log
4141

4242
### Android Patch ###
43-
gen-external-apklibs
43+
taskClass-external-apklibs
4444

4545

4646
### Intellij ###

app/src/main/java/com/phikal/regex/games/match/MatchTask.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
import com.phikal.regex.models.Task;
1414
import com.phikal.regex.models.Word;
1515

16+
import java.io.Serializable;
1617
import java.util.ArrayList;
1718
import java.util.Arrays;
1819
import java.util.Collection;
1920
import java.util.List;
2021
import java.util.regex.Pattern;
2122
import java.util.regex.PatternSyntaxException;
2223

23-
public abstract class MatchTask extends Task {
24+
public abstract class MatchTask extends Task implements Serializable {
2425

2526
private Collection<MatchWord> allWords = new ArrayList<>();
26-
MatchInput input;
27-
List<Collumn> collumns;
27+
private MatchInput input;
28+
private List<Collumn> collumns;
2829

2930
MatchTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
3031
super(ctx, g, p, pc);
@@ -47,7 +48,7 @@ public Input getInput() {
4748
return input;
4849
}
4950

50-
protected class MatchWord extends Word {
51+
protected class MatchWord extends Word implements Serializable {
5152
private final boolean match;
5253
private final String word;
5354

@@ -64,7 +65,7 @@ public String getString() {
6465

6566
}
6667

67-
protected class MatchCollumn implements Collumn {
68+
protected class MatchCollumn implements Collumn, Serializable {
6869
private Context ctx;
6970
private List<MatchWord> words = null;
7071
private boolean match;
@@ -89,7 +90,7 @@ public List<? extends Word> getWords() {
8990
}
9091
}
9192

92-
protected class MatchInput extends Input {
93+
protected class MatchInput extends Input implements Serializable {
9394
Context ctx;
9495

9596
MatchInput(Context ctx) {
@@ -118,9 +119,9 @@ public void afterTextChanged(Editable pat) {
118119
Word.Matches.NONE);
119120
}
120121

121-
if (allMatch) {
122-
getProgressCallback().progress(new Progress(ctx,
123-
getGame().name(), getProgress()));
122+
if (allMatch && pat.length() > 0) {
123+
getProgressCallback().progress(getProgress()
124+
.next(maxLength/pat.length()));
124125
}
125126
} catch (PatternSyntaxException pse) {
126127
for (MatchWord w : allWords)

app/src/main/java/com/phikal/regex/games/match/MutMatchTask.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import com.phikal.regex.games.Game;
66
import com.phikal.regex.models.Progress;
77

8+
import static com.phikal.regex.Util.*;
9+
810
public class MutMatchTask extends SimpleMatchTask {
911

1012
private static final double GAMMA = (1 - Math.sqrt(5)) / 2 + 1;
1113

1214
private String mutateOn = null;
1315

14-
public MutMatchTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
16+
MutMatchTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
1517
super(ctx, g, p, pc);
1618
}
1719

app/src/main/java/com/phikal/regex/games/match/SimpleMatchTask.java

+13-16
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
import com.phikal.regex.games.Game;
66
import com.phikal.regex.models.Progress;
77

8-
import java.security.SecureRandom;
8+
import java.io.Serializable;
99
import java.util.ArrayList;
1010
import java.util.Collections;
1111
import java.util.HashSet;
1212
import java.util.LinkedList;
1313
import java.util.List;
14-
import java.util.Random;
1514
import java.util.Set;
1615

17-
public class SimpleMatchTask extends MatchTask {
16+
import static com.phikal.regex.Util.*;
17+
18+
public class SimpleMatchTask extends MatchTask implements Serializable {
1819

19-
final static Random rnd = new SecureRandom(); // because why not?
2020
final static int MAX_LENGTH = 12;
2121
final static Character[] CHARS;
2222

@@ -34,30 +34,27 @@ public class SimpleMatchTask extends MatchTask {
3434
}
3535

3636
private List<MatchWord>
37-
toMatch,
38-
notToMatch;
37+
toMatch = new LinkedList<>(),
38+
notToMatch = new LinkedList<>();
3939

40-
private Set<String> words;
40+
private transient Set<String> words = new HashSet<>();
4141

42-
public SimpleMatchTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
42+
SimpleMatchTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
4343
super(ctx, g, p, pc);
4444

45-
toMatch = new LinkedList<>();
46-
notToMatch = new LinkedList<>();
47-
words = new HashSet<>();
48-
49-
int max = getProgress().getMaxTasks() + 1;
45+
int max = (int) (Math.pow(getProgress().getDifficutly(),3)+
46+
Math.sqrt(getProgress().getRound()+1));
5047
int i = 0;
5148
do {
5249
toMatch.add(new MatchWord(randString(), true));
5350
i++;
54-
} while ((i / max) * (i / max) > rnd.nextDouble());
51+
} while ((i / max) * (i / max) < rnd.nextDouble());
5552

5653
i = 0;
5754
do {
5855
notToMatch.add(new MatchWord(randString(), false));
5956
i++;
60-
} while ((i / max) * (i / max) > rnd.nextDouble());
57+
} while ((i / max) * (i / max) < rnd.nextDouble());
6158
}
6259

6360
@Override
@@ -74,7 +71,7 @@ String randString() {
7471

7572
for (; ; ) {
7673
StringBuilder b = new StringBuilder();
77-
for (int i = 0; i < len; i++)
74+
for (int i = 0; i < len * rnd.nextDouble() + 1; i++)
7875
b.append(CHARS[rnd.nextInt(range)]);
7976
if (words.contains(b.toString()))
8077
continue;

app/src/main/java/com/phikal/regex/games/match/WordTask.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44

5+
import com.phikal.regex.R;
56
import com.phikal.regex.games.Game;
67
import com.phikal.regex.models.Progress;
78

@@ -13,12 +14,14 @@
1314
import java.util.List;
1415
import java.util.zip.GZIPInputStream;
1516

17+
import static com.phikal.regex.Util.*;
18+
1619
public class WordTask extends SimpleMatchTask {
1720

1821
static private List<String> words = null;
1922
static private int request = 0;
2023

21-
public WordTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
24+
WordTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
2225
super(ctx, g, p, pc);
2326
}
2427

@@ -28,7 +31,7 @@ String randString() {
2831
try {
2932
words = new ArrayList<>(8711); // current length
3033
BufferedReader bis = new BufferedReader(new InputStreamReader(new GZIPInputStream(
31-
getContext().getAssets().open("words.gz"))));
34+
getContext().getResources().openRawResource(R.raw.words))));
3235
for (String line; (line = bis.readLine()) != null; )
3336
words.add(line);
3437
Collections.shuffle(words, rnd);

app/src/main/java/com/phikal/regex/models/Task.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class Task implements Serializable {
1111
private final Progress p;
1212
private final Game g;
1313
private final Progress.ProgressCallback pc;
14-
private final Context ctx;
14+
private transient final Context ctx;
1515

1616
public Task(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
1717
this.ctx = ctx;

gradlew

100755100644
File mode changed.

gradlew.bat

100644100755
File mode changed.

0 commit comments

Comments
 (0)