<commit_before>package org.lichess.compression.game;

import java.util.ArrayList;

final class Board {
    long pawns;
    long knights;
    long bishops;
    long rooks;
    long queens;
    long kings;

    long white;
    long black;
    long occupied;

    boolean turn;
    int epSquare;
    long castlingRights;

    public Board() {
        this.pawns = 0xff00000000ff00L;
        this.knights = 0x4200000000000042L;
        this.bishops = 0x2400000000000024L;
        this.rooks = 0x8100000000000081L;
        this.queens = 0x800000000000008L;
        this.kings = 0x1000000000000010L;

        this.white = 0xffffL;
        this.black = 0xffff000000000000L;
        this.occupied = 0xffff00000000ffffL;

        this.turn = true;
        this.epSquare = 0;
        this.castlingRights = this.rooks;
    }

    public Board(Board board) {
        this.pawns = board.pawns;
        this.knights = board.knights;
        this.bishops = board.bishops;
        this.rooks = board.rooks;
        this.queens = board.queens;
        this.kings = board.kings;

        this.white = board.white;
        this.black = board.black;
        this.occupied = board.occupied;

        this.turn = board.turn;
        this.epSquare = board.epSquare;
        this.castlingRights = board.castlingRights;
    }

    Board(long pawns, long knights, long bishops, long rooks, long queens, long kings,
          long white, long black,
          boolean turn, int epSquare, long castlingRights) {

        this.pawns = pawns;
        this.knights = knights;
        this.bishops = bishops;
        this.rooks = rooks;
        this.queens = queens;
        this.kings = kings;

        this.white = white;
        this.black = black;
        this.occupied = white | black;

        this.turn = turn;
        this.epSquare = epSquare;
        this.castlingRights = castlingRights;
    }

    private boolean isOccupied(int square) {
        return Bitboard.contains(this.occupied, square);
    }

    private void discard(int square) {
        long mask = ~(1L << square);

        this.pawns &= mask;
        this.knights &= mask;
        this.bishops &= mask;
        this.rooks &= mask;
        this.queens &= mask;
        this.kings &= mask;
        this.white &= mask;
        this.black &= mask;
        this.occupied &= mask;
    }

    private void put(int square, boolean color, Role role) {
        discard(square);

        long mask = 1L << square;

        switch (role) {
            case PAWN:
                this.pawns ^= mask;
                break;
            case KNIGHT:
                this.knights ^= mask;
                break;
            case BISHOP:
                this.bishops ^= mask;
                break;
            case ROOK:
                this.rooks ^= mask;
                break;
            case QUEEN:
                this.queens ^= mask;
                break;
            case KING:
                this.kings ^= mask;
                break;
        }

        if (color) this.white ^= mask;
        else this.black ^= mask;
<commit_msg>make switch in put() a bit more compact<commit_after>package org.lichess.compression.game;

import java.util.ArrayList;

final class Board {
    long pawns;
    long knights;
    long bishops;
    long rooks;
    long queens;
    long kings;

    long white;
    long black;
    long occupied;

    boolean turn;
    int epSquare;
    long castlingRights;

    public Board() {
        this.pawns = 0xff00000000ff00L;
        this.knights = 0x4200000000000042L;
        this.bishops = 0x2400000000000024L;
        this.rooks = 0x8100000000000081L;
        this.queens = 0x800000000000008L;
        this.kings = 0x1000000000000010L;

        this.white = 0xffffL;
        this.black = 0xffff000000000000L;
        this.occupied = 0xffff00000000ffffL;

        this.turn = true;
        this.epSquare = 0;
        this.castlingRights = this.rooks;
    }

    public Board(Board board) {
        this.pawns = board.pawns;
        this.knights = board.knights;
        this.bishops = board.bishops;
        this.rooks = board.rooks;
        this.queens = board.queens;
        this.kings = board.kings;

        this.white = board.white;
        this.black = board.black;
        this.occupied = board.occupied;

        this.turn = board.turn;
        this.epSquare = board.epSquare;
        this.castlingRights = board.castlingRights;
    }

    Board(long pawns, long knights, long bishops, long rooks, long queens, long kings,
          long white, long black,
          boolean turn, int epSquare, long castlingRights) {

        this.pawns = pawns;
        this.knights = knights;
        this.bishops = bishops;
        this.rooks = rooks;
        this.queens = queens;
        this.kings = kings;

        this.white = white;
        this.black = black;
        this.occupied = white | black;

        this.turn = turn;
        this.epSquare = epSquare;
        this.castlingRights = castlingRights;
    }

    private boolean isOccupied(int square) {
        return Bitboard.contains(this.occupied, square);
    }

    private void discard(int square) {
        long mask = ~(1L << square);

        this.pawns &= mask;
        this.knights &= mask;
        this.bishops &= mask;
        this.rooks &= mask;
        this.queens &= mask;
        this.kings &= mask;
        this.white &= mask;
        this.black &= mask;
        this.occupied &= mask;
    }

    private void put(int square, boolean color, Role role) {
        discard(square);

        long mask = 1L << square;

        switch (role) {
            case PAWN: this.pawns ^= mask; break;
            case KNIGHT: this.knights ^= mask; break;
            case BISHOP: this.bishops ^= mask; break;
            case ROOK: this.rooks ^= mask; break;
            case QUEEN: this.queens ^= mask; break;
            case KING: this.kings ^= mask; break;
        }

        if (color) this.white ^= mask;
        else this.black ^= mask;

{'fraction_non_alphanumeric': 0.09611520428667113, 'fraction_numerical': 0.0405224380442063, 'mean_word_length': 1.739908256880734, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 16, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1885046', 'n_tokens_mistral': 2101, 'n_tokens_neox': 1820, 'n_words': 439}