tinycodinglm / chess /chess-0015.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
1.71 kB
opencode trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

What are the basic chess tactics (fork, pin, skewer, discovered attack, deflection, back-rank mate)? Define each and show a correct python-chess material evaluation. Include code examples.

Assistant

1. Fork: one piece attacks two+ pieces at once (e.g. Nf6+ forks king and queen).
2. Pin: piece cannot move without exposing a more valuable piece (e.g. Bg5 pins Nf6 to queen).
3. Skewer: reverse pin - valuable piece attacked first, must move, exposing behind.
4. Discovered attack: moving one piece reveals an attack from another.
5. Deflection: force a defender away from its duty.
6. Back-rank mate: king trapped on 1st/8th rank by own pawns, mated by rook/queen.

python
import chess

def evaluate_material(board: chess.Board) -> int:
    values = {chess.PAWN: 1, chess.KNIGHT: 3, chess.BISHOP: 3,
              chess.ROOK: 5, chess.QUEEN: 9}
    score = 0
    for piece in board.piece_map().values():
        v = values.get(piece.piece_type, 0)
        score += v if piece.color == chess.WHITE else -v
    return score