Commit 34abafda authored by PurkkaKoodari's avatar PurkkaKoodari

Add mines exploded as scoring category

parent 961351c3
......@@ -47,6 +47,23 @@
<Space />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/mines"
android:textAppearance="@android:style/TextAppearance.Holo.Widget.TextView" />
<EditText
android:id="@+id/minesBox"
android:layout_height="wrap_content"
android:ems="4"
android:inputType="number" />
<Space />
</TableRow>
<TableRow>
<TextView
......
......@@ -17,6 +17,7 @@
<string name="gained">Gained</string>
<string name="killed">Killed</string>
<string name="letters">Letters</string>
<string name="mines">Mines</string>
<string name="tiles">Tiles</string>
<string name="progress">Progress</string>
<string name="preferwin">Prefer winning moves</string>
......
......@@ -298,20 +298,22 @@ public class BoardActivity extends Activity {
try {
DataInputStream is = new DataInputStream(openFileInput("scoring.dat"));
int letter = is.readInt();
int mine = is.readInt();
int tileGain = is.readInt();
int tileKill = is.readInt();
int progressGain = is.readInt();
int progressKill = is.readInt();
boolean winBonus = is.readBoolean();
is.close();
scoring = new Scoring(letter, tileGain, tileKill, progressGain, progressKill, winBonus);
scoring = new Scoring(letter, mine, tileGain, tileKill, progressGain, progressKill, winBonus);
} catch (FileNotFoundException e) {
scoring = Scoring.DEFAULT;
Log.i("WordbaseHacker", "No previous scoring found, defaulting");
saveScoring();
} catch (IOException e) {
scoring = Scoring.DEFAULT;
Log.e("WordbaseHacker", "Failed to load scoring", e);
Log.e("WordbaseHacker", "Failed to load scoring, defaulting", e);
saveScoring();
}
}
......@@ -319,6 +321,7 @@ public class BoardActivity extends Activity {
try {
DataOutputStream os = new DataOutputStream(openFileOutput("scoring.dat", 0));
os.writeInt(scoring.letter);
os.writeInt(scoring.mine);
os.writeInt(scoring.tileGain);
os.writeInt(scoring.tileKill);
os.writeInt(scoring.progressGain);
......@@ -344,9 +347,9 @@ public class BoardActivity extends Activity {
scoring = currentScoring;
saveScoring();
updateView();
if (scoring.equals(new Scoring(7, 3, 3, 5, 6, false)))
if (scoring.equals(new Scoring(7, 0, 3, 3, 5, 6, false)))
enableDev();
if (scoring.equals(new Scoring(4, 6, 7, 7, 8, false)))
if (scoring.equals(new Scoring(4, 0, 6, 7, 7, 8, false)))
toggleHorst();
}
});
......@@ -367,6 +370,7 @@ public class BoardActivity extends Activity {
public void afterTextChanged(Editable s) {}
};
((EditText) layout.findViewById(R.id.lettersBox)).addTextChangedListener(watcher);
((EditText) layout.findViewById(R.id.minesBox)).addTextChangedListener(watcher);
((EditText) layout.findViewById(R.id.tilesPlrBox)).addTextChangedListener(watcher);
((EditText) layout.findViewById(R.id.tilesOppBox)).addTextChangedListener(watcher);
((EditText) layout.findViewById(R.id.progressPlrBox)).addTextChangedListener(watcher);
......@@ -395,6 +399,7 @@ public class BoardActivity extends Activity {
private void updateFields(View layout) {
((EditText) layout.findViewById(R.id.lettersBox)).setText(Integer.toString(currentScoring.letter));
((EditText) layout.findViewById(R.id.minesBox)).setText(Integer.toString(currentScoring.mine));
((EditText) layout.findViewById(R.id.tilesPlrBox)).setText(Integer.toString(currentScoring.tileGain));
((EditText) layout.findViewById(R.id.tilesOppBox)).setText(Integer.toString(currentScoring.tileKill));
((EditText) layout.findViewById(R.id.progressPlrBox)).setText(Integer.toString(currentScoring.progressGain));
......@@ -407,6 +412,7 @@ public class BoardActivity extends Activity {
return;
try {
int letter = Integer.parseInt(((EditText) layout.findViewById(R.id.lettersBox)).getText().toString());
int mine = Integer.parseInt(((EditText) layout.findViewById(R.id.minesBox)).getText().toString());
int tileGain = Integer.parseInt(((EditText) layout.findViewById(R.id.tilesPlrBox)).getText().toString());
int tileKill = Integer.parseInt(((EditText) layout.findViewById(R.id.tilesOppBox)).getText().toString());
int progressGain = Integer.parseInt(((EditText) layout.findViewById(R.id.progressPlrBox)).getText()
......@@ -414,7 +420,7 @@ public class BoardActivity extends Activity {
int progressKill = Integer.parseInt(((EditText) layout.findViewById(R.id.progressOppBox)).getText()
.toString());
boolean winBonus = ((CheckBox) layout.findViewById(R.id.winBox)).isChecked();
currentScoring = new Scoring(letter, tileGain, tileKill, progressGain, progressKill, winBonus);
currentScoring = new Scoring(letter, mine, tileGain, tileKill, progressGain, progressKill, winBonus);
shown.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
} catch (NumberFormatException e) {
shown.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
......
......@@ -23,7 +23,7 @@ public class Board {
public void score(Possibility pos, boolean flipped) {
Tile[][] newTiles = new Tile[10][13];
int oldPlayer = 0, oldOpponent = 0, oldDistP = 0, oldDistO = 0;
int oldMines = 0, oldPlayer = 0, oldOpponent = 0, oldDistP = 0, oldDistO = 0;
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 13; y++) {
newTiles[x][y] = tiles[x][y];
......@@ -33,6 +33,8 @@ public class Board {
} else if (newTiles[x][y].isSet(Tile.OPPONENT)) {
oldOpponent++;
oldDistO = max(oldDistO, flipped ? y : 12 - y);
} else if (newTiles[x][y].isSet(Tile.MINE | Tile.SUPER_MINE)) {
oldMines++;
}
}
}
......@@ -51,7 +53,7 @@ public class Board {
}
}
int newPlayer = 0, newOpponent = 0, newDistP = 0, newDistO = 0;
int newMines = 0, newPlayer = 0, newOpponent = 0, newDistP = 0, newDistO = 0;
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 13; y++) {
if (newTiles[x][y].isSet(Tile.PLAYER)) {
......@@ -60,11 +62,13 @@ public class Board {
} else if (newTiles[x][y].isSet(Tile.OPPONENT)) {
newOpponent++;
newDistO = max(newDistO, flipped ? y : 12 - y);
} else if (newTiles[x][y].isSet(Tile.MINE | Tile.SUPER_MINE)) {
newMines++;
}
}
}
pos.setScore(new Score(pos.getCoordinates().length, newPlayer - oldPlayer, oldOpponent - newOpponent, newDistP
- oldDistP, oldDistO - newDistO, newDistP == 12));
pos.setScore(new Score(pos.getCoordinates().length, oldMines - newMines, newPlayer - oldPlayer, oldOpponent
- newOpponent, newDistP - oldDistP, oldDistO - newDistO, newDistP == 12));
pos.setResult(new Board(newTiles, words));
}
......
......@@ -2,11 +2,12 @@ package net.pietu1998.wordbasehacker.solver;
public class Score {
public final int wordLength, tilesGained, tilesKilled, progressGained, progressKilled;
public final int wordLength, minesExploded, tilesGained, tilesKilled, progressGained, progressKilled;
public final boolean gameWon;
public Score(int wordLength, int tilesGained, int tilesKilled, int progressGained, int progressKilled, boolean gameWon) {
public Score(int wordLength, int minesExploded, int tilesGained, int tilesKilled, int progressGained, int progressKilled, boolean gameWon) {
this.wordLength = wordLength;
this.minesExploded = minesExploded;
this.tilesGained = tilesGained;
this.tilesKilled = tilesKilled;
this.progressGained = progressGained;
......
......@@ -2,11 +2,12 @@ package net.pietu1998.wordbasehacker.solver;
public class Scoring {
public final int letter, tileGain, tileKill, progressGain, progressKill;
public final int letter, mine, tileGain, tileKill, progressGain, progressKill;
public final boolean winBonus;
public Scoring(int letter, int tileGain, int tileKill, int progressGain, int progressKill, boolean winBonus) {
public Scoring(int letter, int mine, int tileGain, int tileKill, int progressGain, int progressKill, boolean winBonus) {
this.letter = letter;
this.mine = mine;
this.tileGain = tileGain;
this.tileKill = tileKill;
this.progressGain = progressGain;
......@@ -14,11 +15,12 @@ public class Scoring {
this.winBonus = winBonus;
}
public static final Scoring DEFAULT = new Scoring(1, 10, 40, 100, 300, true);
public static final Scoring DEFAULT = new Scoring(1, 0, 10, 40, 100, 300, true);
public int calculateScore(Score score) {
int result = 0;
result += score.wordLength * letter;
result += score.minesExploded * mine;
result += score.tilesGained * tileGain;
result += score.tilesKilled * tileKill;
result += score.progressGained * progressGain;
......@@ -33,7 +35,7 @@ public class Scoring {
if (!(o instanceof Scoring))
return false;
Scoring other = (Scoring) o;
return letter == other.letter && tileGain == other.tileGain && tileKill == other.tileKill
return letter == other.letter && mine == other.mine && tileGain == other.tileGain && tileKill == other.tileKill
&& progressGain == other.progressGain && progressKill == other.progressKill
&& winBonus == other.winBonus;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment