2929
3030public class BotScreen implements Screen {
3131 final Golf game ;
32+
3233 Stage stage ;
33- Physics engine ;
34- Ball ball ;
34+
35+ private Course course ;
36+ private Ball ball ;
3537
3638 TextButton genetic ;
3739 TextButton random ;
@@ -42,12 +44,14 @@ public class BotScreen implements Screen {
4244 OrthographicCamera cam ;
4345 Texture background ;
4446
45- public BotScreen (final Golf game ) {
47+ public BotScreen (final Golf game , Course course , Ball ball ) {
4648 this .game = game ;
49+ this .course = course ;
50+ this .ball = ball ;
4751 stage = new Stage ();
4852 Gdx .input .setInputProcessor (stage );
4953 Skin skin = new Skin (Gdx .files .internal ("uiskin.json" ));
50- genetic = new TextButton ("Genetic Bot " , skin );
54+ genetic = new TextButton (" GeneticBot " , skin );
5155 random = new TextButton ("Random Bot" , skin );
5256 martijn = new TextButton ("Bot Martijn" , skin );
5357 dum = new TextButton ("Dumb Bot" , skin );
@@ -87,132 +91,113 @@ public BotScreen(final Golf game) {
8791 class GeneticBotListener extends ChangeListener {
8892 final Golf game ;
8993 private Screen screen ;
94+ private Course course ;
95+ private Ball ball ;
9096
91- public GeneticBotListener (final Golf game , Screen screen ) {
97+ public GeneticBotListener (final Golf game , Screen screen , Course course , Ball ball ) {
9298 this .game = game ;
9399 this .screen = screen ;
100+ this .course = course ;
101+ this .ball = ball ;
94102 }
95103
96104 @ Override
97105 public void changed (ChangeEvent event , Actor actor ) {
98-
99- String formula = "0.1 * x + 0.3 * x ^ 2 + 0.2 * y" ;
100- double [] start = new double []{4 , 3 };
101- double [] goal = new double []{0 , 1 };
102- Function function = new Function (formula );
103- Computable [][] functions = new Computable [1 ][1 ];
104- functions [0 ][0 ] = function ;
105- Course course = new Course (functions , 9.81 , 0.95 , 80 , start , goal , 0.5 );
106106 genetic .setTouchable (Touchable .disabled );
107107 random .setTouchable (Touchable .disabled );
108108 martijn .setTouchable (Touchable .disabled );
109109 dum .setTouchable (Touchable .disabled );
110110 back .setTouchable (Touchable .disabled );
111111 Bot genBot = new GeneticBot (course , ball );
112- this .game .setScreen (new CourseScreen (this .game , course , new Ball ( 40 ) , genBot ));
112+ this .game .setScreen (new CourseScreen (this .game , this . course , this . ball , genBot ));
113113 this .screen .dispose ();
114114 }
115115
116116 }
117- genetic .addListener (new GeneticBotListener (game , this ));
117+ genetic .addListener (new GeneticBotListener (game , this , this . course , this . ball ));
118118
119119 class RandomBotListener extends ChangeListener {
120120 final Golf game ;
121121 private Screen screen ;
122+ private Course course ;
123+ private Ball ball ;
122124
123- public RandomBotListener (final Golf game , Screen screen ) {
125+ public RandomBotListener (final Golf game , Screen screen , Course course , Ball ball ) {
124126 this .game = game ;
125127 this .screen = screen ;
128+ this .course = course ;
129+ this .ball = ball ;
126130 }
127131
128132 @ Override
129133 public void changed (ChangeEvent event , Actor actor ) {
130-
131- String formula = "0.1 * x + 0.3 * x ^ 2 + 0.2 * y" ;
132- double [] start = new double []{4 , 3 };
133- double [] goal = new double []{0 , 1 };
134- Function function = new Function (formula );
135- Computable [][] functions = new Computable [1 ][1 ];
136- functions [0 ][0 ] = function ;
137- Course course = new Course (functions , 9.81 , 0.95 , 80 , start , goal , 0.5 );
138134 genetic .setTouchable (Touchable .disabled );
139135 random .setTouchable (Touchable .disabled );
140136 martijn .setTouchable (Touchable .disabled );
141137 dum .setTouchable (Touchable .disabled );
142138 back .setTouchable (Touchable .disabled );
143- Ball ball = new Ball (40 );
144-
145- Bot ranBot = new RandomBot (course , engine , ball );
146- this .game .setScreen (new CourseScreen (this .game , course , new Ball (40 ), ranBot ));
139+ Bot ranBot = new RandomBot (course , ball );
140+ this .game .setScreen (new CourseScreen (this .game , this .course , this .ball , ranBot ));
147141 this .screen .dispose ();
148142 }
149143
150144 }
151- random .addListener (new RandomBotListener (game , this ));
145+ random .addListener (new RandomBotListener (game , this , this . course , this . ball ));
152146
153147 class MartijnListener extends ChangeListener {
154148 final Golf game ;
155149 private Screen screen ;
150+ private Course course ;
151+ private Ball ball ;
156152
157- public MartijnListener (final Golf game , Screen screen ) {
153+ public MartijnListener (final Golf game , Screen screen , Course course , Ball ball ) {
158154 this .game = game ;
159155 this .screen = screen ;
156+ this .course = course ;
157+ this .ball = ball ;
160158 }
161159
162160 @ Override
163161 public void changed (ChangeEvent event , Actor actor ) {
164-
165- String formula = "0.1 * x + 0.3 * x ^ 2 + 0.2 * y" ;
166- double [] start = new double []{4 , 3 };
167- double [] goal = new double []{0 , 1 };
168- Function function = new Function (formula );
169- Computable [][] functions = new Computable [1 ][1 ];
170- functions [0 ][0 ] = function ;
171- Course course = new Course (functions , 9.81 , 0.95 , 80 , start , goal , 0.5 );
172162 genetic .setTouchable (Touchable .disabled );
173163 random .setTouchable (Touchable .disabled );
174164 martijn .setTouchable (Touchable .disabled );
175165 dum .setTouchable (Touchable .disabled );
176166 back .setTouchable (Touchable .disabled );
177167 Bot genBot = new GeneticBot (course , ball );
178- this .game .setScreen (new CourseScreen (this .game , course , new Ball ( 40 ) , genBot ));
168+ this .game .setScreen (new CourseScreen (this .game , this . course , this . ball , genBot ));
179169 this .screen .dispose ();
180170 }
181171
182172 }
183- martijn .addListener (new MartijnListener (game , this ));
173+ martijn .addListener (new MartijnListener (game , this , this . course , this . ball ));
184174 class DumBotListener extends ChangeListener {
185175 final Golf game ;
186176 private Screen screen ;
177+ private Course course ;
178+ private Ball ball ;
187179
188- public DumBotListener (final Golf game , Screen screen ) {
180+ public DumBotListener (final Golf game , Screen screen , Course course , Ball ball ) {
189181 this .game = game ;
190182 this .screen = screen ;
183+ this .course = course ;
184+ this .ball = ball ;
191185 }
192186
193187 @ Override
194188 public void changed (ChangeEvent event , Actor actor ) {
195-
196- String formula = "0.1 * x + 0.3 * x ^ 2 + 0.2 * y" ;
197- double [] start = new double []{4 , 3 };
198- double [] goal = new double []{0 , 1 };
199- Function function = new Function (formula );
200- Computable [][] functions = new Computable [1 ][1 ];
201- functions [0 ][0 ] = function ;
202- Course course = new Course (functions , 9.81 , 0.95 , 80 , start , goal , 0.5 );
203189 genetic .setTouchable (Touchable .disabled );
204190 random .setTouchable (Touchable .disabled );
205191 martijn .setTouchable (Touchable .disabled );
206192 dum .setTouchable (Touchable .disabled );
207193 back .setTouchable (Touchable .disabled );
208- Ball ball = new Ball (40 );
209194 Bot dumBot = new DumBot (course , ball );
210- this .game .setScreen (new CourseScreen (this .game , course , ball , dumBot ));
195+ this .game .setScreen (new CourseScreen (this .game , this . course , this . ball , dumBot ));
211196 this .screen .dispose ();
212197 }
213198
214199 }
215- dum .addListener (new DumBotListener (game , this ));
200+ dum .addListener (new DumBotListener (game , this , this . course , this . ball ));
216201 class BackListener extends ChangeListener {
217202 final Golf game ;
218203 private Screen screen ;
0 commit comments