-
Notifications
You must be signed in to change notification settings - Fork 1
/
g2why.c
151 lines (141 loc) · 3.9 KB
/
g2why.c
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* Copyright 1984-2007 David Fotland. All rights reserved.
* This source code is being distributed under a nondisclosure
* agreement. Do not distribute it without written permission
* from David Fotland. Do not show it to anyone not party to the
* nondisclosure. Maintain good security on any computers or
* disks containing this source code.
*/
#include "g2hd.h"
#include "g2proto.h"
#include "g2rldef.h"
#include "g2look.pr"
#ifdef UCT
#include "uct.h"
#endif
#include <stdio.h>
#include <string.h>
#define NUMANUM 20
/* TRUE if move was considered */
int considr(sqr_t s) {
return(scoreval[s] != BIGNUM);
}
void markagroup(group_t g, char *c) {
int ptr;
for (ptr = grpieces[g]; ptr != -1; ptr = mvnext[ptr])
outstone(mvs[ptr],c);
}
#ifndef SMALLCODE
extern int randomval[];
void
printreasons(sqr_t s, int c)
{
list_t ptr, ptr2, tmplist=EOL;
int flag, oflag = 0, newreas, i;
sqr_t s2;
group_t mgroup;
char buf[200],buf2[200],*pt,tmp[40];
int armynums[NUMANUM];
#ifdef G2DEBUGOUTPUT
int p;
#endif
/* unhighlight(); */
for (s2 = 0; s2 < boardsquare; ++s2) {
if (considr(s2)) {
histone(s2);
oflag++;
}
}
for (i = 0; i < NUMANUM; ++i)
armynums[i] = -1;
if (s == PASS) {
outerr(getstring(25,74));
outerr("\n");
return;
}
#ifdef UCT
if (last_search_level == UCTLEVEL) {
sprintf(buf, "After %d pseudorandom games, this move had the highest winning percentage.\n", uct_get_playout_count());
outerr(buf);
if (stratreasons[s] == EOL)
return;
}
#endif
ptr = stratreasons[s];
if (ptr == EOL) {
outerr(getstring(25,75));
outerr("\n");
}
else {
for (ptr = stratreasons[s]; ptr != EOL; ptr = link[ptr]) {
if (list[tmplist] != list[ptr])
adflist(list[ptr],&tmplist);
}
#ifdef G2DEBUGOUTPUT
if (debug) {
if (!considr(s))
outerr("Move not considered.\n");
sprintf(buf,"Guess is %d (with %d random). obaval %d, sumstrat %d, stratvalue %d, savepat %d ",
stratguess[0][s], randomval[s], obaval, sumstrat(s, c), stratvalue[s], stratpatvalue[s]);
outerr(buf);
sprintf(buf,"Move value %d (%d points).\n",scoreval[s],scoreval[s]/50);
outerr(buf);
}
#endif
flag = FALSE;
for (ptr = tmplist; ptr != EOL; ptr = link[ptr]) {
newreas = TRUE;
if (!debug && /* eliminate duplicates */
!(rules[strat[list[ptr]].reason].attack&(ATTACK|DEFEND)))
for (ptr2 = tmplist; ptr2 != ptr; ptr2 = link[ptr2])
if (strat[list[ptr2]].reason == strat[list[ptr]].reason)
newreas = FALSE;
if (!newreas)
continue;
if (strat[list[ptr]].goodrule || debug || last_search_level == UCTLEVEL) {
strcpy(buf,getstring(WHYPAGE,strat[list[ptr]].reason));
if (rules[strat[list[ptr]].reason].attack&(ATTACK|DEFEND|ATKVAL1|DEFVAL1|NAMEGROUP)) {
mgroup = S_GROUP(strat[list[ptr]].param);
for (i = 0; i < NUMANUM-1; ++i)
if (armynums[i] == mgroup || armynums[i] == -1)break;
armynums[i] = mgroup;
pt = (char *)memchr(buf,'%',strlen(buf));
if (pt != NULL)
*pt = 'A'+i;
sprintf(tmp,"%c",'A'+i);
markagroup(mgroup,tmp);
}
if (!debug) {
outerr(buf);
outerr("\n");
}
else {
#ifdef G2DEBUGOUTPUT
p = strat[list[ptr]].param;
if (rules[strat[list[ptr]].reason].attack & PATTERNMV)
p = strat[list[ptr]].pattern;
sprintf(buf2,"%d %d %d+%d G%d[%d] %d - %s",
strat[list[ptr]].goodrule,
strat[list[ptr]].reason,
strat[list[ptr]].value,
rules[strat[list[ptr]].reason].value,
strat[list[ptr]].guess,
rules[strat[list[ptr]].reason].guess,
p,
buf);
#endif
outerr(buf2);
outerr("\n");
}
flag = TRUE;
}
}
if (!flag)
outerr(getstring(25,76));
}
killist(&tmplist);
if (oflag > 1) {
outerr(getstring(27,50));
outerr("\n");
}
}
#endif /* SMALLCODE */