Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
112 pmbaty 1
/*
2
    Protector -- a UCI chess engine
3
 
4
    Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com)
5
 
6
    This program is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
19
*/
20
 
21
#ifndef _coordination_h_
22
#define _coordination_h_
23
 
24
#include "position.h"
25
#include "movegeneration.h"
26
 
27
typedef enum
28
{
29
   TASKTYPE_BEST_MOVE,
30
   TASKTYPE_TEST_BEST_MOVE,
31
   TASKTYPE_MATE_IN_N,
32
   TASKTYPE_TEST_MATE_IN_N
33
} TaskType;
34
 
35
typedef struct
36
{
37
   TaskType type;               /* the type of task to be performed */
38
   Variation *variation;        /* the variation to be examined */
39
   int numberOfMoves;           /* mateproblems: the number of moves */
40
   Movelist solutions;          /* mateproblems: the known solutions */
41
 
42
   Movelist calculatedSolutions;        /* the calculated solutions */
43
   Move bestMove;               /* the calculated best move */
44
 
45
   UINT64 nodes;                /* the number of nodes calculated */
46
} SearchTask;
47
 
48
/**
49
 * Set the number of threads to be used.
50
 *
51
 * @var numThreads the number of threads to be used
52
 * @return the effective number of threads that will be used
53
 */
54
int setNumberOfThreads(int numThreads);
55
int getNumberOfThreads();
56
 
57
/**
58
 * Set the size of the hashtable.
59
 *
60
 * @var size the size of the hashtable in MB
61
 */
62
void setHashtableSizeInMb(unsigned int size);
63
 
64
/**
65
 * Lock out either the gui or the search thread.
66
 */
67
void getGuiSearchMutex(void);
68
 
69
/**
70
 * Release the gui/search thread lock.
71
 */
72
void releaseGuiSearchMutex(void);
73
 
74
/**
75
 * Schedule the specified task as the next task to be calculated.
76
 */
77
void scheduleTask(SearchTask * task);
78
 
79
/**
80
 * Start the timer of the specified task.
81
 */
82
void startTimerThread(SearchTask * task);
83
 
84
/**
85
 * Get the elapsed time of the current search.
86
 */
87
long getElapsedTime();
88
 
89
/**
90
 * Get the hashtable shared by the search threads.
91
 */
92
Hashtable *getSharedHashtable();
93
 
94
/**
95
 * Signal an abortion of the current search and copy
96
 * the current variation to 'variation'.
97
 */
98
void prepareSearchAbort(void);
99
 
100
/**
101
 * Unset the ponder mode for the current search.
102
 */
103
void unsetPonderMode(void);
104
 
105
/**
106
 * Wait for the current search to terminate.
107
 */
108
void waitForSearchTermination(void);
109
 
110
/**
111
 * Set the timelimits for the current search task.
112
 */
113
void setTimeLimit(unsigned long timeTarget, unsigned long timeLimit);
114
 
115
/**
116
 * Schedule the specified task as the next task to be calculated.
117
 * Then wait until the task is completed.
118
 */
119
void completeTask(SearchTask * task);
120
 
121
/**
122
 * Get the variation object of the current search task.
123
 */
124
Variation *getCurrentVariation(void);
125
 
126
/**
127
 * Get the number of nodes calculated by all active threads.
128
 */
129
UINT64 getNodeCount(void);
130
 
131
/**
132
 * Initialize this module.
133
 *
134
 * @return 0 if no errors occurred.
135
 */
136
int initializeModuleCoordination(void);
137
 
138
/**
139
 * Test this module.
140
 *
141
 * @return 0 if all tests succeed.
142
 */
143
int testModuleCoordination(void);
144
 
145
#endif