Commit 07da586e authored by Emil's avatar Emil

Nothing

parent a57f6120
......@@ -32,13 +32,15 @@ namespace gameengine
constexpr size_t invalidBoardPosition() { return computeBoardSize(); }
} // namespace detail
struct BitPos {
constexpr BitPos() : m_bitpos{detail::invalidBoardPosition()} {}
constexpr explicit BitPos(size_t bitpos) : m_bitpos{bitpos} {
if (bitpos >= detail::computeBoardSize())
throw std::out_of_range(
"BitPos input position out of range " + std::to_string(bitpos)
+ ". Must be between 0 and "
+ ". Must be between 0 and 63"
+ std::to_string(detail::computeBoardSize() - 1));
}
constexpr explicit BitPos(int bitpos) : m_bitpos{size_t(bitpos)} {
......@@ -79,6 +81,8 @@ namespace gameengine
enum class MoveDirection { N, S, E, W, NE, NW, SE, SW };
} // namespace gameengine
namespace std
......@@ -100,6 +104,11 @@ namespace gameengine // resume namespace gameengine
using BitPieces = std::bitset<detail::computeBoardSize()>;
using BitBoard = std::array<BitPieces, 2>;
using BitPosSet = std::unordered_set<BitPos>;
struct Move{
BitPieces start_pos;
std::vector<BitPieces> moves;
};
enum class PlayerId : size_t { One = 0UL, Two = 1UL };
......
......@@ -7,6 +7,7 @@
#include <algorithm>
namespace gameengine::utility
{
BitPieces occupiedPosition(const BitBoard& board, const PlayerId& player_id)
......@@ -30,6 +31,24 @@ namespace gameengine::utility
return occupied(occupiedPositions(board),board_pos);
}
const BitPieces MaskE = BitPieces("00000001"
"00000001"
"00000001"
"00000001"
"00000001"
"00000001"
"00000001"
"00000001");
const BitPieces MaskW = BitPieces("10000000"
"10000000"
"10000000"
"10000000"
"10000000"
"10000000"
"10000000"
"10000000");
BitPos nextPosition(const BitPos& board_pos, const MoveDirection& dir)
{
if (board_pos.value()%8 > 6 && (MoveDirection::E == dir || MoveDirection::NE == dir || MoveDirection::SE == dir)) {
......@@ -91,9 +110,10 @@ namespace gameengine::utility
}
bool isLegalMove(const BitBoard& board, const PlayerId& player_id,
const BitPos& /*board_pos*/, const BitPos& board_new_pos)
const BitPos& board_pos, const BitPos& board_new_pos)
{
if (occupied(occupiedPosition(board,player_id),board_new_pos)==1){
BitPieces player_board = occupiedPosition(board,player_id);
if (occupied(board,board_new_pos) == 1 || occupied(player_board,board_pos) == 0){
return false;
}
else {
......@@ -105,7 +125,8 @@ namespace gameengine::utility
void move(BitBoard& /*board*/, const PlayerId& /*player_id*/,
const BitPos& /*board_pos*/, const BitPos& /*board_new_pos*/)
{
//BitPieces New_pices;
//New_pices
}
} // namespace gameengine::utility
......@@ -35,17 +35,29 @@ GuiApplication::GuiApplication(int& argc, char** argv)
connect(root_window, SIGNAL(initNewHumanGame()), this,
SLOT(initNewHumanGame()));
//connect(root_window, SIGNAL(boardClicked(int)), this, SLOT(int));
//connect( this, &Application::enqueueNextTurn, this, &Application::executeNextTurn );
connect(this, &GuiApplication::gameEnded, this,
&GuiApplication::endOfGameActions);
}
}
void GuiApplication::startNextTurn()
{
// check for legal moves
// if player is human wait for input
// else perform AI move
}
void GuiApplication::initNewHumanGame()
{
m_game_engine.initPlayerType<gameengine::HumanPlayer, gameengine::PlayerId::One>();
m_game_engine.initPlayerType<gameengine::HumanPlayer, gameengine::PlayerId::Two>();
}
void GuiApplication::endGameAndQuit() { QGuiApplication::quit(); }
......@@ -54,3 +66,5 @@ void GuiApplication::endGameAndQuit() { QGuiApplication::quit(); }
void GuiApplication::endOfGameActions()
{
}
......@@ -40,7 +40,7 @@ INSTANTIATE_TEST_CASE_P(
NextPosition,
NextPositionFixture,
testing::Values(NextPositionParameters{
BitPos(0), MoveDirection::N, BitPos(8)},
BitPos(0), MoveDirection::NE, BitPos(9)},
NextPositionParameters{
BitPos(9), MoveDirection::S, BitPos(1)}
) );
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