Example #1
0
void DispBoard(const BOARD *Board) {

   int Time, Rank, File, Square;
   static const char *Colour[] = { "Black", "?!?!?", "White" };

   Time = 0;

   if (Board == Game->Board) {
      Time = (int) (ClockWise == FORWARD) ? ElapsedTime[0] : RemainingTime(0);
      if (Time < 0) Time = 0;
   }
   printf("\n  A B C D E F G H         %02d:%02d:%02d\n",Time/3600,(Time%3600)/60,Time%60);
   for (Rank = 0, Square = A1; Rank < 8; Rank++, Square++) {
      printf("%d ",Rank+1);
      for (File = 0; File < 8; File++, Square++) {
         board.Square[Rank][File].Colour = Board->Square[Square];
         if (IsLegalMove(Board,Square)) {
            printf(". ");
            strcpy(board.Square[Rank][File].String,"*");
         } else {
            printf("%c ","*-O"[Board->Square[Square]+1]);
            strcpy(board.Square[Rank][File].String,"");
         }
      }
      printf("%d",Rank+1);
      switch (Rank) {
         case 1 :
            printf("  %2d Disks * %2d Moves",DiskNb(Board,BLACK),Mobility(Board,BLACK));
            break;
         case 3 :
            printf("      %2d Empties",EmptyNb(Board));
            break;
         case 4 :
            if (IsFinished(Board)) {
               printf("      Game ended");
            } else {
               printf("     %s's Turn",Colour[Board->Colour+1]);
            }
            break;
         case 6 :
            printf("  %2d Disks O %2d Moves",DiskNb(Board,WHITE),Mobility(Board,WHITE));
            break;
      }
      printf("\n");
   }
   if (Board == Game->Board) {
      Time = (int) (ClockWise == FORWARD) ? ElapsedTime[1] : RemainingTime(1);
      if (Time < 0) Time = 0;
   }
   printf("  A B C D E F G H         %02d:%02d:%02d\n\n",Time/3600,(Time%3600)/60,Time%60);

   board.Colour = Board->Colour;
   DispXBoard();
}
Example #2
0
bool eChatPrefixSpamTester::HasKnownPrefix( tString & out, nTimeRolling & timeOut ) const
{
    eChatLastSaid::PrefixList & prefixes = player_->GetLastSaid().knownPrefixes_;
    eChatLastSaid::Prefix testPrefix( say_.Said(), 0, 0 );
    
    eChatLastSaid::PrefixList::iterator it =
        std::find_if( prefixes.begin(), prefixes.end(), IsPrefixPredicate< eChatLastSaid::Prefix >( testPrefix ) );
    
    if ( it != prefixes.end() )
    {
        // Stop saying that!
        it->timeout_ += se_CalcTimeout( it->score_ ) / 3;
        
        out = se_EscapeColors( it->prefix_ );
        timeOut = RemainingTime( it->timeout_ );
        
        return true;
    }
    
    return false;
}
Example #3
0
bool eChatPrefixSpamTester::Check( tString & out, nTimeRolling & timeOut, eChatPrefixSpamType & typeOut )
{
    if ( !ShouldCheckMessage( say_ ) )
        return false;
        
    RemoveTimedOutPrefixes();
    
    // check from known prefixes
    if ( HasKnownPrefix( out, timeOut ) )
    {
        typeOut = eChatPrefixSpamType_Known;
        return true;
    }
        
    
    eChatLastSaid::SaidList & lastSaid = player_->GetLastSaid().lastSaid_;
    
    // Map of Prefix => Data
    std::map< tString, PrefixEntry > foundPrefixes;
        
    for ( eChatLastSaid::SaidList::iterator it = lastSaid.begin(); it != lastSaid.end(); ++it )
    {
        eChatSaidEntry & said = *it;
        
        if ( !ShouldCheckMessage( said ) || say_.Said() == said.Said() )
            continue;
        
        int common = CommonPrefix( say_.Said(), said.Said() );
        
        if ( common > 0 )
        {
            const tString prefix = say_.Said().SubStr(0, common);
            
            // User is talking to a player. Not prefix spam, but we still check the
            // message text excluding the player name.
            // Example: Player 1: grind center. [etc...]
            int nameLen;
            if ( ChatDirectedTowardsPlayer( prefix, nameLen ) )
            {
                said.SetType( eChatMessageType_Public_Direct );
                said.said_ = said.said_.SubStr( nameLen + 1 );
                
                return false;
                
            }
            
            if ( foundPrefixes.find(prefix) == foundPrefixes.end() )
                foundPrefixes[prefix] = PrefixEntry();
            
            PrefixEntry & data = foundPrefixes[prefix];

            data.occurrences += 1;
            CalcScore( data, common, prefix );
            if ( data.score >= se_prefixSpamRequiredScore )
            {
                
#ifdef DEBUG
                con << "Spam prefix found: \"" << se_EscapeColors( prefix ) << "\" with score " << data.score << '\n';
#endif
                nTimeRolling t = player_->GetLastSaid().AddPrefix( prefix, data.score, say_.Time() );
                timeOut = RemainingTime( t );
                
                // We caught the prefix. Don't catch words that start with the prefix.
                RemovePrefixEntries( prefix, said );
                
                out = se_EscapeColors( prefix );
                typeOut = eChatPrefixSpamType_New;
                
                return true;
            }
        }
    }

    return false;
}