Skip to content

Commit

Permalink
Reduce number of operations when updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Alfonso committed Dec 4, 2023
1 parent 555d059 commit f1548bc
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/CTableauState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ CTableauState::CSetState::CSetState() :

unsigned short CTableauState::CSetState::Update( const piece_type& aPiece )
{
// If it is a wildcard, just keep it going!
if( aPiece == CTableau::E_PIECE_TYPE::WILDCARD )
mPieceSequence.push_back( aPiece );
// If it continues the sequence
else if( !mChessSet || *mChessSet == CTableau::CHESS_PIECES().contains( aPiece ) )
if( aPiece != CTableau::E_PIECE_TYPE::WILDCARD )
{
const auto& found = std::find( mPieceSequence.begin(), mPieceSequence.end(), aPiece );
// If repeated, delete that portion and reset count before adding new
if( found != mPieceSequence.end() )
const auto pieceSet = CTableau::CHESS_PIECES().contains( aPiece );
if( !mChessSet )
mChessSet = pieceSet;
// If it continues the sequence
else if( *mChessSet == pieceSet )
{
mPieceSequence.erase( mPieceSequence.begin(), found + 1 );
auto found = std::find( mPieceSequence.cbegin(), mPieceSequence.cend(), aPiece );
// If repeated, delete that portion and reset count before adding new
if( found != mPieceSequence.cend() )
{
mPieceSequence.erase( mPieceSequence.cbegin(), ++found );
mCount = 0;
}
}
// Otherwise, reset
else
{
mPieceSequence.clear();
mChessSet = !*mChessSet;
mCount = 0;
}
mPieceSequence.push_back( aPiece );
mChessSet = CTableau::CHESS_PIECES().contains( aPiece );

}
// Otherwise, reset
else
{
mPieceSequence.clear();
mPieceSequence.push_back( aPiece );
mChessSet = !*mChessSet;
mCount = 0;
}
mPieceSequence.push_back( aPiece );

// Detect score given by this piece
if( mPieceSequence.size() == CTableau::CHESS_PIECES().size() )
if( mChessSet && mPieceSequence.size() >= CTableau::CHESS_PIECES().size() )
{
++mCount;
mPieceSequence.clear();
Expand Down

0 comments on commit f1548bc

Please sign in to comment.