choose the shortest pattern

Don't assume it's the last as previous code did
This commit is contained in:
Eric House 2020-12-28 14:44:20 -08:00
parent d72142ad40
commit 0c939984f5
2 changed files with 15 additions and 5 deletions

View file

@ -27,7 +27,7 @@
<ul>
<li>Send language code rather than name when checking for
wordlist upgrades</li>
<li>Slightly improve play over Bluetooth</li>
<li>Improve play over Bluetooth (slightly)</li>
<li>Include translations in Brazillian Portuguese, Italian,
Spanish and Turkish (via Weblate)</li>
</ul>

View file

@ -587,11 +587,12 @@ public class DictBrowseDelegate extends DelegateBase
PatDesc[] pats = m_browseState.m_pats;
for ( int ii = 0; ii < pats.length && !pending; ++ii ) {
final PatDesc thisPats = pats[ii];
if ( justFixed == ii ) {
Assert.assertTrueNR( null != fixedTiles );
pats[ii].tilePat = fixedTiles;
} else if ( null == pats[ii].tilePat ) {
String strPat = pats[ii].strPat;
thisPats.tilePat = fixedTiles;
} else if ( null == thisPats.tilePat ) {
String strPat = thisPats.strPat;
if ( null != strPat && 0 < strPat.length() ) {
byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat );
if ( null == choices || 0 == choices.length ) {
@ -603,7 +604,16 @@ public class DictBrowseDelegate extends DelegateBase
pending = true;
} else if ( 1 == choices.length
|| !XwJNI.dict_hasDuplicates( m_dict ) ) {
pats[ii].tilePat = choices[choices.length - 1];
// Pick the shortest option, i.e. when there's a
// choice between using one or several tiles to spell
// something choose one.
thisPats.tilePat = choices[0];
for ( int jj = 1; jj < choices.length; ++jj ) {
byte[] tilePat = choices[jj];
if ( tilePat.length < thisPats.tilePat.length ) {
thisPats.tilePat = tilePat;
}
}
} else {
m_browseState.m_delim = DELIM;
showDialogFragment( DlgID.CHOOSE_TILES, (Object)choices, ii );