1
1
package com .gipf .client .game .player .bot ;
2
2
3
- import java .util .ArrayList ;
4
-
5
3
import com .gipf .client .game .GameController ;
6
- import com .gipf .client .game .player .bot .action .Action ;
7
- import com .gipf .client .game .player .bot .tree .Node ;
8
- import com .gipf .client .game .player .bot .tree .Tree ;
9
4
import com .gipf .client .player .bot .algorithm .Algorithm ;
10
- import com .gipf .client .player .bot .evaluation .Evaluator ;
5
+ import com .gipf .client .player .bot .generator .GameState ;
6
+ import com .gipf .client .utils .Point ;
11
7
12
8
public class BotMoveThread extends Thread {
13
9
14
- public static long runTime = 0 ;
15
- public static int runs = 0 ;
16
-
17
10
private GameController gameController ;
18
- private Evaluator evaluator ;
19
11
private Algorithm algorithm ;
20
12
private Bot bot ;
21
13
22
- public BotMoveThread (Bot bot , GameController gameController , Algorithm algorithm , Evaluator evaluator ) {
14
+ public BotMoveThread (Bot bot , GameController gameController , Algorithm algorithm ) {
23
15
this .gameController = gameController ;
24
16
this .algorithm = algorithm ;
25
- this .evaluator = evaluator ;
26
17
this .bot = bot ;
27
18
}
28
19
29
20
public void run () {
30
- long start = System .nanoTime ();
21
+ long start = System .currentTimeMillis ();
31
22
32
23
// computation for move
33
- Node root = this .evaluator .evalToNode (this .gameController .getController ().getGame ().copy ());
34
- this .bot .getGenerator ().generateTreeLayer (root , this .bot , this .bot .getLogic (), true );
35
- ArrayList <Action > actions = this .algorithm .calculateBestActions (new Tree (root ), this .bot );
36
-
37
- ArrayList <Node > search = new Tree (root ).bfSearch (root );
38
-
39
- if (actions .size () > 1 ) {
40
- ArrayList <Action > upcomingActions = new ArrayList <Action >();
41
- for (int i = 1 ; i < actions .size (); i ++)
42
- upcomingActions .add (actions .get (i ));
43
- this .bot .setUpcomingActions (upcomingActions );
44
- }
45
-
46
- long end = System .nanoTime ();
47
-
48
- runTime += end - start ;
49
- runs ++;
50
- System .out .println ("average runtime: " + runTime / (runs * 1000000.0 ) + "ms at " + runs + " runs, current run time: " + (end - start ) + " miliseconds = " + ((end - start ) / 1000000.0 ) + " ms with " + search .size () + " nodes." );
51
- System .out .println ();
52
- // used for making bots move visible
53
- if (end - start < 166700000 ) {
54
- try {
55
- Thread .sleep ((166700000 - (end - start )) / 1000000 );
56
- } catch (InterruptedException e ) {
57
- Thread .currentThread ().interrupt ();
58
- }
59
- }
24
+ Point [] move = this .algorithm .returnBestMove (new GameState (this .gameController .getController ().getGame (), null , null ), this .bot );
25
+
26
+ long end = System .currentTimeMillis ();
27
+
28
+ // used for making bots move visible
29
+ // if (end - start < 500) {
30
+ // try {
31
+ // Thread.sleep(500 - (end - start));
32
+ // } catch (InterruptedException e) {
33
+ // Thread.currentThread().interrupt();
34
+ // }
35
+ // }
60
36
61
37
// do move
62
- this .gameController .getController ().getGamePanel ().getButtons ()[actions .get (0 ).getPoints ()[0 ].getX ()][actions .get (0 ).getPoints ()[0 ].getY ()].doClick ();
63
-
64
- // visualise direction choice
65
- if (end - start < 250000000 ) {
66
- try {
67
- Thread .sleep ((250000000 - (end - start )) / 1000000 );
68
- } catch (InterruptedException e ) {
69
- Thread .currentThread ().interrupt ();
70
- }
71
- }
72
- this .gameController .getController ().getGamePanel ().getButtons ()[actions .get (0 ).getPoints ()[1 ].getX ()][actions .get (0 ).getPoints ()[1 ].getY ()].doClick ();
38
+ this .gameController .getController ().getGamePanel ().getButtons ()[move [0 ].getX ()][move [0 ].getY ()].doClick ();
39
+ this .gameController .getController ().getGamePanel ().getButtons ()[move [1 ].getX ()][move [1 ].getY ()].doClick ();
73
40
74
41
// ending thread
75
42
try {
@@ -79,4 +46,4 @@ public void run() {
79
46
Thread .currentThread ().interrupt ();
80
47
}
81
48
}
82
- }
49
+ }
0 commit comments