mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-12 09:02:41 +01:00
DroidFish: Made it easier to disable the opening book.
This commit is contained in:
@@ -76,6 +76,7 @@ you are not actively using the program.\
|
|||||||
<string name="edit_move_counters">Edit Move Counters</string>
|
<string name="edit_move_counters">Edit Move Counters</string>
|
||||||
<string name="internal_book"><Internal Book></string>
|
<string name="internal_book"><Internal Book></string>
|
||||||
<string name="eco_book"><ECO Book></string>
|
<string name="eco_book"><ECO Book></string>
|
||||||
|
<string name="no_book"><No Book></string>
|
||||||
<string name="select_opening_book_file">Select opening book file</string>
|
<string name="select_opening_book_file">Select opening book file</string>
|
||||||
<string name="select_chess_engine">Select Chess Engine</string>
|
<string name="select_chess_engine">Select Chess Engine</string>
|
||||||
<string name="select_pgn_file">Open PGN file</string>
|
<string name="select_pgn_file">Open PGN file</string>
|
||||||
|
|||||||
@@ -1472,7 +1472,7 @@ public class DroidFish extends Activity
|
|||||||
BookOptions options = new BookOptions(bookOptions);
|
BookOptions options = new BookOptions(bookOptions);
|
||||||
if (options.filename.isEmpty())
|
if (options.filename.isEmpty())
|
||||||
options.filename = "internal:";
|
options.filename = "internal:";
|
||||||
if (!options.filename.equals("internal:") && !options.filename.equals("eco:")) {
|
if (!options.filename.endsWith(":")) {
|
||||||
String sep = File.separator;
|
String sep = File.separator;
|
||||||
if (!options.filename.startsWith(sep)) {
|
if (!options.filename.startsWith(sep)) {
|
||||||
File extDir = Environment.getExternalStorageDirectory();
|
File extDir = Environment.getExternalStorageDirectory();
|
||||||
@@ -2512,13 +2512,17 @@ public class DroidFish extends Activity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
final int numFiles = fileNames.length;
|
final int numFiles = fileNames.length;
|
||||||
CharSequence[] items = new CharSequence[numFiles + 2];
|
final CharSequence[] items = new CharSequence[numFiles + 3];
|
||||||
for (int i = 0; i < numFiles; i++)
|
for (int i = 0; i < numFiles; i++)
|
||||||
items[i] = fileNames[i];
|
items[i] = fileNames[i];
|
||||||
items[numFiles] = getString(R.string.internal_book);
|
items[numFiles] = getString(R.string.internal_book);
|
||||||
items[numFiles + 1] = getString(R.string.eco_book);
|
items[numFiles + 1] = getString(R.string.eco_book);
|
||||||
final CharSequence[] finalItems = items;
|
items[numFiles + 2] = getString(R.string.no_book);
|
||||||
int defaultItem = bookOptions.filename.equals("eco:") ? numFiles + 1 : numFiles;
|
int defaultItem = numFiles;
|
||||||
|
if (bookOptions.filename.equals("eco:"))
|
||||||
|
defaultItem = numFiles + 1;
|
||||||
|
else if (bookOptions.filename.equals("nobook:"))
|
||||||
|
defaultItem = numFiles + 2;
|
||||||
for (int i = 0; i < numFiles; i++) {
|
for (int i = 0; i < numFiles; i++) {
|
||||||
if (bookOptions.filename.equals(items[i])) {
|
if (bookOptions.filename.equals(items[i])) {
|
||||||
defaultItem = i;
|
defaultItem = i;
|
||||||
@@ -2535,8 +2539,10 @@ public class DroidFish extends Activity
|
|||||||
bookFile = "internal:";
|
bookFile = "internal:";
|
||||||
else if (item == numFiles + 1)
|
else if (item == numFiles + 1)
|
||||||
bookFile = "eco:";
|
bookFile = "eco:";
|
||||||
|
else if (item == numFiles + 2)
|
||||||
|
bookFile = "nobook:";
|
||||||
else
|
else
|
||||||
bookFile = finalItems[item].toString();
|
bookFile = items[item].toString();
|
||||||
editor.putString("bookFile", bookFile);
|
editor.putString("bookFile", bookFile);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
bookOptions.filename = bookFile;
|
bookOptions.filename = bookFile;
|
||||||
@@ -2707,14 +2713,13 @@ public class DroidFish extends Activity
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CharSequence[] items = new CharSequence[numFiles + 1];
|
final CharSequence[] items = new CharSequence[numFiles + 1];
|
||||||
for (int i = 0; i < numFiles; i++)
|
for (int i = 0; i < numFiles; i++)
|
||||||
items[i] = fileNames[i];
|
items[i] = fileNames[i];
|
||||||
items[numFiles] = getString(R.string.new_file);
|
items[numFiles] = getString(R.string.new_file);
|
||||||
final CharSequence[] finalItems = items;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(R.string.select_pgn_file_save);
|
builder.setTitle(R.string.select_pgn_file_save);
|
||||||
builder.setSingleChoiceItems(finalItems, defaultItem, new DialogInterface.OnClickListener() {
|
builder.setSingleChoiceItems(items, defaultItem, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
String pgnFile;
|
String pgnFile;
|
||||||
if (item >= numFiles) {
|
if (item >= numFiles) {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public final class DroidBook {
|
|||||||
private IOpeningBook externalBook = new NullBook();
|
private IOpeningBook externalBook = new NullBook();
|
||||||
private IOpeningBook ecoBook = new EcoBook();
|
private IOpeningBook ecoBook = new EcoBook();
|
||||||
private IOpeningBook internalBook = new InternalBook();
|
private IOpeningBook internalBook = new InternalBook();
|
||||||
|
private IOpeningBook noBook = new NoBook();
|
||||||
private BookOptions options = null;
|
private BookOptions options = null;
|
||||||
|
|
||||||
private static final DroidBook INSTANCE = new DroidBook();
|
private static final DroidBook INSTANCE = new DroidBook();
|
||||||
@@ -78,6 +79,7 @@ public final class DroidBook {
|
|||||||
externalBook.setOptions(options);
|
externalBook.setOptions(options);
|
||||||
ecoBook.setOptions(options);
|
ecoBook.setOptions(options);
|
||||||
internalBook.setOptions(options);
|
internalBook.setOptions(options);
|
||||||
|
noBook.setOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return a random book move for a position, or null if out of book. */
|
/** Return a random book move for a position, or null if out of book. */
|
||||||
@@ -179,6 +181,8 @@ public final class DroidBook {
|
|||||||
return externalBook;
|
return externalBook;
|
||||||
} else if (ecoBook.enabled()) {
|
} else if (ecoBook.enabled()) {
|
||||||
return ecoBook;
|
return ecoBook;
|
||||||
|
} else if (noBook.enabled()) {
|
||||||
|
return noBook;
|
||||||
} else {
|
} else {
|
||||||
return internalBook;
|
return internalBook;
|
||||||
}
|
}
|
||||||
|
|||||||
43
DroidFish/src/org/petero/droidfish/book/NoBook.java
Normal file
43
DroidFish/src/org/petero/droidfish/book/NoBook.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
DroidFish - An Android chess program.
|
||||||
|
Copyright (C) 2017 Peter Österlund, peterosterlund2@gmail.com
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.petero.droidfish.book;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.petero.droidfish.book.DroidBook.BookEntry;
|
||||||
|
import org.petero.droidfish.gamelogic.Position;
|
||||||
|
|
||||||
|
class NoBook implements IOpeningBook {
|
||||||
|
private boolean enabled = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOptions(BookOptions options) {
|
||||||
|
enabled = options.filename.equals("nobook:");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<BookEntry> getBookEntries(Position pos) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,11 +31,11 @@ class NullBook implements IOpeningBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<BookEntry> getBookEntries(Position pos) {
|
public void setOptions(BookOptions options) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOptions(BookOptions options) {
|
public ArrayList<BookEntry> getBookEntries(Position pos) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user