<commit_before>#include "boardslot.h"
#include "board.h"

BoardSlot::BoardSlot(Player::Who owner, Piece::Type piece)
	: m_piece(piece)
	, m_owner(owner)
{
}

Piece::Type BoardSlot::piece(void) const
{
	return (Piece::Type)m_piece;
}

Player::Who BoardSlot::owner(void) const
{
	return (Player::Who)m_owner;
}

std::vector<Board*> *BoardSlot::validMoves(const Board &b, const Location &loc) const
{
	std::vector<Board*> *moves = new std::vector<Board*>();
	
	switch(m_piece)
	{
		case Piece::Pawn:
			if(m_owner == Player::Player1)
				scanMoves(*moves, b, loc, 0, 1, true, 1);
			else
				scanMoves(*moves, b, loc, 0, -1, true, 1);
			break;
		case Piece::Knight:
			// !@%^ this one
			break;
		case Piece::Bishop:
			// Diags
			scanMoves(*moves, b, loc, 1, 1);
			scanMoves(*moves, b, loc, 1, -1);
			scanMoves(*moves, b, loc, -1, 1);
			scanMoves(*moves, b, loc, -1, -1);

			// Color change
			scanMoves(*moves, b, loc, 1, 0, false, 1);
			scanMoves(*moves, b, loc, -1, 0, false, 1);
			scanMoves(*moves, b, loc, 0, 1, false, 1);
			scanMoves(*moves, b, loc, 0, -1, false, 1);
			break;
		case Piece::Rook:
			// Laterals
			scanMoves(*moves, b, loc, 1, 0);
			scanMoves(*moves, b, loc, -1, 0);
			scanMoves(*moves, b, loc, 0, 1);
			scanMoves(*moves, b, loc, 0, -1);
			break;
		case Piece::Queen:
			// Diags
			scanMoves(*moves, b, loc, 1, 1);
			scanMoves(*moves, b, loc, 1, -1);
			scanMoves(*moves, b, loc, -1, 1);
			scanMoves(*moves, b, loc, -1, -1);
			
			// Laterals
			scanMoves(*moves, b, loc, 1, 0);
			scanMoves(*moves, b, loc, -1, 0);
			scanMoves(*moves, b, loc, 0, 1);
			scanMoves(*moves, b, loc, 0, -1);
			break;
		case Piece::King:
			scanMoves(*moves, b, loc, 1, 0, true, 1);
			scanMoves(*moves, b, loc, -1, 0, true, 1);
			scanMoves(*moves, b, loc, 0, 1, true, 1);
			scanMoves(*moves, b, loc, 0, -1, true, 1);
			break;
	}

	return moves;
}

void BoardSlot::scanMoves(std::vector<Board*> &vals,
                          const Board &b,
                          const Location &origin,
                          int dx,
                          int dy,
                          bool can_capture,
                          int max_cnt) const
{
	scanMoves(vals,
	          b,
	          origin,
	          Location(origin.x() + dx, origin.y() + dy),
	          dx,
	          dy,
	          0,
	          can_capture,
	          max_cnt);
}

void BoardSlot::scanMoves(std::vector<Board*> &vals,
                      const Board &b,
                      const Location &origin,
                      const Location &l,
                      int dx,
                      int dy,
                      int cnt,
                      bool can_capture,
                      int max_cnt) const
{
	const BoardSlot *piece = &b.get(l);
	if(piece->owner() == m_owner)
		return;
	if(piece->owner() == Player::None || can_capture)
	{
		Board *board = new Board(b);
		board->move(origin, l);
		vals.push_back(board);
		if(!can_capture)
		{
			++cnt;
			if(max_cnt && max_cnt > cnt)
				scanMoves(vals,
				          b,
				          origin,
				          Location(l.x()+dx, l.y()+dy),
				          dx,
				          dy,
				          cnt,
				          can_capture,
				          max_cnt);
		}
	}
}


<commit_msg>Added knight moves to boardslot<commit_after>#include "boardslot.h"
#include "board.h"

BoardSlot::BoardSlot(Player::Who owner, Piece::Type piece)
	: m_piece(piece)
	, m_owner(owner)
{
}

