in GomokuServer/GomokuServer/GameSession.cpp [80:133]
void GameSession::PutStone(std::shared_ptr<PlayerSession> psess, int x, int y)
{
if (x < 0 || x >= BOARD_SIZE || y < 0 || y >= BOARD_SIZE)
{
GConsoleLog->PrintOut(true, "[PutStone Denied] out of range\n", psess->GetPlayerSessionId().c_str());
return;
}
if (mGameStatus != GameStatus::GS_STARTED)
{
GConsoleLog->PrintOut(true, "[PutStone Denied] Not started game\n", psess->GetPlayerSessionId().c_str());
return;
}
FastSpinlockGuard lock(mGameSessionLock);
bool isBlack = (psess == mPlayerBlack);
if (isBlack && mCurrentTurn != StoneType::STONE_BLACK)
{
GConsoleLog->PrintOut(true, "[PutStone Denied] Turn mismatch\n", psess->GetPlayerSessionId().c_str());
return;
}
if (!isBlack && mCurrentTurn != StoneType::STONE_WHITE)
{
GConsoleLog->PrintOut(true, "[PutStone Denied] Turn mismatch\n", psess->GetPlayerSessionId().c_str());
return;
}
if (mBoardStatus.mBoardMatrix[x][y] != StoneType::STONE_NONE)
{
GConsoleLog->PrintOut(true, "[PutStone Denied] wrong position\n", psess->GetPlayerSessionId().c_str());
return;
}
StoneType st = isBlack ? StoneType::STONE_BLACK : StoneType::STONE_WHITE;
mBoardStatus.mBoardMatrix[x][y] = st;
/// Win check...
if (IsWin(st))
{
mGameStatus = isBlack ? GameStatus::GS_GAME_OVER_BLACK_WIN : GameStatus::GS_GAME_OVER_WHITE_WIN;
SendGameResult(isBlack);
}
if (isBlack)
mCurrentTurn = StoneType::STONE_WHITE;
else
mCurrentTurn = StoneType::STONE_BLACK;
BroadcastGameStatus();
}