/*
	< DanaSah is a chess engine winboard. >
    Copyright (C) <2012>  <Pedro Castro Elgarresta>
	E-mail <pecastro@msn.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/* Funciones para tener un static exchange evaluator */

/*Includes*/
#include "definiciones.h"
#include "variables.h"
#include "funciones.h"


/*esta función nos permite saber que algunos movimientos son malas capturas, basado en CPW
sustituye de momento a SEE (static exchange evaluator)*/
int malaCaptura(movimiento mcmov) {

	int recaptura_peon = 0;

	/*Capturas "de igual a igual o de menos a más" (también AxC) son buenas por definición*/
	if (valor_pieza[pieza[mcmov.a]] > valor_pieza[pieza[mcmov.de]] - 50)
		return 0;

    /*Comprobamos si el oponente puede recapturar con un peon*/
	if (color[mcmov.de] == BLANCO) {
		if (mcmov.a - 9 >= 0 && COLUMNA(mcmov.a) != 0 && pieza[mcmov.a - 9] == PEON && color[mcmov.a - 9] == NEGRO)
			recaptura_peon = 1;
		else if (mcmov.a - 7 >= 0 && COLUMNA(mcmov.a) != 7 && pieza[mcmov.a - 7] == PEON && color[mcmov.a - 7] == NEGRO)
				recaptura_peon = 1;
	}
	else {
		if (mcmov.a + 7 < 64 && COLUMNA(mcmov.a) != 0 && pieza[mcmov.a + 7] == PEON && color[mcmov.a + 7] == BLANCO)
			recaptura_peon = 1;
		else if (mcmov.a + 9 < 64 && COLUMNA(mcmov.a) != 7 && pieza[mcmov.a + 9] == PEON && color[mcmov.a + 9] == BLANCO)
			recaptura_peon = 1;
	}
	
	if (recaptura_peon)
		return 1;

	return 0;
}