Piece::Type BoardSlot::piece(void) const
{
	return (Piece::Type)m_piece;
}

Player::Who BoardSlot::owner(void) const
{
	return (Player::Who)m_owner;
}

std::vector<Board*> *BoardSlot::validMoves(const Board &b, const Location &loc) const
{
	std::vector<Board*> *moves = new std::vector<Board*>();
	
	switch(m_piece)
	{
		case Piece::Pawn:
			if(m_owner == Player::Player1)
				scanMoves(*moves, b, loc, 0, 1, true, 1);
			else
				scanMoves(*moves, b, loc, 0, -1, true, 1);
			break;
		case Piece::Knight:
			scanMoves(*moves, b, loc, 1, 2, true, 1);
			scanMoves(*moves, b, loc, 1, -2, true, 1);
			scanMoves(*moves, b, loc, -1, 2, true, 1);
			scanMoves(*moves, b, loc, -1, -2, true, 1);
			break;
		case Piece::Bishop:
			// Diags
			scanMoves(*moves, b, loc, 1, 1);
			scanMoves(*moves, b, loc, 1, -1);
			scanMoves(*moves, b, loc, -1, 1);
			scanMoves(*moves, b, loc, -1, -1);

			// Color change
			scanMoves(*moves, b, loc, 1, 0, false, 1);
			scanMoves(*moves, b, loc, -1, 0, false, 1);
			scanMoves(*moves, b, loc, 0, 1, false, 1);
			scanMoves(*moves, b, loc, 0, -1, false, 1);
			break;
		case Piece::Rook:
			// Laterals
			scanMoves(*moves, b, loc, 1, 0);
			scanMoves(*moves, b, loc, -1, 0);
			scanMoves(*moves, b, loc, 0, 1);
			scanMoves(*moves, b, loc, 0, -1);
			break;
		case Piece::Queen:
			// Diags
			scanMoves(*moves, b, loc, 1, 1);
			scanMoves(*moves, b, loc, 1, -1);
			scanMoves(*moves, b, loc, -1, 1);
			scanMoves(*moves, b, loc, -1, -1);
			
			// Laterals
			scanMoves(*moves, b, loc, 1, 0);
			scanMoves(*moves, b, loc, -1, 0);
			scanMoves(*moves, b, loc, 0, 1);
			scanMoves(*moves, b, loc, 0, -1);
			break;
		case Piece::King:
			scanMoves(*moves, b, loc, 1, 0, true, 1);
			scanMoves(*moves, b, loc, -1, 0, true, 1);
			scanMoves(*moves, b, loc, 0, 1, true, 1);
			scanMoves(*moves, b, loc, 0, -1, true, 1);
			break;
	}

	return moves;
}

void BoardSlot::scanMoves(std::vector<Board*> &vals,
                          const Board &b,
                          const Location &origin,
                          int dx,
                          int dy,
                          bool can_capture,
                          int max_cnt) const
{
	scanMoves(vals,
	          b,
	          origin,
	          Location(origin.x() + dx, origin.y() + dy),
	          dx,
	          dy,
	          0,
	          can_capture,
	          max_cnt);
}

void BoardSlot::scanMoves(std::vector<Board*> &vals,
                      const Board &b,
                      const Location &origin,
                      const Location &l,
                      int dx,
                      int dy,
                      int cnt,
                      bool can_capture,
                      int max_cnt) const
{
	const BoardSlot *piece = &b.get(l);
	if(piece->owner() == m_owner)
		return;
	if(piece->owner() == Player::None || can_capture)
	{
		Board *board = new Board(b);
		board->move(origin, l);
		vals.push_back(board);
		if(!can_capture)
		{
			++cnt;
			if(max_cnt && max_cnt > cnt)
				scanMoves(vals,
				          b,
				          origin,
				          Location(l.x()+dx, l.y()+dy),
				          dx,
				          dy,
				          cnt,
				          can_capture,
				          max_cnt);
		}
	}
}



{'fraction_non_alphanumeric': 0.16346153846153846, 'fraction_numerical': 0.021033653846153848, 'mean_word_length': 1.977191413237925, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2915671', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2487, 'n_words': 628}