summaryrefslogtreecommitdiffstats
path: root/kmines/solver/test.cpp
blob: ed42da700efe8f0f69b428f70383d3d92045b2ed (plain)
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
/** A program to test advisory library */

#include "bfield.h"
#include "headerP.h"

#define W 10
#define H 10

int main(int argc, char *argv[])
{
    long seed = (argc<2 ? time(0) : atoi(argv[1]));
    cout << "seed = " << seed << endl;

	BaseField f(seed);
    f.reset(W, H, 10);

    KRandomSequence random(seed);
    Coord c(random.getLong(W), random.getLong(H));
    f.doReveal(c, 0, 0);

	CoordSet sp;
	AdviseFull::ProbabilityMap pm;

	AdviseFast::FactSet facts(&f);
	AdviseFull::adviseFull(&facts, &sp, &pm);

	float pic[H][W];

	for(uint i=0; i<H; ++i)
        for(uint j=0; j<W; ++j) pic[i][j] = -1; // unknown
    pic[c.second][c.first] = -(int)f.nbMinesAround(c);

	AdviseFull::ProbabilityMap::iterator pmi;
	for(pmi = pm.begin(); pmi != pm.end(); ++pmi)
		pic[pmi->second.second][pmi->second.first] = pmi->first;

    TQString s;
	for(uint i=0;i<H;++i) {
		for(uint j=0;j<W;++j)
            cout << s.sprintf("%+.02f ", pic[i][j]).latin1();
        cout << endl;
	}

	return 0;
}