File: levels.c

package info (click to toggle)
phalanx 12-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 664 kB
  • ctags: 504
  • sloc: ansic: 6,094; makefile: 76; sh: 50
file content (132 lines) | stat: -rw-r--r-- 2,465 bytes parent folder | download
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
#include "phalanx.h"

long T1, T2;

long Time = 600*100;
long Otim = 600*100;


long ptime(void)
{
	if( Flag.easy ) return Nodes;
	else
	if( Flag.cpu ) return clock()*100/CLOCKS_PER_SEC;
	else
	{
		struct timeval t;
		gettimeofday( &t, NULL );
		return t.tv_sec*100 + t.tv_usec/10000;
	}
}



void l_level( int moves, int minutes, int increment )
{
	printf(
	 "level: %i moves in %i minutes, increment %i seconds\n",
	 moves, minutes, increment );
	if( Flag.easy )
	{
		if( moves == 0 ) moves = 80;
		Flag.level = fixedtime;
		Flag.centiseconds =
			(increment+minutes*60/moves)
			* (150-Flag.easy);
		if( Flag.post )
		printf( "setting avg time to %i cs\n", Flag.centiseconds );
	}
	else
	{
		Flag.level = timecontrol;
		Flag.moves = moves;
		Flag.centiseconds = minutes*6000;
		Flag.increment = increment;
	}
}



void l_startsearch(void)
{
	int moves;
	T1 = ptime();

	switch( Flag.level )
	{
	case timecontrol:
		if( Flag.moves > 0 ) moves = 2*Flag.moves;
		else
		{
			moves = Counter +
			        (G[Counter].mtrl+G[Counter].xmtrl)/800;
			if( Counter < 120 )
				moves += 60 - Counter/4;
			else	moves += 30;
		}

		if( Flag.increment == 0 ) T2 = 0;
		else
		if( Time/Flag.increment >= 1600 )
			T2 = Flag.increment * 60;
		else
		if( Time/Flag.increment <= 400 )
			T2 = Flag.increment * 10;
		else
			T2 = Flag.increment * (Time/Flag.increment/8-20)/3;

		if( Flag.post && T2 )
		printf( "    -> increment adds %g s to soft time limit\n",
			((float)T2) / (float)100 );

		T2 += Time / ( moves - Counter%moves + 4 );

		if( Flag.ponder ) T2 += T2/8;

		if( Flag.post )
		printf( "    -> soft time limit %g s\n",
			((float)T2) / (float)100 );

		/*** Now, set up the hard limit ***/
		Flag.centiseconds = Time - 500; /* 5 seconds to flag! move! */
		if( Flag.increment < 10 )
			Flag.centiseconds -= 10*Time/(20-Flag.increment);
		if( Flag.centiseconds < 10 ) Flag.centiseconds = 10;

		if( Flag.post )
		printf( "    -> hard time limit %g s\n",
			((float)Flag.centiseconds) / (float)100 );

	break;
	case averagetime:
		T2 = Flag.centiseconds/3;
	break;
	default: break;
	}

	if( T2 < 1 ) T2 = 1;
}



int l_iterate(void)
{
	if( Flag.level == fixeddepth )
	{
		return ( Depth < Flag.depth );
	}
	else
	if( Flag.level == averagetime || Flag.level == timecontrol )
	{
		long t = ptime();
		switch( EasyMove )
		{
			case 1:  return ( t <= T1 + T2/3 );
			case 2:  return ( t <= T1 + T2/6 );
			default: return ( t <= T1 + T2 );
		}
	}
	else
	return 1;
}