// Copyright (c) 2022 Yevhen Babiichuk (DustDFG), <dfgdust@gmail.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.
//
// 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/>.

#include "Data.h"

#include <cstdint>

uint8_t Data::getContentCode(uint8_t x, uint8_t y)
{
	//TODO: add checks for x and y

	if(this->horseX == x && this->horseY == y)
	{
		return 255;
	}

	//TODO: add new code for possible steps

	return this->cells[x][y];
}

bool Data::isPossibleStep(uint8_t x, uint8_t y)
{
	if(this->cells[x][y] == 0){
		//Top
		if((x == this->horseX - 1) && (y == this->horseY - 2))
		{
			return true;
		}
		else if((x == this->horseX + 1) && (y == this->horseY - 2))
		{
			return true;
		}
		//Right
		else if((x == this->horseX + 2) && (y == this->horseY - 1))
		{
			return true;
		}
		else if((x == this->horseX + 2) && (y == this->horseY + 1))
		{
			return true;
		}
		//Bottom
		else if((x == this->horseX + 1) && (y == this->horseY + 2))
		{
			return true;
		}
		else if((x == this->horseX - 1) && (y == this->horseY + 2))
		{
			return true;
		}
		//Left
		else if((x == this->horseX - 2) && (y == this->horseY - 1))
		{
			return true;
		}
		else if((x == this->horseX - 2) && (y == this->horseY + 1))
		{
			return true;
		}
	}

	return false;
}

void Data::doStep(uint8_t x, uint8_t y)
{
	this->cells[this->horseX][this->horseY] = this->steps++;

	this->horseX = x;
	this->horseY = y;
}

uint8_t Data::getSize()
{
	return this->size;
}

Data::Data() : size(8), cells {0}, horseX(0), horseY(this->size - 1), steps(1)
{
	this->cells[this->horseX][this->horseY] = 255;
}

Data::~Data()
{
}
