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.
12
* A class for producing word boards.
14
class WordBoardFactory
17
var encoder : Encoder;
19
function new( size : MatPoint, encoder : Encoder )
22
this.encoder = encoder;
25
static public function withSizeLang( mp : MatPoint, enc : Encoder )
27
return new WordBoardFactory( mp, enc );
31
* Produces an array of sequences which would be all the sides
32
* of the dice in a game set. It does not indicate to which each
33
* dice the value belongs, and I don't think we need this now, we
34
* can live with the occassional invalid/very difficult game.
36
public function getDiceStack() : Array<String>
38
var dist = encoder.getSeqDistrib().copy();
43
total += TypeConvert.asInt( seq[1] );
44
seq[2] = 1; //guarantee one each
47
var numDice = size.x * size.y;
48
var numSides = numDice * 6;
50
//distrib quickly, each guaranteed one, and then the rest based on
51
//assignment, butin order, all 2 first, then 3, etc... (if any remain)
52
var sidesRemain = numSides - dist.length; //less guaranteed amounts
54
while( sidesRemain > 0 )
58
var expect = Math.round( seq[1] / total * numSides );
63
if( sidesRemain == 0 )
69
var stack = new Array<String>();
71
for( i in 0...seq[2] )
77
public function createBoard() : WordBoard
79
var mat = Matrix.create( size.x, size.y, "" );
80
var dice = ArrayUtil.shuffle( getDiceStack() );
81
for( i in 0...(mat.maxLinearIndex()+1) )
83
var mp = mat.fromLinearIndex( i );
84
mat.set( mp.x, mp.y, dice[i] );
87
return WordBoard.withMatrix( mat );