-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.h
More file actions
134 lines (115 loc) · 2.51 KB
/
tools.h
File metadata and controls
134 lines (115 loc) · 2.51 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* File: tools.h
*
* Created on 15. Februar 2015, 20:41
*/
#ifndef TOOLS_H
#define TOOLS_H
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include "constants.h"
#include "globals.h"
namespace Tools
{
/**
* Find last set bit
*
* @param bb
* @return
*/
int bitScanReverse(u_int64_t bb);
/**
* Print the formated field.
*
* @param field
*/
void printField(u_int64_t field);
/**
* Returns the bitfield pos of the coordinate pos
*
* @param x
* @param y
* @return
*/
int getPos(int x, int y);
/**
* Returns the coordinate pos of the bitfield pos
* @param pos
* @return
*/
int* getPos(int pos);//{x,y}
/**
* Check if a bitfield pos is not >= 60
*
* @param pos
* @return
*/
bool isInvalid(int pos);
/**
* Generates a field of reachable positions from pos in constant time.
*
* @param pos
* @param used
* @return
*/
u_int64_t genMoveField(int pos, u_int64_t used);
/**
* Find first set bit
*
* @param bb
* @return
*/
int bitScanForward(u_int64_t bb);
/**
* Counts the number of set bits in constant time.
*
* @param x
* @return
*/
int popCount (u_int64_t x);
/**
* Counts the number of set bits in O(n).
*
* @param x
* @return
*/
int fastPopCount (u_int64_t x);
/**
* Returns an array of set bits based on popCount.
*
* @param x
* @param length the length of the resulting array
* @return
*/
int* bitScan (u_int64_t x, int *length);
/**
* Returns an array of set bits based on fastPopCount.
*
* @param x
* @param length the length of the resulting array
* @return
*/
int* fastBitScan (u_int64_t x, int *length);
/**
* Returns a field of reachable positions for both players.
* It is based on genMoveField and adds them.
*
* @param field
* @param posa1
* @param posa2
* @param posa3
* @param posa4
* @param posb1
* @param posb2
* @param posb3
* @param posb4
* @param resulta
* @param resultb
*/
void getReachableFields(u_int64_t field,
int posa1, int posa2, int posa3, int posa4,
int posb1, int posb2, int posb3, int posb4,
u_int64_t *resulta, u_int64_t *resultb);
}
#endif /* TOOLS_H */