calculate value in advance with a bitshift for some performance gain
[aco.git] / Element.java
blob06fa56ee82556eb84ffee29ebdb0860ca1c8fba1
1 import java.util.Random;
2 import java.lang.Math;
4 class Element {
6 static int PosX = 0, PosY = 0, ValS = 0, ValP = 0;
8 Element() {
9 PosX = 0;
10 PosY = 0;
11 ValS = 0;
12 ValP = 0;
15 public int getPosX () {
16 return PosX;
19 public int getPosY () {
20 return PosY;
23 public int getValS () {
24 return ValS + ValP;
27 public int getValP () {
28 return ValP;
31 public void changePos ( int px, int py ) {
32 PosX = px;
33 PosY = py;
36 public void changeVal ( int vs, int vp ) {
37 ValS = vs;
38 ValP = vp;
41 public void move () {
43 Random rand = new Random();
45 int newPosX = PosX + (int)Math.round(rand.nextGaussian())
46 % Global.stepWidth;
48 rand.setSeed(rand.nextLong());
50 int newPosY = PosY + (int)Math.round(rand.nextGaussian())
51 % Global.stepWidth;
53 if ( newPosX < Global.boundX && newPosX >= 0)
54 PosX = newPosX;
55 if ( newPosY < Global.boundY && newPosY >= 0)
56 PosY = newPosY;