|
|
|
|
@ -11,8 +11,7 @@
|
|
|
|
|
#include <chess/bitboard.h>
|
|
|
|
|
#include "evaluate.h"
|
|
|
|
|
|
|
|
|
|
//#define START_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
|
|
|
|
#define START_FEN "rnbqkbnr/PPppppPP/8/8/8/8/ppPPPPpp/RNBQKBNR w KQkq - 0 1"
|
|
|
|
|
#define START_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
|
|
|
|
|
|
|
|
|
struct drawData_t {
|
|
|
|
|
RsvgHandle **piecesSvg;
|
|
|
|
|
@ -30,24 +29,21 @@ struct drawData_t {
|
|
|
|
|
const uint_least8_t PROMOTION_PIECES[] = {QUEEN, KNIGHT, BISHOP, ROOK};
|
|
|
|
|
|
|
|
|
|
static uint_least8_t pieceToSvgI(struct piece_t piece) {
|
|
|
|
|
return piece.color == WHITE ? piece.type | 8 : piece.type;
|
|
|
|
|
return piece.color == WHITE ? PIECES_LENGTH + piece.type : piece.type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void drawPiece(struct drawData_t *ctx, cairo_t *cr, uint_least8_t field, struct piece_t piece) {
|
|
|
|
|
const uint_least8_t file = field % BOARD_SIZE;
|
|
|
|
|
const uint_least8_t rank = field / BOARD_SIZE;
|
|
|
|
|
const RsvgRectangle rect = {ctx->xOffset + file * ctx->fieldSize, ctx->yOffset + rank * ctx->fieldSize, ctx->fieldSize, ctx->fieldSize};\
|
|
|
|
|
const RsvgRectangle rect = {ctx->xOffset + getFile(field)* ctx->fieldSize,
|
|
|
|
|
ctx->yOffset + getRank(field) * ctx->fieldSize, ctx->fieldSize, ctx->fieldSize};
|
|
|
|
|
rsvg_handle_render_document(ctx->piecesSvg[pieceToSvgI(piece)], cr, &rect, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void selectCircle(cairo_t *cr, const struct drawData_t *drawData, uint_least8_t field, double radius) {
|
|
|
|
|
uint_least8_t file = field % BOARD_SIZE;
|
|
|
|
|
uint_least8_t rank = field / BOARD_SIZE;
|
|
|
|
|
double xOffset = drawData->xOffset;
|
|
|
|
|
double yOffset = drawData->yOffset;
|
|
|
|
|
double fieldSize = drawData->fieldSize;
|
|
|
|
|
cairo_arc(cr, xOffset + (file + 0.5) * fieldSize, yOffset + (rank + 0.5) * fieldSize, radius, 0, 2 * M_PI);
|
|
|
|
|
static void selectCircle(cairo_t *cr, const struct drawData_t *drawData, uint_least8_t field, double radius) {
|
|
|
|
|
const double xOffset = drawData->xOffset;
|
|
|
|
|
const double yOffset = drawData->yOffset;
|
|
|
|
|
const double fieldSize = drawData->fieldSize;
|
|
|
|
|
cairo_arc(cr, xOffset + (getFile(field) + 0.5) * fieldSize, yOffset + (getRank(field) + 0.5) * fieldSize, radius, 0, 2 * M_PI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct gameState_t userMove(struct gameState_t gameState, struct move_t move) {
|
|
|
|
|
@ -67,6 +63,13 @@ static uint_least8_t promotionUiPos(uint_least8_t dst, bool color) {
|
|
|
|
|
return uiPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void drawRetangle(cairo_t *cr, struct drawData_t *drawData, uint_least8_t field, double width) {
|
|
|
|
|
const double fieldSize = drawData->fieldSize;
|
|
|
|
|
cairo_rectangle(cr, drawData->xOffset + getFile(field) * fieldSize,
|
|
|
|
|
drawData->yOffset + getRank(field) * fieldSize, width, fieldSize);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void draw_event(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer data) {
|
|
|
|
|
const double fieldSize = (double)(width < height ? width : height) / BOARD_SIZE;
|
|
|
|
|
const double xOffset = (width - fieldSize * BOARD_SIZE) / 2;
|
|
|
|
|
@ -81,10 +84,9 @@ static void draw_event(GtkDrawingArea *area, cairo_t *cr, int width, int height,
|
|
|
|
|
for(uint_least8_t file = 0; file < BOARD_SIZE; ++file) {
|
|
|
|
|
for(uint_least8_t rank = 0; rank < BOARD_SIZE; ++rank) {
|
|
|
|
|
const uint_least8_t field = rank * BOARD_SIZE + file;
|
|
|
|
|
cairo_rectangle(cr, xOffset + file * fieldSize, yOffset + rank * fieldSize, fieldSize, fieldSize);
|
|
|
|
|
if((file + rank) & 1) cairo_set_source_rgb(cr, 0.46274, 0.5882, 0.3373);
|
|
|
|
|
else cairo_set_source_rgb(cr, 0.9333, 0.9333, 0.8235);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
drawRetangle(cr, drawData, field, fieldSize);
|
|
|
|
|
if(bitboardGetAllPieces(board, field)) {
|
|
|
|
|
const struct piece_t piece = pieceAtField(board, rank * BOARD_SIZE + file);
|
|
|
|
|
drawPiece(drawData, cr, field, piece);
|
|
|
|
|
@ -104,8 +106,7 @@ static void draw_event(GtkDrawingArea *area, cairo_t *cr, int width, int height,
|
|
|
|
|
if(drawData->selectDst != NOT_SELECTED) {
|
|
|
|
|
uint_least8_t uiPos = promotionUiPos(drawData->selectDst, gameState->color);
|
|
|
|
|
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
|
|
|
|
|
cairo_rectangle(cr, xOffset + uiPos * fieldSize, yOffset, 4 * fieldSize, fieldSize);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
drawRetangle(cr, drawData, uiPos, 4 * fieldSize);
|
|
|
|
|
for(uint_least8_t i = 0; i < LENGTH(PROMOTION_PIECES); ++i) {
|
|
|
|
|
const struct piece_t piece = {PROMOTION_PIECES[i], gameState->color};
|
|
|
|
|
drawPiece(drawData, cr, uiPos + i, piece);
|
|
|
|
|
@ -186,7 +187,7 @@ static void on_click(GtkGestureClick *gesture, int n_press, double x, double y,
|
|
|
|
|
|
|
|
|
|
static void app_activate(GApplication *app, gpointer data) {
|
|
|
|
|
GtkWindow *window = GTK_WINDOW(gtk_window_new());
|
|
|
|
|
static RsvgHandle *piecesSvg[16];
|
|
|
|
|
static RsvgHandle *piecesSvg[2 * PIECES_LENGTH];
|
|
|
|
|
static uint_least64_t board[BITBOARD_LENGTH];
|
|
|
|
|
static struct gameState_t gameState;
|
|
|
|
|
gameState = newGameState(board, START_FEN);
|
|
|
|
|
|