2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
8
import flash.utils.ByteArray;
10
import words.PermutationIterator;
12
class WordTest extends ui.StageLayout
14
var tfEntry : ui.EditText;
15
var dict : words.Dictionary;
16
var encoder : words.Encoder;
17
var boardFactory : words.WordBoardFactory;
24
encoder = new words.Encoder_EN();
25
boardFactory = words.WordBoardFactory.withSizeLang( MatPoint.at( 4, 4 ), encoder );
27
tfEntry = ui.EditText.singleLine();
28
tfEntry.text = "hello";
29
layout.add( tfEntry );
32
ui.Button.plain( ui.Action.bind( onLookup ), "Lookup Word" )
35
ui.Button.plain( ui.Action.bind( onAnagram ), "Lookup Anagrams" )
38
ui.Button.plain( ui.Action.bind( onDumpBoardDice ), "Dump Board Dice" )
41
ui.Button.plain( ui.Action.bind( onCreateBoard ), "Create Board" )
44
ui.Button.plain( ui.Action.bind( onAnagramBoard ), "Anagram Board" )
47
ui.Button.plain( ui.Action.bind( onSolveBoard ), "Solve Provided Board" )
50
system.Loader.urlBinary(
52
ui.Action.bind1( onBinaryLoaded, null )
60
trace( "No dictionary available yet." );
64
var enc = encoder.encode( tfEntry.text );
65
trace( "Encoded: " + enc );
66
trace( "Lookup: " + encoder.decode( enc ) ); //what actually will be looked up
68
var value = dict.lookup( tfEntry.text );
70
trace( "Not Found / Continues" );
71
else if ( value == -2 )
72
trace( "Not Found / Terminal" );
74
trace( "Value: " + value );
77
function onDumpBoardDice()
79
trace( boardFactory.getDiceStack() );
82
function onCreateBoard()
84
trace( boardFactory.createBoard() );
87
function onAnagramBoard()
89
var b = boardFactory.createBoard();
91
anagram( words.Anagram.withMatrix( b, dict ) );
95
* NOTE: This test function does not respect time limits in scripts (like in Flash)
96
* and will likely timeout on long strings. A proper function would need to reschedule
97
* itself and quasi as a thread
101
anagram( words.Anagram.withString( tfEntry.text, dict ) );
104
function anagram( ana : words.Anagram )
106
var start = haxe.Timer.stamp();
110
if( !ana.step( 1000 ) )
112
trace( "Complete." );
116
trace( "Step: " + step++ );
117
} while( (haxe.Timer.stamp() - start) < 5 ); //limit time for demo purposes (Flash also has limit)
120
var all = new Array<String>();
121
for( key in ana.found.keys() )
123
var level = ana.found.get( key );
124
trace( key + " => " + level );
127
//collect all simple words
128
if( level <= 2 && key.length >= 3 )
131
trace( "Total Count: " + count );
133
all.sort( function( x, y ) { return x.length - y.length; } );
140
function onBinaryLoaded( binary : ByteArray )
142
trace( "Loaded: " + binary.bytesAvailable );
143
dict = words.Dictionary.withByteArray( binary, encoder );
146
function onSolveBoard()
148
var letters = tfEntry.text.split( "," );
149
ASSERT( letters.length == 16 );
151
var mat = mathx.Matrix.create( 4, 4, "" );
152
for( i in 0...(mat.maxLinearIndex()+1) )
154
var mp = mat.fromLinearIndex( i );
155
mat.set( mp.x, mp.y, letters[i] );
158
var board = words.WordBoard.withMatrix( mat );
160
anagram( words.Anagram.withMatrix( board, dict ) );
163
static public function main()
165
ui.StageLayout.setup( WordTest );
168
define(`IsVerticalLayout',`')
169
include(`ui/MixinLayout.ihx')
b'\\ No newline at end of file'