Example #1
0
void MainTest::deletePost()
{
    auto count = FROM(db.posts())
            WHERE(Post::idField() == postId)
            DELETE();

    QTEST_ASSERT(count == 1);

    count = FROM(db.posts())
            WHERE(Post::idField() == postId)
            COUNT();

    QTEST_ASSERT(count == 0);
}
Example #2
0
int main (int argc, char** argv) {
  //FILE* fp = popen(FROM("/sys/devices") SELECT SUBSYSTEM("tty"), "r");
  FILE* fp = popen(FROM("/sys/devices") SELECT SUBSYSTEM("usb") SELECTUP SUBSYSTEM("pci"), "r");

  if (!fp) {
    printf("popen() failed\n");
    return 1;
  }

  char* device = NULL;
  size_t n = 0;
  while (-1 != getdelim(&device, &n, '\0', fp)) {
    printf("%s\n", device);
  }

  free(device);

  if (ferror(fp)) {
    printf("error while reading\n");
    return 1;
  }

  if (-1 == pclose(fp)) {
    printf("pclose() failed\n");
    return 1;
  }
}
Example #3
0
int getBookMove(Position *pos) {
	tableEntry *t;
	int i;
	i = HASHKEY(pos->hash);
	t = &transpositionTable[i];
	if (t->hash == pos->hash && t->bookMove) {
		//the opening book doesn't contain information like en-passant
		//and castling rights, so we must provide it
		int move;
		int p, sq0, sq1, cap, prom;
		int sd;
		sd = 6 * (pos->ply % 2);
		move = t->bookMove;
		sq0 = FROM(move);
		sq1 = TO(move);
		p = pos->squares[sq0];
		cap = pos->squares[sq1];
		if ((p == WP || p == BP) && cap == EMPTY && sq1%8 != sq0%8) { //en passant
			cap = BP - sd;
		}
		prom = PROM(move);
		return MOV(sq0, sq1, cap, prom, pos->castle, pos->enpas);
	}
	return 0;
}
Example #4
0
// String move in long algebraic form.
char*
StringMoveFull(Move move, Piece piece, bool capture)
{
  char actionChr, pieceChr;
  char *suffix, *from, *to;
  char ret[1+2+1+2+2+1];

  if(move == INVALID_MOVE) {
    return strdup("-");
  }

  from = StringPosition(FROM(move));
  to = StringPosition(TO(move));

  switch(TYPE(move)) {
  default:
    suffix = "??";
    break;
  case CastleQueenSide:
    return strdup("O-O-O");
  case CastleKingSide:
    return strdup("O-O");
  case EnPassant:
    suffix = "ep";
    break;
  case PromoteKnight:
    suffix = "=N";
    break;
  case PromoteBishop:
    suffix = "=B";
    break;
  case PromoteRook:
    suffix = "=R";
    break;
  case PromoteQueen:
    suffix = "=Q";
    break;
  case Normal:
    suffix = "";
    break;
  }

  if(capture) {
    actionChr = 'x';
  } else {
    actionChr = '-';
  }

  pieceChr = CharPiece(piece);

  if(pieceChr == 'P' || pieceChr == 'p') {
    sprintf(ret, "%s%c%s%s", from, actionChr, to, suffix);
  } else {
    sprintf(ret, "%c%s%c%s%s", pieceChr, from, actionChr, to, suffix);
  }

  return strdup(ret);
}
Example #5
0
void MainTest::initTestCase()
{
    qDebug() << "User type id:" << qRegisterMetaType<Post*>();
    qDebug() << "Comment type id:" << qRegisterMetaType<Comment*>();
    qDebug() << "DB type id:" << qRegisterMetaType<WeblogDatabase*>();

    db.setDriver(DRIVER);
    db.setHostName(HOST);
    db.setDatabaseName(DATABASE);
    db.setUserName(USERNAME);
    db.setPassword(PASSWORD);

    bool ok = db.open();

    QTEST_ASSERT(ok);

    FROM(db.comments())
            DELETE();
    FROM(db.posts())
            DELETE();
}
Example #6
0
void MainTest::modifyPost()
{
    auto q = db.posts()->createQuery();
    q->setWhere(Post::idField() == postId);

    Post *post = q->first();

    QTEST_ASSERT(post != 0);

    post->setTitle("new name");
    db.saveChanges();

    q = FROM(db.posts())
            WHERE(Post::idField() == postId);

    post = q->first();
    QTEST_ASSERT(post->title() == "new name");
}
Example #7
0
void MainTest::testDate()
{
    QDateTime d = QDateTime::currentDateTime();
    QTime t = QTime(d.time().hour(), d.time().minute(), d.time().second());
    d.setTime(t);

    Post *newPost = new Post;
    newPost->setTitle("post title");
    newPost->setSaveDate(d);

    db.posts()->append(newPost);

    db.saveChanges();

    auto q = FROM(db.posts())
            WHERE(Post::idField() == newPost->id())
            FIRST();

    qDebug() << d << q->saveDate();
    QTEST_ASSERT(q->saveDate() == d);
}
Example #8
0
char*
StringMove(Move move)
{
  char ret[10];

  if(move == INVALID_MOVE) {
    return strdup("-");
  }

  sprintf(ret, "%s%s", StringPosition(FROM(move)),
          StringPosition(TO(move)));

  switch(TYPE(move)) {
  case CastleKingSide:
    return strdup("O-O");
  case CastleQueenSide:
    return strdup("O-O-O");
  case PromoteKnight:
    sprintf(ret+4, "=N");
    break;
  case PromoteBishop:
    sprintf(ret+4, "=B");
    break;
  case PromoteRook:
    sprintf(ret+4, "=R");
    break;
  case PromoteQueen:
    sprintf(ret+4, "=Q");
    break;
  case EnPassant:
    sprintf(ret+4, "ep");
    break;
  case Normal:
    break;
  default:
    sprintf(ret+4, "??%d", TYPE(move));
  }

  return strdup(ret);
}
Example #9
0
			wxColor colour(wxString::Format(wxT("#%06x"), (int)FbParams(param)));
			control->SetColour(colour);
		}
	} else wxLogError(wxT("Control not found: %d"), winid);
}

