Source code: com/eireneh/bible/control/map/BrownianRule.java
1
2 package com.eireneh.bible.control.map;
3
4 import java.util.Random;
5
6 /**
7 * BrownianRule.
8 *
9 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
10 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
11 * Distribution Licence:<br />
12 * Project B is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General Public License,
14 * version 2 as published by the Free Software Foundation.<br />
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.<br />
19 * The License is available on the internet
20 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
21 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
23 * The copyright to this program is held by it's authors.
24 * </font></td></tr></table>
25 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
26 * @see docs.Licence
27 * @author Joe Walker
28 * @version D0.I0.T0
29 */
30 public class BrownianRule extends AbstractRule
31 {
32 /**
33 * Basic Constructor - How much is it possible to a node to move
34 * randomly each turn. a heat of 1.0 means that any node could move
35 * roughly anywhere across the board each turn, so a heat of 0.001
36 * is probably more useful.
37 * To be precise the heat is the standard deviation in a gaussian
38 * distribution.
39 * @param heat The maximum random jiggle each turn
40 */
41 public BrownianRule(float heat)
42 {
43 this.heat = heat;
44 }
45
46 /**
47 * Specify where it would like a node to be positioned in space.
48 * Rules return an array of positions where the average of them
49 * specifies the real desired position. So to specify a single place
50 * simply return an array of one position. The positions are added
51 * to the results from all Rules so to specify a single position
52 * more strongly, return an array conataining that position many
53 * times.
54 * @param map The Map to select a node from
55 * @param ord The ordinal number (1 - 31104) of the verse
56 * @return An array of desired positions.
57 */
58 public Position[] getDesiredPosition(Map map, int ord)
59 {
60 if (scale == 0)
61 return new Position[] { };
62
63 float[] pos = map.getPosition(ord);
64
65 for (int i=0; i<pos.length; i++)
66 {
67 pos[i] += (float) (rand.nextGaussian() * heat);
68 }
69
70 return scale(new Position(pos));
71 }
72
73 /** The max random jiggle */
74 private float heat;
75
76 /** The random number generator */
77 private Random rand = new Random();
78 }