package com.dairymoose.modernlife.blocks.gui.chess;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/chess/KingPiece.class */
public class KingPiece extends Piece {
    private static final Logger LOGGER = LogManager.getLogger();

    public boolean inCheck() {
        if (this.black) {
            for (Piece p : this.screen.whitePieces) {
                p.ignoreCheckRules = true;
                boolean canKillKing = p.canMove(this.f9x, this.f10y);
                p.ignoreCheckRules = false;
                if (canKillKing) {
                    return true;
                }
            }
            return false;
        }
        for (Piece p2 : this.screen.blackPieces) {
            p2.ignoreCheckRules = true;
            boolean canKillKing2 = p2.canMove(this.f9x, this.f10y);
            p2.ignoreCheckRules = false;
            if (canKillKing2) {
                return true;
            }
        }
        return false;
    }

    @Override // com.dairymoose.modernlife.blocks.gui.chess.Piece
    public boolean canMove(int x, int y) {
        int xDiff = x - this.f9x;
        int yDiff = y - this.f10y;
        if (Math.abs(xDiff) <= 1 && Math.abs(yDiff) <= 1 && !wouldCollide(x, y) && canDoMove(x, y)) {
            int originalX = this.f9x;
            int originalY = this.f10y;
            this.f9x = x;
            this.f10y = y;
            if (inCheck()) {
                this.f9x = originalX;
                this.f10y = originalY;
                return false;
            }
            this.f9x = originalX;
            this.f10y = originalY;
            return true;
        }
        return false;
    }

    @Override // com.dairymoose.modernlife.blocks.gui.chess.Piece
    public int getId() {
        return PieceIds.KING.ordinal();
    }
}
