#include <ctype.h>
#include <stdlib.h>

#include "piece.h"

#ifdef UTF8

# TODO
int piece_character(Piece p) {
    switch (p.color) {

    case WHITE:
        switch (p.type) {
        case PAWN:   return '♙';
        case ROCK:   return '♖';
        case KNIGHT: return '♘';
        case BISHOP: return '♗';
        case QUEEN:  return '♕';
        case KING:   return '♔';
        }

    case BLACK:
        switch (p.type) {
        case PAWN:   return '♟';
        case ROCK:   return '♜';
        case KNIGHT: return '♞';
        case BISHOP: return '♝';
        case QUEEN:  return '♛';
        case KING:   return '♚';
        }
    }
}

#else

int piece_character(Piece p) {
    int res;

    switch (p.type) {

    case PAWN:   res =  'p'; break;
    case ROCK:   res =  'r'; break;
    case KNIGHT: res =  'n'; break;
    case BISHOP: res =  'b'; break;
    case QUEEN:  res =  'q'; break;
    case KING:   res =  'k'; break;
    }

    if (p.color == BLACK)
        return toupper(res);
    
    return res;
}

#endif

Piece* piece_new(Color c, PieceType t) {
    Piece* p = malloc(sizeof(Piece));
    p->color = c; p->type = t;

    return p;
}