-
Notifications
You must be signed in to change notification settings - Fork 0
/
halma.h
101 lines (85 loc) · 2.25 KB
/
halma.h
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
//https://stackoverflow.com/questions/40063080/casting-an-array-of-c-structs-to-a-numpy-array
// class SeekTreeC(ct.Structure):
// _fields_=[("board",ct.POINTER(ct.c_uint8)),
// ("w",ct.c_uint8), #width of board
// ("real_data",ct.POINTER(ct.c_double)),
// ("cmplx_data",ct.POINTER(ct.cmplx))]
//
//
// class SeekNodeC(ct.Structure):
// _fields_=[("seekTree",ct.POINTER(SeekTreeC)),
// ("armyIdx",ct.c_uint8),
// ("arr_len",ct.c_int),
// ("real_data",ct.POINTER(ct.c_double)),
// ]
//
// #ct.c_func.restype=info
// #ret_val=ct.c_func()
// #data=np.ctypeslib.as_array(ret_val.contents.real_data,shape=(info.contents.arr_len,))
typedef struct InfoC {
uint16 *armies;
uint8 *armiesLbl;
uint8 numArmies; //1..6
uint8 lenArmy; //default is 10=1+2+3+4
uint8 *board;
float *weightmaps;
uint8 *distmap;
uint8 w; //width of board, weightmap, distmap etc.
} InfoC;
typedef struct SeekManC { // one move of one man
uint8 manIdx; //0..9
uint16 dstPos;
float quality;
//uint16 sumDMap;
//uint16 maxDiff; ... and other stats possible
} SeekManC;
typedef struct SeekArmyC { // all moves on one army
uint8 armyIdx;
SeekManC moves[128]; //array of all moves of this army,
//range is about 20-50 possible moves
uint8 lenUsedMoves;
} SeekArmyC;
typedef struct SeekTreeC{
float bestQuality;
uint8 bestIdx;
} SeekTreeC;
SeekTreeRoot(uint8 depth)
{
SeekTreeC st;
st.bestQuality=0.f;
SeekArmyC sa;
SeekMoves(&sa);
EvalMoves(&sa);
ReduceMoves(&sa);
for(mvIdx=0;mvIdx<sa.lenUsedMoves;mvIdx++)
{
Move(sa.moves[mvIdx])
SeekTree(st,mvIdx,depth)
UndoMove(sa.moves[mvIdx])
}
}
SeekTree(SeekTreeC* st,rootMvIdx,depth)
{
SeekArmyC sa;
SeekMoves(&sa);
EvalMoves(&sa);
ReduceMoves(&sa);
for(mvIdx=0;mvIdx<sa.lenUsedMoves;mvIdx++)
{
if (sa.moves[mvIdx].quality>st->bestTreeMove)
{
st->bestTreeMove=sa.moves[mvIdx].quality;
st->bestIdx=rootMvIdx;
}
}
if(depth>0) // and not winning move found
{
for(mvIdx=0;mvIdx<sa.lenUsedMoves;mvIdx++)
{
Move(sa.moves[mvIdx])
SeekTree(st,rootMvIdx,depth-1)
UndoMove(sa.moves[mvIdx])
}
}
return;
}