示例#1
0
static void write_transfer(output_plaintext_move_context_type *context,
                           move_effect_journal_index_type removal,
                           move_effect_journal_index_type addition)
{
  next_context(context,removal,"[","]");

  write_complete_piece(context,
                       move_effect_journal[removal].u.piece_removal.flags,
                       move_effect_journal[removal].u.piece_removal.walk,
                       move_effect_journal[removal].u.piece_removal.on);

  (*context->engine->fprintf)(context->file,"%s",(*context->symbol_table)[output_symbol_right_arrow]);

  if (move_effect_journal[removal].u.piece_removal.flags
      !=move_effect_journal[addition].u.piece_addition.added.flags
      || (TSTFLAG(move_effect_journal[addition].u.piece_addition.added.flags,Royal)
          && is_king(move_effect_journal[removal].u.piece_removal.walk)
          && !is_king(move_effect_journal[addition].u.piece_addition.added.walk)))
  {
    WriteSpec(context->engine,context->file,
               move_effect_journal[addition].u.piece_addition.added.flags,
               move_effect_journal[addition].u.piece_addition.added.walk,
               false);
    WriteWalk(context->engine,context->file,move_effect_journal[addition].u.piece_addition.added.walk);
  }
  else if (move_effect_journal[removal].u.piece_removal.walk
           !=move_effect_journal[addition].u.piece_addition.added.walk)
    WriteWalk(context->engine,context->file,move_effect_journal[addition].u.piece_addition.added.walk);

  WriteSquare(context->engine,context->file,move_effect_journal[addition].u.piece_addition.added.on);
}
示例#2
0
// finds moves with chained captures
int get_capture_moves(Pos start, Pos piece, char board[BOARD_SIZE][BOARD_SIZE], COLOR player, int count, Pos* dests){
	Pos pos[4] = { { piece.col - 1, piece.row - 1 }, { piece.col + 1, piece.row - 1 }, { piece.col - 1, piece.row + 1 }, { piece.col + 1, piece.row + 1 } };
	int found_now = 0, found_ahead = -1;
	for (int p = 0; p < 4; p++)
		if (is_valid_pos(pos[p]) && is_opposite(player, board[pos[p].col][pos[p].row])){
		Pos new_piece = get_next_diag(piece, pos[p]);
		if (is_valid_pos(new_piece) && board[new_piece.col][new_piece.row] == EMPTY){
			found_now++;
			char tmp = board[pos[p].col][pos[p].row];
			board[pos[p].col][pos[p].row] = EMPTY;
			Pos* new_dests = malloc(sizeof(Pos) * (count + 1));
			for (int i = 0; i < count; i++){
				new_dests[i].row = dests[i].row;
				new_dests[i].col = dests[i].col;
			}
			new_dests[count].row = new_piece.row;
			new_dests[count].col = new_piece.col;
			if (!(is_EOB(new_piece, player) && !is_king(curr_piece))) found_ahead = get_capture_moves(start, new_piece, board, player, count + 1, new_dests);
			if (found_ahead == 0 || (is_EOB(new_piece, player) && !is_king(curr_piece))){ add_move(start, new_dests, count + 1); }
			free(new_dests);
			board[pos[p].col][pos[p].row] = tmp;
		}
		}
	return found_now;
}
示例#3
0
boolean WriteSpec(output_engine_type const * engine, FILE *file,
                  Flags sp, piece_walk_type p, boolean printcolours)
{
  boolean result = false;

  if (is_piece_neutral(sp))
  {
    (*engine->fputc)(tolower(ColourTab[colour_neutral][0]),file);
    result = true;
  }
  else if (printcolours)
  {
    if (areColorsSwapped)
    {
      if (TSTFLAG(sp,White))
        (*engine->fputc)(tolower(ColourTab[colour_black][0]),file);
      if (TSTFLAG(sp,Black))
        (*engine->fputc)(tolower(ColourTab[colour_white][0]),file);
    }
    else
    {
      if (TSTFLAG(sp,White))
        (*engine->fputc)(tolower(ColourTab[colour_white][0]),file);
      if (TSTFLAG(sp,Black))
        (*engine->fputc)(tolower(ColourTab[colour_black][0]),file);
    }
  }

  {
    piece_flag_type spname;
    for (spname = nr_sides; spname<nr_piece_flags; ++spname)
      if ((spname!=Volage || !CondFlag[volage])
          && (spname!=Patrol || !CondFlag[patrouille])
          && (spname!=Beamtet || !CondFlag[beamten])
          && (spname!=Royal || !is_king(p))
          && TSTFLAG(sp, spname))
      {
        char const *curr = PieSpTab[spname-nr_sides];
        while (*curr!=0)
        {
          if (isupper(*curr))
            (*engine->fputc)(tolower(*curr),file);
          ++curr;
        }
        result = true;
      }
  }

  return result;
}
示例#4
0
Move * get_all_moves(char board[BOARD_SIZE][BOARD_SIZE], COLOR player){
	clear_old_moves(moves_head);
	Pos p;
	for (int i = 0; i < BOARD_SIZE; i++)
		for (int j = 0; j < BOARD_SIZE; j++)
			if (!is_opposite(player, board[i][j]) && board[i][j] != EMPTY){
		p.row = j;
		p.col = i;
		if (is_king(board[i][j])) get_king_moves(board, player, p);
		else get_man_moves(board, player, p);
			}
	return moves_head;
	// need to handle man becoming kings
}
示例#5
0
Move * get_all_moves(char board[BOARD_SIZE][BOARD_SIZE], COLOR player){
	moves_head = NULL;
	moves = NULL;
	Pos p;
	for (int i = 0; i < BOARD_SIZE; i++)
		for (int j = 0; j < BOARD_SIZE; j++)
			if (!is_opposite(player, board[i][j]) && board[i][j] != EMPTY){
		p.row = j;
		p.col = i;
		curr_piece = board[i][j];
		if (is_king(curr_piece)) get_king_moves(board, player, p);
		else get_man_moves(board, player, p);
			}
	return moves_head;
}
示例#6
0
//------------------------------------------------------------------------------
Position *new_position(char *white, char *black) {
    tree[node] = (Position){};
    Position *self = &tree[node];

    setup_side(self, white, White);
    setup_side(self, black, Black);

    self->castles = castleKingside[White] | castleQueenside[White] | castleKingside[Black] | castleQueenside[Black];
    if (self->pieces[E1] != King || self->pieces[H1] != Rook) {
        self->castles &= ~castleKingside[White];
    }
    if (self->pieces[E1] != King || self->pieces[A1] != Rook) {
        self->castles &= ~castleQueenside[White];
    }
    if (self->pieces[E8] != BlackKing || self->pieces[H8] != BlackRook) {
        self->castles &= ~castleKingside[Black];
    }
    if (self->pieces[E8] != BlackKing || self->pieces[A8] != BlackRook) {
        self->castles &= ~castleQueenside[Black];
    }

    for (int sq = A1; sq < len(self->pieces); sq++) {
        Piece piece = self->pieces[sq];
        if (piece != 0) {
            self->outposts[piece] |= bit[sq];
            self->outposts[color(piece)] |= bit[sq];
            if (is_king(piece)) {
                self->king[color(piece)] = (uint8)sq;
            }
            self->balance += materialBalance[piece];
        }
    }

    self->reversible = true;
    self->board = self->outposts[White] | self->outposts[Black];

    polyglot(self);  // Calculate self->id and self->pawnId.
    valuation(self); // Calculate self->tally.

    return &tree[node];
}
示例#7
0
char get_chesspiece(char p)
{
    if (is_king(p))
        return KING;

    if (is_queen(p))
        return QUEEN;

    if (is_rook(p))
        return ROOK;

    if (is_bishop(p))
        return BISHOP;

    if (is_knight(p))
        return KNIGHT;

    if (is_pawn(p))
        return PAWN;

    return ERROR;
}
示例#8
0
void print_chesspiece(char p, FILE * f)
{
    char output, black;

    output = '?';

    if (is_black(p))
        black = 1;
    else
        black = 0;

    if (is_king(p))
        output = 'K';

    if (is_queen(p))
        output = 'Q';

    if (is_rook(p))
        output = 'R';

    if (is_bishop(p))
        output = 'B';

    if (is_knight(p))
        output = 'N';

    if (is_pawn(p))
        output = 'P';

    if (black)
        output += 'a' - 'A';

    if (is_free(p))
        output = ' ';

    fprintf(f, "%c", output);
}