Beispiel #1
0
void Board::takeStep(){
  checkTurn();
  vec step = inputVec();
  if(step == vec(-1, -1)){
    fprintf(stderr, "no input vector!\n");
    step = inputVec();
  }
  while(!canFlip(step.x, step.y, turnToPieceType(turn))){
    fprintf(stderr, "invalid input (%d, %d)!\n", step.x, step.y);
    step = inputVec();
  }
  setPieces(step.x, step.y);
  if(checkEnd()){
    if(countColor(black) > countColor(white)){
      printf("black: %d\n", countColor(black));
      printf("white: %d\n", countColor(white));
      printf("black wins!\n");
    }
    else if(countColor(black) < countColor(white)){
      printf("black: %d\n", countColor(black));
      printf("white: %d\n", countColor(white));
      printf("white wins!\n");
    }
    else{
      printf("black: %d\n", countColor(black));
      printf("white: %d\n", countColor(white));
      printf("ties!\n");
    }
    printBoard();
    exit(0);
  }
  else{
    printBoard();
  }
}
Beispiel #2
0
GameWidget::GameWidget(QWidget *parent, const char *name)
        : QWidget(parent, name)
{
	in_game = false;
	in_pause = false;

	random.setSeed(0);

	loadSprites();
	setPieces(Pieces_Smiles);

	map = new Sprite[scr_width * scr_height];
	mirror_sprites = new Sprite[scr_width];

	screen = new ScreenWidget(sprites, &in_game, &in_pause, this);
	screen->move(10, 10);
	screen->setScreenSprites(map);

	mirror = new MirrorWidget(sprites, &in_game, &in_pause, this);
	mirror->move(10, 407);
	mirror->setMirrorSprites(mirror_sprites);

	next = new NextPieceWidget(sprites, &in_game, &in_pause, this);
	next->move(278, 10);
	next->setNextPieceSprites(next_piece);

	timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
}
Beispiel #3
0
int readFen(const char *fen, Position * position)
{
   int index;

   /*
    * Initialize this module.
    */
   initialize();

   /*
    * Get the piece positions.
    */
   if ((index = setPieces(fen, position)) < 0)
   {
      return -1;
   }

   /*
    * Get the active color.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   if (stringContainsChar("bw", fen[index]))
   {
      position->activeColor = (fen[index] == 'w' ? WHITE : BLACK);
      index++;
   }
   else
   {
      return -1;                /* fen format error */
   }

   /*
    * Get the castling rights.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   position->castlingRights = NO_CASTLINGS;

   while (fen[index] != ' ')
   {
      switch (fen[index++])
      {
      case 'K':
         position->castlingRights += WHITE_00;
         break;
      case 'Q':
         position->castlingRights += WHITE_000;
         break;
      case 'k':
         position->castlingRights += BLACK_00;
         break;
      case 'q':
         position->castlingRights += BLACK_000;
         break;
      case '-':
         position->castlingRights = NO_CASTLINGS;
         break;
      default:
         return -1;             /* fen format error */
      }
   }

   /*
    * Get the en passant square.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   if (fen[index] == '-')
   {
      position->enPassantSquare = NO_SQUARE;
      index++;
   }
   else if (fen[index] >= 'a' && fen[index] <= 'h' &&
            (fen[index + 1] == '3' || fen[index + 1] == '6'))
   {
      File file = (File) (fen[index++] - 'a');
      Rank rank = (Rank) (fen[index++] - '1');

      position->enPassantSquare = getSquare(file, rank);
   }
   else
   {
      return -1;                /* fen format error */
   }

   /*
    * Get the half move clock value.
    */
   while (fen[index] == ' ')
   {
      index++;
   }

   position->halfMoveClock = atoi(fen + index);

   /*
    * Get the move number value.
    */
   while (fen[index] != ' ')
   {
      if (!isdigit((int) fen[index]))
      {
         return -1;             /* fen format error */
      }

      index++;
   }

   while (fen[index] == ' ')
   {
      index++;
   }

   position->moveNumber = atoi(fen + index);

   return 0;
}