Started implementing in state.cpp. Added State::positionPoint(). It
compiles, but is not tested at all. Added some methods in state.h (but did not implement them, apparently).
This commit is contained in:
parent
eef0ecc952
commit
1228a70cb5
@ -17,7 +17,12 @@ class Settings
|
||||
|
||||
public:
|
||||
Settings( void );
|
||||
|
||||
point getUL( void );
|
||||
point getUR( void );
|
||||
point getBL( void );
|
||||
point getBR( void );
|
||||
int getWhiteTreshold( void );
|
||||
int getBlackTreshold( void );
|
||||
|
||||
private:
|
||||
//upper left, upper right etc...
|
||||
|
@ -1,13 +1,47 @@
|
||||
#include "state.h"
|
||||
#include <malloc.h>
|
||||
|
||||
int State::size = 19;
|
||||
|
||||
State::State( void )
|
||||
{
|
||||
//does nothing yet
|
||||
board = (type*)malloc(sizeof(type) * size * size);
|
||||
}
|
||||
|
||||
State generateState (SDL_Surface *board)
|
||||
State State::generateState (SDL_Surface *boardImg, Settings settings)
|
||||
{
|
||||
|
||||
State state;
|
||||
int i, j, x, y, r, sum;
|
||||
point p;
|
||||
r = 20;
|
||||
for (i = 0; i < size; i++) {
|
||||
for (j = 0; j < size; j++) {
|
||||
p = positionPoint(i, j, settings);
|
||||
for (y = p.y-r; y < p.y+r; y++) {
|
||||
for (x = p.x-r; x < p.x+r; x++) {
|
||||
uint32_t px = PX(boardImg, x, y);
|
||||
sum += PXR(px) + PXG(px) + PXB(px);
|
||||
}
|
||||
}
|
||||
type t = BOARD;
|
||||
if (sum < settings.getBlackTreshold()) t = BLACK;
|
||||
if (sum > settings.getWhiteTreshold()) t = WHITE;
|
||||
PX_(state.board, i, j, size, size) = t;
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
point State::positionPoint(int i, int j, Settings s)
|
||||
{
|
||||
point ul = s.getUL(), ur = s.getUR(), bl = s.getBL(), br = s.getBR();
|
||||
point topp, botp, pp;
|
||||
topp.x = ul.x + (i*(ur.x-ul.x))/size;
|
||||
topp.y = ul.y + (i*(ur.y-ul.y))/size;
|
||||
botp.x = bl.x + (i*(br.x-bl.x))/size;
|
||||
botp.y = bl.y + (i*(br.y-bl.y))/size;
|
||||
pp.x = topp.x + (j*(botp.x-topp.x))/size;
|
||||
pp.y = topp.y + (j*(botp.y-topp.y))/size;
|
||||
return pp;
|
||||
}
|
||||
|
||||
|
15
lib/state.h
15
lib/state.h
@ -5,10 +5,18 @@
|
||||
#include <SDL/SDL.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// get pixel/something in array p of size w*h
|
||||
#define PX_(p, x, y, w, h) ((p)[(x)+(y)*(w)])
|
||||
// get pixel in SDL_Surface i
|
||||
#define PX(i,x,y) (PX_((uint32_t*)(i)->pixels, (x), (y), (i)->w, (i)->h))
|
||||
// get color components of pixel value. should probably be done in a nicer way
|
||||
#define PXR(px) ((px) & 0xff)
|
||||
#define PXG(px) (((px) & 0xff00) >> 8)
|
||||
#define PXB(px) (((px) & 0xff0000) >> 16)
|
||||
// iterate over SDL_Surface s with variables x, y
|
||||
#define iter_pixels(s,x,y) for (x = 0; x < s->w; x++) for (y = 0; y < s->h; y++)
|
||||
|
||||
|
||||
/**
|
||||
* Describes the current state of a go board.
|
||||
*/
|
||||
@ -28,7 +36,14 @@ class State
|
||||
|
||||
|
||||
private:
|
||||
/*
|
||||
* Get the image point corresponding to board position (i, j) using
|
||||
* settings s.
|
||||
*/
|
||||
static point positionPoint(int i, int j, Settings s);
|
||||
|
||||
static int size;
|
||||
type *board; // array describing the board situation
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user