Skip to content

Commit

Permalink
Добавлена проверка входного массива для метода setTilesPositon(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChernov committed Nov 16, 2014
1 parent 0fc8b7d commit 1083be0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/rdo_studio/plugins/game5/src/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,22 @@ std::vector<unsigned int> Board::getBoardState() const

void Board::setTilesPositon(const std::vector<unsigned int>& newState)
{
for (unsigned int positionIndex = 0; positionIndex < newState.size(); positionIndex++)
for (unsigned int positionIndex = 0; positionIndex < newState.size() &&
positionIndex < getBoardState().size(); positionIndex++)
{
unsigned int currentStateIndex = getBoardState()[positionIndex];
if (newState[positionIndex] != currentStateIndex)
swapTiles(newState[positionIndex], currentStateIndex);
swapTiles(newState[positionIndex], currentStateIndex);
}
}

void Board::swapTiles(int first, int second)
{
const unsigned int firstPosition = tiles[first]->getPosition();
moveTile(tiles[first], tiles[second]->getPosition());
moveTile(tiles[second], firstPosition);
if (first != second)
{
const unsigned int firstPosition = tiles[first]->getPosition();
moveTile(tiles[first], tiles[second]->getPosition());
moveTile(tiles[second], firstPosition);
}
}

void Board::moveTile(PlacedTile* tile, unsigned int place)
Expand Down

0 comments on commit 1083be0

Please sign in to comment.