Started doing some actual guessing of what's happening on the board. Gui has sliders that adjust thresholds.

This commit is contained in:
2007-02-23 22:28:29 +00:00
parent 7cb6c5f44f
commit f82e141315
10 changed files with 289 additions and 59 deletions

View File

@@ -2,5 +2,6 @@
Settings::Settings( void )
{
colorThreshold[0] = 100;
colorThreshold[1] = 1000;
}

View File

@@ -17,12 +17,20 @@ class Settings
public:
Settings( void );
point getUL( void );
point getUR( void );
point getBL( void );
point getBR( void );
int getWhiteTreshold( void );
int getBlackTreshold( void );
point getUL( void ) { return ul; }
point getUR( void ) { return ur; }
point getBL( void ) { return bl; }
point getBR( void ) { return br; }
void setUL( point p ) { ul = p; }
void setUR( point p ) { ur = p; }
void setBL( point p ) { bl = p; }
void setBR( point p ) { br = p; }
int getWhiteTreshold( void ) { return colorThreshold[WHITE]; }
int getBlackTreshold( void ) { return colorThreshold[BLACK]; }
void setWhiteThreshold( int t) { colorThreshold[WHITE] = t; }
void setBlackThreshold( int t) { colorThreshold[BLACK] = t; }
private:
//upper left, upper right etc...

View File

@@ -1,11 +1,39 @@
#include "state.h"
#include <malloc.h>
#include <stdio.h>
int State::size = 19;
State::State( void )
{
board = (type*)malloc(sizeof(type) * size * size);
board = new type[size * size];
}
State::~State( void )
{
delete[] board;
}
void State::printState( void )
{
int i,j;
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) { //for all points:
switch (board[i*size + j])
{
case BLACK:
printf("B ");
break;
case WHITE:
printf("W ");
break;
case BOARD:
printf("- ");
break;
}
}
printf("\n");
}
printf("\n");
}
State State::generateState (SDL_Surface *boardImg, Settings settings)
@@ -13,22 +41,29 @@ State State::generateState (SDL_Surface *boardImg, Settings settings)
State state;
int i, j, x, y, r, sum;
point p;
r = 20;
r = 10; //what kind of magic number is this?
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
p = positionPoint(i, j, settings);
for (j = 0; j < size; j++) { //for all points:
p = positionPoint(i, j, settings); //retrieve the estimated point
sum = 0;
//TODO: this loop should be placed into its own function!
for (y = p.y-r; y < p.y+r; y++) {
for (x = p.x-r; x < p.x+r; x++) {
for (x = p.x-r; x < p.x+r; x++) { //for -20 to 20 around the point
uint32_t px = PX(boardImg, x, y);
sum += PXR(px) + PXG(px) + PXB(px);
sum += (1024 -PXR(px) - PXG(px) + PXB(px)); //sum up the colors
}
}
sum/=400;
//printf("%d\t", sum);
type t = BOARD;
if (sum < settings.getBlackTreshold()) t = BLACK;
if (sum > settings.getWhiteTreshold()) t = WHITE;
PX_(state.board, i, j, size, size) = t;
}
//printf("\n");
}
//printf("\n");
return state;
}

View File

@@ -29,21 +29,30 @@ class State
* Standard constructor
*/
State( void );
virtual ~State( void );
void setSize(int size) { State::size = size; }
void printState( void );
static State generateState( SDL_Surface *board, Settings settings);
private:
/*
* Get the image point corresponding to board position (i, j) using
* settings s.
*/
static point positionPoint(int i, int j, Settings s);
private:
/**
* The size of the board, e.g. 19x19, 13x13 etc.
*/
static int size;
type *board; // array describing the board situation
/**
* array describing the board situation
*/
type *board;
};