Beispiel #1
0
bool FindSquare::check(const Point& a, const Point& b) const {
// Works only if a different from b
  if(a==b){
    return false;
  }

  Vector u = b - a;
  Vector v(-u.y(), u.x());
  
  Point A1 = a + v;
  Point B1 = b + v;

  // Return true if A1,B1 exist and  are part of a square with a,b
  if(existsInMap(A1) && existsInMap(B1)) {
    printSquare(a,b,A1,B1);
    return true;
  }
  
  Point A2 = a - v;
  Point B2 = b - v;
  
  // Return true if A2,B2 exist and  are part of a square with a,b
  if(existsInMap(A2) && existsInMap(B2)) {
    printSquare(a,b,A2,B2);
    return true;
  }

  // False othewise
  return false;
}
Beispiel #2
0
// Prints a formatted version of the game board into the console window.
inline void printBoard(const S_BOARD *pos) {
  static const char *temp = "   +---+---+---+---+---+---+---+---+";
  printf("\n============================ GAME BOARD "
         "============================\n\n");
  printf("     a   b   c   d   e   f   g   h\n");
  printf("%s\n", temp);
  for (unsigned rank = RANK_8; rank != (unsigned)(RANK_1 - 1); rank--) {
    printf(" %c | ", '1' + rank);
    for (unsigned file = FILE_A; file <= FILE_H; file++) {
      const unsigned piece = pos->pieces[FR2SQ(file, rank)];
      ASSERT(pieceValidEmpty(piece));
      printf("%c | ", pieceChar[piece]);
    }
    printf("%c", '1' + rank);
    switch (rank) {
    case RANK_8:
      printf("          DROPPABLE PIECES\n%s         +---+---+---+---+---+\n",
             temp);
      break;
    case RANK_7:
      printf("       | P | N | B | R | Q |");
      printf("\n%s     +---+---+---+---+---+---+\n", temp);
      break;
    case RANK_6:
      printf("   | W | %d | %d | %d | %d | %d |", pos->dropNum[wP],
             pos->dropNum[wN], pos->dropNum[wB], pos->dropNum[wR],
             pos->dropNum[wQ]);
      printf("\n%s     +---+---+---+---+---+---+\n", temp);
      break;
    case RANK_5:
      printf("   | B | %d | %d | %d | %d | %d |", pos->dropNum[bP],
             pos->dropNum[bN], pos->dropNum[bB], pos->dropNum[bR],
             pos->dropNum[bQ]);
      printf("\n%s     +---+---+---+---+---+---+\n", temp);
      break;
    default:
      printf("\n%s\n", temp);
      break;
    }
  }
  printf("     a   b   c   d   e   f   g   h\n\n");

  ASSERT(sideValid(pos->side));
  if (pos->hisPly > 0) {
    printf("  LAST MOVE: %s\n", printMove(pos->history[pos->hisPly - 1]->move));
  } else {
    printf("  LAST MOVE: NONE\n");
  }
  printf("  SIDE TO MOVE: %s\n", pos->side == WHITE ? "WHITE" : "BLACK");
  printf("  EN PASSANT SQUARE: %s\n", printSquare(pos->enPas));
  printf("  CASTLING PERMISSIONS: %c%c%c%c\n",
         pos->castlePerm & WKCA ? 'K' : '-', pos->castlePerm & WQCA ? 'Q' : '-',
         pos->castlePerm & BKCA ? 'k' : '-',
         pos->castlePerm & BQCA ? 'q' : '-');
  printf("  HASHKEY: %llX\n", pos->posKey);
  printf("  FEN: '%s'\n", printFEN(pos));
  printf("\n========================== END GAME BOARD "
         "==========================\n\n");
}
Beispiel #3
0
int main()
{
	
    printSquare();
	
	
    return 0;
}
int main(void) {
	int size;
	printf("Enter size of square: ");
	scanf("%d", &size);

	printSquare(size);

	system("pause");
	return 0;
}
void fourth(std::vector< std::vector<int> > &square){
    if(actualValue == LIMIT) {return;}
    std::cout<<"4. Caso já haja um número na nova posição, volta-se a posição antiga\n e apenas descemos linha. A coluna continua a mesma."<<std::endl;
    
    y = (y+((L*2)-1))%L;
    x = (x+2)%L;

    square[x][y] = actualValue++;
    printSquare(square);
}
Beispiel #6
0
void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b) {
	int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
	int counter = 0;
	dx=x2-x1;			//Delta x
	dy=y2-y1;			//Delta y
	dxabs=abs(dx);		//Absolute delta
	dyabs=abs(dy);		//Absolute delta
	sdx=(dx>0)?1:-1; //signum function
	sdy=(dy>0)?1:-1; //signum function
	x=dyabs>>1;
	y=dxabs>>1;
	px=x1;
	py=y1;

	if (dxabs>=dyabs)
	{
		for(i=0;i<dxabs;i++)
		{
			y+=dyabs;
			if (y>=dxabs)
			{
				y-=dxabs;
				py+=sdy;
			}
			px+=sdx;					
			printSquare(px,py,r,b,g);
		}
	}
	else
	{
		for(i=0;i<dyabs;i++)
		{
			x+=dxabs;
			if (x>=dyabs)
			{
				x-=dyabs;
				px+=sdx;
			}
			py+=sdy;	
			printSquare(px,py,r,g,b);
		}
	}
}
void third(std::vector< std::vector<int> > &square){
    x =(x+((L*2)-1))%L;
    y =(y+1)%L;   

    if(square[x][y] != 0){
        fourth(square);
        return;
    }
    std::cout<<"3. O próximo número é colocado deslocando uma posição para cima \ne  uma posição para direita. Caso seja alcançada uma das \nbordas do quadrado, a posição é invertida."<<std::endl;
    square[x][y] = actualValue++;
    printSquare(square);
}
Beispiel #8
0
inline const char *printFEN(const S_BOARD *pos) {
  int emptyCount = 0;
  int strIndex = 0;
  static char result[256];
  for (int rank = RANK_8; rank >= RANK_1; rank--) {
    for (int file = FILE_A; file <= FILE_H; file++) {
      int sq120 = FR2SQ(file, rank);
      int piece = pos->pieces[sq120];
      if (piece == EMPTY) {
        emptyCount++;
      } else {
        if (emptyCount != 0) {
          result[strIndex++] = '0' + emptyCount;
          emptyCount = 0;
        }
        result[strIndex++] = pieceChar[piece];
      }
    }
    if (emptyCount != 0) {
      result[strIndex++] = '0' + emptyCount;
      emptyCount = 0;
    }
    if (rank != RANK_1) {
      result[strIndex++] = '/';
    }
  }
  strIndex +=
      sprintf(result + strIndex, " %c ", pos->side == WHITE ? 'w' : 'b');
  if (pos->castlePerm == 0) {
    result[strIndex++] = '-';
  } else {
    if (pos->castlePerm & WKCA)
      result[strIndex++] = 'K';
    if (pos->castlePerm & WQCA)
      result[strIndex++] = 'Q';
    if (pos->castlePerm & BKCA)
      result[strIndex++] = 'k';
    if (pos->castlePerm & BQCA)
      result[strIndex++] = 'q';
  }
  // TODO: Check if pos->hisPly / 2 + 1 is the correct formula
  strIndex += sprintf(result + strIndex, " %s %d %d", printSquare(pos->enPas),
                      pos->fiftyMove, pos->hisPly / 2 + 1);
  ASSERT(strIndex < 256);
  return result;
}
void printSquarShadow(int distanceLeft, int distanceRight,int distanceTop, int distanceDown,int textura, int corback,
 int desloc, int corShadow){
	int i=0, j=0;
	
	printSquare(distanceLeft+desloc,distanceRight-desloc,distanceTop+desloc,
	distanceDown-desloc,7,corShadow,176);
	
	textbackground(corback);
	
	for(i=distanceTop;i <= (24 - distanceDown) ; i++){
		for( j=distanceLeft; j <= (80 - distanceRight);j++){
				gotoxy(j,i);printf("%c",textura);
		}
	}
		
	color(BLACK, WHITE);
}
Beispiel #10
0
int main()
{
    char *temp_arr = (char *)malloc(50 * sizeof(char));
    int r, c, rd, cd;
    int dim = getDim(temp_arr);
    char **square = make2D(dim);
    char **answer = make2D(dim);
    moveTemp(square, temp_arr, dim);
    fillSquare(square, dim);
    /*printSquare(square, dim);*/

    temp_arr = (char*)malloc(50 * sizeof(char));
    while((fgets(temp_arr, 50, stdin)) != NULL )
    {
        if(strlen(temp_arr) > 1)
        {
            temp_arr[strlen(temp_arr) - 1] = '\0';
            /*printf("searching for %s\n",temp_arr);*/

            for(r = 0; r < dim; r++)
                for(c = 0; c < dim; c++)
                    for(rd = -1; rd <= 1; rd++)
                        for(cd = -1; cd <= 1; cd++)
                        {
                            if(find(r, c, rd, cd, dim, square, temp_arr))
                            {
                                add(r, c, rd, cd, dim, square, answer, temp_arr);
                                cd = 2;
                                rd = 2;
                                c = dim + 1;
                                r = dim + 1;
                            }
                        }
        }
    }
    free(temp_arr);
    
    printSquare(answer, dim);

    free2D(square, dim);
    free2D(answer, dim);
    return 0;
}
Beispiel #11
0
void rankingOut(tlista lista){
	
	printSquarShadow(16,3,2,1,255,7,1,8);
	printSquare(16,3,2,21,4,4,255);
	
	color(WHITE, 4);
	gowrite(43,2,"RANKING");
	
	if(statusLista(lista)==1){
		color(1, 7);
		gowrite(37,12,"No scores currently!");
		color(BLACK, WHITE);
	}
	else{
		exibeLista(lista,20,5,1,7);
	}
	
	color(BLACK, WHITE);
	getch();
}
Beispiel #12
0
int main()
{
    char opt;
    int i,j;
    printMenu();
    scanf(" %c", &opt);
    while(opt != 'q') {
        switch (opt)
        {
        case 's' : printSquare();
                   break;
        case 't' : printTriangle();
                   break;
        default:   printf("Unknown option\n");
        }
        printMenu();
        scanf(" %c", &opt);
    }
    return 0;
}
Beispiel #13
0
int main(void){
    int squareSize;
    int** square;
    
    //Grabbing initial input
    printf("This program creates a magic square if a specified size.\nThe size must be an odd number between 1 and 99.\n");
    printf("Enter size of magic square: ");
    scanf("%i", &squareSize);
    
    // Some basic error checking
    while(!isOdd(squareSize)){
        printf("The size must be an odd number between 1 and 99.\n");
        printf("Enter size of magic square: ");
        scanf("%i", &squareSize);
    }
    
    //Building and printing square
    square = buildSquare(squareSize);
    printSquare(square, squareSize);
    free(square);
    
    return 0;
}
Beispiel #14
0
int ranking(tlista *lista,tplayer player){
	int pos=0, saida=-2, i;
	
	printSquarShadow(16,3,2,1,255,7,1,8);
	printSquare(16,3,2,21,4,4,255);
	
	color(WHITE, 4);
	gowrite(43,2,"RANKING");
	
	saida = getPos(*lista,player,&pos);
	
	if(saida == 0 ){	
		inserir(&(*lista),player,1);
	}
	else if(saida == 1){
		saida=0;
		saida = inserir(&(*lista),player,pos);
		
		if(saida == 0){ /*saída igual a zero indica	 que a lista/
					  / esta cheia e é preciso remover o ultimo*/
			remov(&(*lista),TAMLISTA);
			inserir(&(*lista),player,pos);
		}
	}

	if(statusLista(*lista)==1){
		color(1, 7);
		gowrite(37,12,"No scores currently!");
		color(BLACK, WHITE);
	}
	else{
		exibeLista(*lista,20,5,1,7);
	}
	
	color(BLACK, WHITE);
	getch();
}
Beispiel #15
0
void k_shutdownScreen(){
	clearFullScreen();
	setFullBackgroundColor(BACKGROUND_COLOR_BLACK);
	set_vga_size(1,25);
	k_printWarning("                         Turning off your computer...");
	// 1 row
	printSquare(28, 1, 0x44);
	printSquare(32, 1, 0x44);
	printSquare(36, 1, 0x44);
	printSquare(40, 1, 0x44);
	printSquare(44, 1, 0x44);
	// 2 row
	printSquare(24, 3, 0x44);
	printSquare(28, 3, 0x44);
	printSquare(32, 3, 0x44);
	printSquare(36, 3, 0x44);
	printSquare(40, 3, 0x44);
	printSquare(44, 3, 0x44);
	printSquare(48, 3, 0x44);
	printSquare(52, 3, 0x44);
	printSquare(56, 3, 0x44);
	// 3 row
	printSquare(24, 5, 0x66);
	printSquare(28, 5, 0x66);
	printSquare(32, 5, 0x66);
	printSquare(36, 5, 0xFF);
	printSquare(40, 5, 0xFF);
	printSquare(44, 5, 0x00);
	printSquare(48, 5, 0xFF);
	// 4 row
	printSquare(20, 7, 0x66);
	printSquare(24, 7, 0xFF);
	printSquare(28, 7, 0x66);
	printSquare(32, 7, 0xFF);
	printSquare(36, 7, 0xFF);
	printSquare(40, 7, 0xFF);
	printSquare(44, 7, 0x00);
	printSquare(48, 7, 0xFF);
	printSquare(52, 7, 0xFF);
	printSquare(56, 7, 0xFF);
	// 5 row
	printSquare(20, 9, 0x66);
	printSquare(24, 9, 0xFF);
	printSquare(28, 9, 0x66);
	printSquare(32, 9, 0x66);
	printSquare(36, 9, 0xFF);
	printSquare(40, 9, 0xFF);
	printSquare(44, 9, 0xFF);
	printSquare(48, 9, 0x66);
	printSquare(52, 9, 0xFF);
	printSquare(56, 9, 0xFF);
	printSquare(60, 9, 0xFF);
	// 6 row
	printSquare(20, 11, 0x66);
	printSquare(24, 11, 0x66);
	printSquare(28, 11, 0xFF);
	printSquare(32, 11, 0xFF);
	printSquare(36, 11, 0xFF);
	printSquare(40, 11, 0xFF);
	printSquare(44, 11, 0x66);
	printSquare(48, 11, 0x66);
	printSquare(52, 11, 0x66);
	printSquare(56, 11, 0x66);
	// 7 row
	printSquare(28, 13, 0xFF);
	printSquare(32, 13, 0xFF);
	printSquare(36, 13, 0xFF);
	printSquare(40, 13, 0xFF);
	printSquare(44, 13, 0xFF);
	printSquare(48, 13, 0xFF);
	printSquare(52, 13, 0xFF);
	// 8 row
	printSquare(24, 15, 0x11);
	printSquare(28, 15, 0x11);
	printSquare(32, 15, 0x44);
	printSquare(36, 15, 0x11);
	printSquare(40, 15, 0x11);
	printSquare(44, 15, 0x11);
	// 9 row
	printSquare(20, 17, 0x11);
	printSquare(24, 17, 0x11);
	printSquare(28, 17, 0x11);
	printSquare(32, 17, 0x44);
	printSquare(36, 17, 0x11);
	printSquare(40, 17, 0x11);
	printSquare(44, 17, 0x44);
	printSquare(48, 17, 0x11);
	printSquare(52, 17, 0x11);
	printSquare(56, 17, 0x11);
	// 10 row
	printSquare(16, 19, 0x11);
	printSquare(20, 19, 0x11);
	printSquare(24, 19, 0x11);
	printSquare(28, 19, 0x11);
	printSquare(32, 19, 0x44);
	printSquare(36, 19, 0x11);
	printSquare(40, 19, 0x11);
	printSquare(44, 19, 0x44);
	printSquare(48, 19, 0x11);
	printSquare(52, 19, 0x11);
	printSquare(56, 19, 0x11);
	printSquare(60, 19, 0x11);
	// 11 row
	printSquare(16, 21, 0xFF);
	printSquare(20, 21, 0xFF);
	printSquare(24, 21, 0x11);
	printSquare(28, 21, 0x11);
	printSquare(32, 21, 0x44);
	printSquare(36, 21, 0x44);
	printSquare(40, 21, 0x44);
	printSquare(44, 21, 0x44);
	printSquare(48, 21, 0x11);
	printSquare(52, 21, 0x11);
	printSquare(56, 21, 0xFF);
	printSquare(60, 21, 0xFF);
	// 12 row
	printSquare(16, 23, 0xFF);
	printSquare(20, 23, 0xFF);
	printSquare(24, 23, 0xFF);
	printSquare(28, 23, 0x44);
	printSquare(32, 23, 0xEE);
	printSquare(36, 23, 0x44);
	printSquare(40, 23, 0x44);
	printSquare(44, 23, 0xEE);
	printSquare(48, 23, 0x44);
	printSquare(52, 23, 0xFF);
	printSquare(56, 23, 0xFF);
	printSquare(60, 23, 0xFF);
	return;
}
void second(std::vector< std::vector<int> > &square){
    std::cout<<"2. O primeiro número é posicionada no meio da primeira coluna."<<std::endl;
    y = (int)(L/2);
    square[x][y] = actualValue++;
    printSquare(square); 
}