コード例 #1
0
ファイル: Chess.c プロジェクト: ishefi/chess
moves queen_moves(settings  * set, cord curr, int color, int is_king){
	moves all_simple_moves = bishop_moves(set, curr, color, is_king);
	if (all_simple_moves.len == -1)
		return error_moves;
	moves more_moves = rook_moves(set, curr, color, is_king);
	if (more_moves.len == -1) {
		free_list(&all_simple_moves, &free);
		return error_moves;
	}
	else
		concat(&all_simple_moves, more_moves);
	return all_simple_moves;
}
コード例 #2
0
ファイル: gen_moves.cpp プロジェクト: jason-amju/quick-chess
void gen_moves(const board& b, piece_colour pc, move* movelist, int& num_moves)
{
  for (int i = 0; i < 8; i++)
  {
    for (int j = 0; j < 8; j++)
    {
      row_col rc(i, j);
      square s = b.get(rc);
      if (pc == get_piece_colour(s))
      {
         piece_type pt = get_piece_type(s);
         switch (pt)
         {
         case NONE:
           assert(0); // only here if square contains one of our pieces
           break;
         case PAWN:
           pawn_moves(pc, rc, b, movelist, num_moves);
           break; 
         case KNIGHT:
           knight_moves(pc, rc, b, movelist, num_moves);
           break;
         case BISHOP:
           bishop_moves(pc, rc, b, movelist, num_moves);
           break;
         case ROOK:
           rook_moves(pc, rc, b, movelist, num_moves);
           break;
         case KING:
           king_moves(pc, rc, b, movelist, num_moves);
           break;
         case QUEEN:
           queen_moves(pc, rc, b, movelist, num_moves);
           break;
         }
      }
    }
  }
}
コード例 #3
0
ファイル: Chess.c プロジェクト: ishefi/chess
/*
* return the non-eat (simple) moves.
* curr = starting coordinate of the move
* max_step = length of maximal possible step (1 for man, BOARD_SIZE for king)
* in case of an error - return error_moves
*/
moves get_simple_moves(settings * set, cord curr){
	char piece = board_piece(set->board, curr);
	int color = which_color(piece);
	int type = tolower(piece);
	moves all_simple_moves = { 0 };
	switch (type)
	{
	case PAWN:
		return pawn_moves(set, curr, color);
	case BISHOP:
		return bishop_moves(set, curr, color, FALSE);
	case ROOK:
		return rook_moves(set, curr, color, FALSE);
	case KNIGHT:
		return knight_moves(set, curr, color);
	case QUEEN:
		return queen_moves(set, curr, color, FALSE);
	case KING:
		return king_moves(set, curr, color);
	default:
		return all_simple_moves;
	}
}
コード例 #4
0
ファイル: gen_moves.cpp プロジェクト: jason-amju/quick-chess
void queen_moves(piece_colour pc, const row_col& pos, const board& b, move* movelist, int& num_moves)
{
  bishop_moves(pc, pos, b, movelist, num_moves);
  rook_moves(pc, pos, b, movelist, num_moves);
}
コード例 #5
0
ファイル: move.c プロジェクト: jes/zoe
/* return the set of all squares the given piece is able to move to, without
 * considering a king left in check */
uint64_t generate_moves(Game *game, int tile) {
    Board *board = &(game->board);
    int colour = !(board->b[WHITE][OCCUPIED] & (1ull << tile));
    int type = board->mailbox[tile];
    uint64_t moves = 0;
    uint64_t blockers;

    switch(type) {
    case PAWN:
        moves = pawn_moves(board, tile);

        int x = tile % 8, y = tile / 8;

        if((game->ep == x + 1 || game->ep == x - 1) && (y == 4 - colour))
            moves |= 1ull << ((5 - colour * 3) * 8 + game->ep);
        break;

    case KNIGHT:
        moves = knight_moves[tile];
        break;

    case BISHOP:
        moves = bishop_moves(board, tile);
        break;

    case ROOK:
        moves = rook_moves(board, tile);
        break;

    case QUEEN:
        moves = bishop_moves(board, tile) | rook_moves(board, tile);
        break;

    case KING:
        moves = king_moves[tile];

        /* queenside castling */
        if(game->can_castle[colour][QUEENSIDE]) {
            blockers = ((1ull << (tile - 1)) | (1ull << (tile - 2))
                | (1ull << (tile - 3))) & board->occupied;

            /* if there are no pieces in the way and no intermediate tiles are
             * threatened, add the move
             */
            if(!blockers && !is_threatened(board, tile)
                    && !is_threatened(board, tile - 1)
                    && !is_threatened(board, tile - 2))
                moves |= 1ull << (tile - 2);
        }

        /* kingisde castling */
        if(game->can_castle[colour][KINGSIDE]) {
            blockers = ((1ull << (tile + 1)) | (1ull << (tile + 2)))
                & board->occupied;

            /* if there are no pieces in the way and no intermediate tiles are
             * threatened, add the move
             */
            if(!blockers && !is_threatened(board, tile)
                    && !is_threatened(board, tile + 1)
                    && !is_threatened(board, tile + 2))
                moves |= 1ull << (tile + 2);
        }
        break;
    }

    /* return the moves, removing the final tile if it ended on our own
     * colour.
     */
    return moves & ~board->b[colour][OCCUPIED];
}