Beispiel #1
0
int main(int argc, char *argv[])
{
	int x, y;
	int step = 0;
	int who;
	printf("Hello, FIVE CHESS PLAYER!\nReady to go? GO!\n");

	print_chessboard();
	printf("you can input 4 4 to put a chess on board\n");

	while (1) 
	{
		who = step % 2 + 1;
		printf("player %d: ", who);
		get(&x, &y);

		if (test(x, y)) 
		{
			put(x, y, who);
			print_chessboard();
			step++;
			if (find()) 
			{
				printf("Congratulations, player %d win! \n", who);
				return 0;
			}
		}
		else
			printf("%d %d is not permitted! please reinput.\n\n", x, y);
	}
	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	int x, y;
	int iffirst;
	int step = 0;
	int who;
	printf("Hello, FIVE CHESS PLAYER!\nReady to go? GO!\n");
	printf("Input 1 to go first, other to go second:\n");
	scanf("%d", &iffirst);

	if (iffirst!=1)
		chessboard[4][4] = 2;

	print_chessboard();
	printf("you can input n n to put a chess on board\n");

	while (1) 
	{
		who = step % 2 + 1;
		printf("player %d: ", who);
		if (who == 1)
			get(&x, &y);
		else
			autoget(&x, &y);
		

		if (test(x, y)) 
		{
			put(x, y, who);
			print_chessboard();
			step++;
			if (find()) 
			{
				if (who == 1)
					printf("Congratulations, You win! \n");
				else
					printf("You lose!...\n");
				return 0;
			}
		}
		else
			printf("%d %d is not permitted! please reinput.\n\n", x, y);
	}
	return 0;
}
Beispiel #3
0
void b19(int* position)
{
    const char knight  = 'K';       // symbol of Knight
    const char capture = 'X';       // symbol of captured field
    const char empty   = '.';       // symbol of empty field
    int moves[2]       = {1, 2};    // length of knight's moves: one or two cells
    int directions[2]  = {-1, 1};   // direction of knight's moves: up/down in either dimension
    char board[size][size];         // our chessboard

    // initialize board; mark all squares as empty
    for(int rank = size-1; rank >= 0; rank--)
        for(int file = 0; file < size ; file++)
            board[rank][file] = empty;

    int file = position[0];             // file is a chessboard term for a column
    int rank = position[1];             // rank is a chessboard term for a row
    board[rank][file] = knight;         // mark knight's position on board

    //
    // the BIG loop for calculating knight's captured squares
    //
    // for each direction - up or down - for rank ..
    for (int rank_direction = 0; rank_direction <= 1; rank_direction++)
    {
        // .., and for each possible move - 1 or 2 cells, on rank..
        for (int rank_move = 0; rank_move <= 1; rank_move++)
        {
            // .., and for each possible direction for file:
            for (int file_direction = 0; file_direction <= 1; file_direction++)
            {
                // calculate move per file
                // (trick is, if you move knight ONE cell right, you can move just TWO cells up or down)
                int file_move = rank_move? moves[0] : moves[1];
                int file_captured = file + directions[file_direction] * file_move;
                int rank_captured = rank + directions[rank_direction] * moves[rank_move];

                if
                (
                    // if file and rank are on board (1..8)
                    is_on_board(file_captured) &&
                    is_on_board(rank_captured)
                )
                {
                    // then mark this square as captured
                    board[rank_captured][file_captured] = capture;
                }
            }
        }
    }
    print_chessboard(board, position);
}
Beispiel #4
0
int main(void)
{
	struct chessboard *c = get_new_board();
	int tmp, sx, sy, dx, dy;

	while (1) {
		print_chessboard(c);
		/* Calcluate white's suggested move */
		tmp = calculate_move(c, 0, MOVE_DEPTH);
		sx = tmp & 0xff;
		sy = (tmp & 0xff00) >> 8;
		dx = (tmp & 0xff0000) >> 16;
		dy = (tmp & 0xff000000) >> 24;
		printf("Computer suggests (%d,%d) -> (%d,%d)\n", sx, sy, dx, dy);

no_clear:
		printf("Enter move: ");
		tmp = scanf("%d %d %d %d", &sx, &sy, &dx, &dy);
		if (tmp != 4)
			goto no_clear;

		if (sx == -1)
			return 0;

		tmp = execute_move(c, sx, sy, dx, dy);
		if (tmp) {
			printf("Error: %s\n", get_error_string(tmp));
			goto no_clear;
		} else {
			printf("Move succeeded!\n");
		}

		/* Calcluate black's move */
		tmp = calculate_move(c, 1, MOVE_DEPTH);
		sx = tmp & 0xff;
		sy = (tmp & 0xff00) >> 8;
		dx = (tmp & 0xff0000) >> 16;
		dy = (tmp & 0xff000000) >> 24;
		printf("Black moves (%d,%d) -> (%d,%d)\n", sx, sy, dx, dy);
		tmp = execute_move(c, sx, sy, dx, dy);
		if (tmp)
			fatal("Computer tried to make an illegal move: %s\n", get_error_string(tmp));
	}

	return 0;
}
Beispiel #5
0
void chessboard_ready(Chessboard *cboard) {
    cboard->bitboard = create_bitboard((void *)cboard->board, sizeof(Pawn*), 
        &bitboard_type_mapper, 1);

    print_chessboard(cboard->bitboard);
}