DroidFish: Made it easier to disable the opening book.

This commit is contained in:
Peter Osterlund 2017-09-23 23:52:49 +02:00
parent 6b5e42dfd9
commit 45a8bee002
5 changed files with 64 additions and 11 deletions

View File

@ -76,6 +76,7 @@ you are not actively using the program.\
<string name="edit_move_counters">Edit Move Counters</string>
<string name="internal_book">&lt;Internal Book&gt;</string>
<string name="eco_book">&lt;ECO Book&gt;</string>
<string name="no_book">&lt;No Book&gt;</string>
<string name="select_opening_book_file">Select opening book file</string>
<string name="select_chess_engine">Select Chess Engine</string>
<string name="select_pgn_file">Open PGN file</string>

View File

@ -1472,7 +1472,7 @@ public class DroidFish extends Activity
BookOptions options = new BookOptions(bookOptions);
if (options.filename.isEmpty())
options.filename = "internal:";
if (!options.filename.equals("internal:") && !options.filename.equals("eco:")) {
if (!options.filename.endsWith(":")) {
String sep = File.separator;
if (!options.filename.startsWith(sep)) {
File extDir = Environment.getExternalStorageDirectory();
@ -2512,13 +2512,17 @@ public class DroidFish extends Activity
}
});
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++)
items[i] = fileNames[i];
items[numFiles] = getString(R.string.internal_book);
items[numFiles + 1] = getString(R.string.eco_book);
final CharSequence[] finalItems = items;
int defaultItem = bookOptions.filename.equals("eco:") ? numFiles + 1 : numFiles;
items[numFiles + 2] = getString(R.string.no_book);
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++) {
if (bookOptions.filename.equals(items[i])) {
defaultItem = i;
@ -2535,8 +2539,10 @@ public class DroidFish extends Activity
bookFile = "internal:";
else if (item == numFiles + 1)
bookFile = "eco:";
else if (item == numFiles + 2)
bookFile = "nobook:";
else
bookFile = finalItems[item].toString();
bookFile = items[item].toString();
editor.putString("bookFile", bookFile);
editor.commit();
bookOptions.filename = bookFile;
@ -2707,14 +2713,13 @@ public class DroidFish extends Activity
break;
}
}
CharSequence[] items = new CharSequence[numFiles + 1];
final CharSequence[] items = new CharSequence[numFiles + 1];
for (int i = 0; i < numFiles; i++)
items[i] = fileNames[i];
items[numFiles] = getString(R.string.new_file);
final CharSequence[] finalItems = items;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
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) {
String pgnFile;
if (item >= numFiles) {

View File

@ -53,6 +53,7 @@ public final class DroidBook {
private IOpeningBook externalBook = new NullBook();
private IOpeningBook ecoBook = new EcoBook();
private IOpeningBook internalBook = new InternalBook();
private IOpeningBook noBook = new NoBook();
private BookOptions options = null;
private static final DroidBook INSTANCE = new DroidBook();
@ -78,6 +79,7 @@ public final class DroidBook {
externalBook.setOptions(options);
ecoBook.setOptions(options);
internalBook.setOptions(options);
noBook.setOptions(options);
}
/** Return a random book move for a position, or null if out of book. */
@ -179,6 +181,8 @@ public final class DroidBook {
return externalBook;
} else if (ecoBook.enabled()) {
return ecoBook;
} else if (noBook.enabled()) {
return noBook;
} else {
return internalBook;
}

View 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;
}
}

View File

@ -31,11 +31,11 @@ class NullBook implements IOpeningBook {
}
@Override
public ArrayList<BookEntry> getBookEntries(Position pos) {
return null;
public void setOptions(BookOptions options) {
}
@Override
public void setOptions(BookOptions options) {
public ArrayList<BookEntry> getBookEntries(Position pos) {
return null;
}
}