wxString FbDialog::GetCommandSQL(const wxString &table)
{
wxString sql = wxT("\
SELECT\
	b.file_type,t.command,CASE WHEN b.file_type='fb2' THEN 1 ELSE 2 END \
FROM(\
	SELECT DISTINCT LOWER(file_type) AS file_type FROM books WHERE deleted IS NULL\
	GROUP BY file_type\
	UNION SELECT DISTINCT file_type FROM %s.types\
	UNION SELECT 'fb2'\
	UNION SELECT 'pdf'\
	UNION SELECT 'djvu'\
	UNION SELECT 'txt'\
)AS b LEFT JOIN %s.types as t ON b.file_type=t.file_type \
ORDER BY 3,1\
");
return wxString::Format(sql, table.c_str(), table.c_str());
}

//-----------------------------------------------------------------------------
//  FbDialog
//-----------------------------------------------------------------------------

IMPLEMENT_CLASS(FbToolBar, wxToolBar)
void trans_snd_rcv(double *buff,  double *trans, int Block_order,
                   double *work,  int my_ID, int Num_procs)
{
   int iphase;
   int block_size;
   int send_to, recv_from;
   double *bblock;    /* pointer to current location in buff */
   double *tblock;    /* pointer to current location in trans */
   MPI_Status status;

   block_size = Block_order * Block_order;

/*******************************************************************
**  Do the tranpose in Num_procs phases.  
**
**  In the first phase, do the diagonal block.  Then move out 
**  from the diagonal copying the local matrix into a communication 
**  buffer (while doing the local transpose) and send to processor 
**  (diag+phase)%Num_procs.
*******************************************************************/
   bblock = buff  + my_ID*block_size;
   tblock = trans + my_ID*block_size;

   transpose(bblock, Block_order, tblock, Block_order, 
             Block_order, Block_order);

   for (iphase=1; iphase<Num_procs; iphase++){

      send_to = TO(my_ID, iphase, Num_procs);
      bblock  = buff + send_to * block_size;

      transpose(bblock, Block_order, work, Block_order, 
             Block_order, Block_order);
	 
#ifdef DEBUG 
   printf("\n transposed block for phase %d on node %d is \n",
               iphase,my_ID);
   outmat(work, Block_order, Block_order);
   fflush(stdout);
#endif
  
      MPI_Send (work, block_size, MPI_DOUBLE, send_to,
                iphase, MPI_COMM_WORLD);

      recv_from = FROM(my_ID, iphase, Num_procs);
	 
      tblock  = trans + recv_from * block_size;
 
#ifdef DEBUG
   printf("\n phase %d on node %d, recv_from = %d and send_to = %d\n",
                             iphase, my_ID, recv_from, send_to);
   printf("\n %x %d %d %d %x \n", tblock, block_size, recv_from, 
                             iphase, &status );
   fflush(stdout);
#endif

         MPI_Recv (tblock, block_size, MPI_DOUBLE, recv_from,
              iphase, MPI_COMM_WORLD, &status);  

   }
}
int BOARD::alphabeta(int depth,int alpha,int beta,bool donull)
{
	if(depth==0)
	{ 
		//info.nodes++;
		return quiescence(alpha,beta);
		//return evaluate();
	}

	
	if((info.nodes & 2047) == 0)
	check();
	info.nodes++;
	

	
	if((repeat() || fifty >=100) & ply)
	return 0;

	if(ply >MAXDEPTH -1)
	return evaluate();
	
		bool kingsafe;
		int pos=(int)log2(board[side+4] & -board[side+4]);
		kingsafe=isSafe(pos,side);
		if(!kingsafe)
		depth++;
	
	int score = -INFINITE;
	
/*	if(donull && ply && kingsafe && depth >4 && bigPiece[side] >0)
	{
		makeNullMove();
		score=-alphabeta(depth-4,-beta,-beta+1,false);
		unmakeNullMove();
		if(info.stopped)
		return 0;
		
		if(score>=beta)
		return beta;
	}*/
	
	int legal=0;
	int oldalpha=alpha;
	int bestmove=NOMOVE;
	score=-INFINITE;
	MOVE_LIST moveList;
	moveList.count=0;
	generateAllMoves(moveList);
	

	int pvMove=getPvMove();
	if(pvMove != NOMOVE)
	{
		for(int i=0;i<moveList.count;i++)
		{
			if(moveList.l[i].move == pvMove)
			{
				moveList.l[i].score=2000000;
				break;			
			}
		}
	}

	std::sort(moveList.l,moveList.l+moveList.count,so);

	for(int i=0;i<moveList.count;i++)
	{
		//pickBest(i,moveList);
		if(!makeMove(moveList.l[i].move))
		continue;
		legal++;
		score=-alphabeta(depth-1,-beta,-alpha,donull);
		unmakeMove();

		if(info.stopped)
		return 0;
		
		if(score >alpha)
		{
			if(score >=beta)
			{
				if(legal==1)
				info.fhf++;
				info.fh++;
			if(CAP(moveList.l[i].move) == EMPTY)
			{
				searchKillers[1][depth]=searchKillers[0][depth];
				searchKillers[0][depth]=moveList.l[i].move;				
			}
			return beta;	//beta - cutoff
			}
			alpha=score;
			bestmove=moveList.l[i].move;
			if(CAP(moveList.l[i].move) == EMPTY)
			searchHistory[cboard[FROM(bestmove)]][TO(bestmove)]+=depth;
		}		
	}

	if(legal == 0)
	{
		if(!kingsafe)
		return -MATE + ply;
		else
		return 0;
	}

	if(alpha != oldalpha)
	storePv(bestmove);
	
	return alpha;
}
Example #12
0
void MakeWhite (typePOS* POSITION, uint32 move)
{
  int fr, to, pi, fl, cp, z;
  uint64 mask;
  TRACE (TRACE_MAKE_UNMAKE,
	 printf ("Mw %d %s\n", HEIGHT (POSITION), Notate(move, STRING1[POSITION->cpu])));
  POSITION->nodes++;
  if (!TITANIC_MODE) /* new */
    {
      NODE_CHECK++;
      if ((NODE_CHECK & 4095) == 0)
	CheckDone (POSITION, 0);
    }
  memcpy (POSITION->DYN + 1, POSITION->DYN, 32);
  fr = FROM (move);
  to = TO (move);
#ifdef CHESS_960
  if (UCI_OPTION_CHESS_960 && MoveIsOO (move))
    {
      Castle960White (POSITION, move, to, fr);
      return;
    }
#endif
  pi = POSITION->sq[fr];
  POSITION->DYN++;
  REV_HASH (POSITION);
  POSITION->DYN->reversible++;
  POSITION->DYN->move = move;
  fl = CastleTable[fr] & CastleTable[to] & POSITION->DYN->oo;
  POSITION->DYN->HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->PAWN_HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->oo = fl;
  if (POSITION->DYN->ep)
    {
      POSITION->DYN->HASH ^= ZobristEP[POSITION->DYN->ep & 7];
      POSITION->DYN->ep = 0;
    }
  POSITION->sq[fr] = 0;
  mask = SqClear[fr];
  wBitboardOcc &= mask;
  POSITION->bitboard[pi] &= mask;
  ClearOccupied (mask, fr);
  POSITION->DYN->STATIC += PST (pi, to) - PST (pi, fr);
  mask = Zobrist (pi, fr) ^ Zobrist (pi, to);
  cp = POSITION->sq[to];
  POSITION->DYN->cp = cp;
  POSITION->DYN->HASH ^= mask;
  if (pi == wEnumP)
    POSITION->DYN->PAWN_HASH ^= mask;
  POSITION->wtm ^= 1;
  POSITION->height++;
  POSITION->DYN->HASH ^= ZobristWTM;
  if (pi == wEnumK)
    {
      POSITION->DYN->PAWN_HASH ^= mask;
      POSITION->wKsq = to;
    }
  if (cp)
    {
      mask = SqClear[to];
      bBitboardOcc &= mask;
      POSITION->bitboard[cp] &= mask;
      POSITION->DYN->material -= MATERIAL_VALUE[cp];
      POSITION->DYN->STATIC -= PST (cp, to);
      if (cp == bEnumP)
	POSITION->DYN->PAWN_HASH ^= Zobrist (cp, to);
      POSITION->DYN->HASH ^= Zobrist (cp, to);
      POSITION->DYN->reversible = 0;
    }
  else
    {
      mask = SqSet[to];
      SetOccupied (mask, to);
      if (MoveIsOO (move))
	{
	  REV_CASTLE (POSITION);
	  MakeWhiteOO (POSITION, to);
	}
    }
  POSITION->sq[to] = pi;
  wBitboardOcc |= SqSet[to];
  POSITION->bitboard[pi] |= SqSet[to];
  if (pi == wEnumP)
    {
      POSITION->DYN->reversible = 0;
      if (MoveIsEP (move))
	{
	  z = to ^ 8;
	  mask = SqClear[z];
	  bBitboardOcc &= mask;
	  bBitboardP &= mask;
	  ClearOccupied (mask, z);
	  POSITION->DYN->material -= MATERIAL_VALUE[bEnumP];
	  POSITION->DYN->STATIC -= PST (bEnumP, z);
	  POSITION->DYN->HASH ^= Zobrist (bEnumP, z);
	  POSITION->DYN->PAWN_HASH ^= Zobrist (bEnumP, z);
	  POSITION->sq[z] = 0;
	}
      else if (MoveIsProm (move))
	{
	  pi = PromW[(move & FLAG_MASK) >> 12];
	  if (pi == wEnumBL && SqSet[to] & DARK)
	    pi = wEnumBD;
	  POSITION->sq[to] = pi;
	  if (POSITION->bitboard[pi])
	    POSITION->DYN->material |= 0x80000000;
	  wBitboardP &= SqClear[to];
	  POSITION->bitboard[pi] |= SqSet[to];
	  POSITION->DYN->material += MATERIAL_VALUE[pi] - MATERIAL_VALUE[wEnumP];
	  POSITION->DYN->STATIC += PST (pi, to) - PST (wEnumP, to);
	  POSITION->DYN->HASH ^= Zobrist (pi, to) ^ Zobrist (wEnumP, to);
	  POSITION->DYN->PAWN_HASH ^= Zobrist (wEnumP, to);
	}
      else if ((to ^ fr) == 16)