Commit 2924b300 authored by Emil's avatar Emil

start of islegalmove

parent c6af497f
......@@ -14,9 +14,17 @@
#include <optional>
namespace gameengine
{
namespace eagde_case {
struct MyException : std::exception {
const char* what() const override {
return "Out of board";
}
};
}
// 8x8 game board
namespace detail
{
......
......@@ -27,82 +27,63 @@ namespace gameengine::utility
BitPos nextPosition(const BitPos& board_pos, const MoveDirection& dir)
{
switch (dir) {
case MoveDirection::N: //new position when moving North
if (board_pos.value()>55) {
if (board_pos.value()%8 > 6 && (MoveDirection::E == dir || MoveDirection::NE == dir || MoveDirection::SE == dir)) {
throw eagde_case::MyException();
}
else {
return gameengine::BitPos(board_pos.value()+8);
if (board_pos.value()%8 < 1 && (MoveDirection::W == dir || MoveDirection::NW == dir|| MoveDirection::SW == dir)) {
throw eagde_case::MyException();
}
case MoveDirection::S: //new position when moving South
if (board_pos.value()<8) {
if (floor(board_pos.value()/8) > 7 && (MoveDirection::N == dir|| MoveDirection::NE == dir || MoveDirection::NW == dir)){
throw eagde_case::MyException();
}
else {
return gameengine::BitPos(board_pos.value()-8);
}
case MoveDirection::E: //new position when moving East
if (board_pos.value()%8>6) {
if (floor(board_pos.value()/8) < 1 && (MoveDirection::S == dir|| MoveDirection::SE == dir|| MoveDirection::SW == dir)){
throw eagde_case::MyException();
}
}
else {
else {
switch (dir) {
case MoveDirection::N: //new position when moving North
return gameengine::BitPos(board_pos.value()+8);
case MoveDirection::S: //new position when moving South
return gameengine::BitPos(board_pos.value()-8);
case MoveDirection::E: //new position when moving East
return gameengine::BitPos(board_pos.value()+1);
}
case MoveDirection::W: //new position when moving West
if (board_pos.value()%8<1) {
}
else {
case MoveDirection::W: //new position when moving West
return gameengine::BitPos(board_pos.value()-1);
}
case MoveDirection::SE: //new position when moving South_East
if (board_pos.value()<8 && board_pos.value()%8>6) {
}
else {
case MoveDirection::SE: //new position when moving South_East
return gameengine::BitPos(board_pos.value()-7);
}
case MoveDirection::SW: //new position when moving South-West
if (board_pos.value()<8 && board_pos.value()%8<1) {
}
else {
case MoveDirection::SW: //new position when moving South-West
return gameengine::BitPos(board_pos.value()-9);
}
case MoveDirection::NE: //new position when moving North-East
if (board_pos.value()>55 && board_pos.value()%8>6) {
}
else {
case MoveDirection::NE: //new position when moving North-East
return gameengine::BitPos(board_pos.value()+9);
}
case MoveDirection::NW: //new position when moving North-West
if (board_pos.value()>55 && board_pos.value()%8<1) {
}
else {
return gameengine::BitPos(board_pos.value()+7);
case MoveDirection::NW: //new position when moving North-West
return gameengine::BitPos(board_pos.value()+7);
}
}
}
BitPosSet legalMoves(const BitBoard& /*board*/, const PlayerId& /*player_id*/)
BitPosSet legalMoves(const BitBoard& board, const PlayerId& player_id)
{
return {};
}
bool isLegalMove(const BitBoard& /*board*/, const PlayerId& /*player_id*/,
const BitPos& /*board_pos*/)
bool isLegalMove(const BitBoard& board, const PlayerId& player_id,
const BitPos& board_pos)
{
if (){
return true;
}
else{
return false;
return false;
}
}
void move(BitBoard& /*board*/, const PlayerId& /*player_id*/,
const BitPos& /*board_pos*/)
void move(BitBoard& board, const PlayerId& player_id,
const BitPos& board_pos)
{
}
......
......@@ -28,6 +28,7 @@ int main(int argc, char** argv) try {
return app.exec();
}
catch ()
catch (std::string exception) {
std::cout << "Runtime exception: " << exception << std::endl;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment