-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyMove.java
More file actions
107 lines (97 loc) · 2.54 KB
/
Copy pathMyMove.java
File metadata and controls
107 lines (97 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.ggp.base.util.statemachine.Move;
import org.ggp.base.util.statemachine.exceptions.GoalDefinitionException;
import org.ggp.base.util.statemachine.exceptions.MoveDefinitionException;
import org.ggp.base.util.statemachine.exceptions.TransitionDefinitionException;
public class MyMove {
public MyMove(Move move, StoredState parent) throws MoveDefinitionException
{
mLegalMove = move;
mParent = parent;
mChildren = null;
mVisitCount = 0;
}
public Move getMove()
{
return mLegalMove;
}
public StoredState getState()
{
return mParent;
}
public List<EnemyMove> getEnemyMoveList() throws MoveDefinitionException
{
if (mChildren == null)
{
calculateEnemyMoves();
}
return mChildren;
}
public int getVisitCount()
{
return mVisitCount;
}
public int sendProbe(int[] depth) throws GoalDefinitionException, TransitionDefinitionException,
MoveDefinitionException
{
++mVisitCount;
List<Integer> choices = null;
int choosenMove = 0;
// Des mouvements n'ont jamais été explorés
if (mChildren == null)
{
calculateEnemyMoves();
}
if (mVisitCount < mChildren.size())
{
choices = new ArrayList<>(mChildren.size() - mVisitCount);
for (int i = 0; i < mChildren.size(); ++i)
{
if (mChildren.get(i).getVisitCount() == 0)
{
choices.add(i);
}
}
choosenMove = choices.get(new Random().nextInt(choices.size()));
}
// Tous les mouvements ont été explorés au moins une fois
else
{
choosenMove = new Random().nextInt(mChildren.size());
}
++depth[0];
return mChildren.get(choosenMove).getNextState().sendProbe(depth);
}
public int getWorstScore() throws TransitionDefinitionException, MoveDefinitionException
{
int score = 100;
if(mChildren == null)
{
return 50;
}
for (EnemyMove enemyMove : mChildren)
{
if (enemyMove.getNextState().getScore() < score)
{
score = enemyMove.getNextState().getScore();
}
}
return score;
}
private void calculateEnemyMoves() throws MoveDefinitionException
{
List<List<Move>> legalJointMoves = mParent.getMachine().getLegalJointMoves(mParent.getState(),
mParent.getRole(), mLegalMove);
mChildren = new ArrayList<EnemyMove>(legalJointMoves.size());
for (List<Move> joinMove : legalJointMoves)
{
mChildren.add(new EnemyMove(joinMove, this));
}
}
private Move mLegalMove;
private StoredState mParent;
private List<EnemyMove> mChildren;
private int mVisitCount;
}