getFigureAt() public method

public getFigureAt ( int row, int col ) : Figure
row int
col int
return Figure
コード例 #1
0
        // Megnézi, hogy adott figurával legális lépés-e
        public static StepType isLegalStep(Board board, int fromRow, int fromCol, int toRow, int toCol)
        {
            if (toRow < 0 || toRow >= board.getDimension()[1] || toCol < 0 || toCol >= board.getDimension()[0])
                return StepType.Failure;

            if (fromRow == toRow && fromCol == toCol)
                return StepType.Failure;

            Figure figure = board.getFigureAt(toRow, toCol);

            if (figure == null || figure.getFigureType() == FigureType.Nothing)
                return StepType.Success;

            if (Figure.isEnemy(board, fromRow, fromCol, toRow, toCol))
            {
                if (figure.getFigureType() == Figure.FigureType.King)
                    return StepType.CaptureKing;
                return StepType.Capture;
            }

            return StepType.Failure;
        }
コード例 #2
0
 // Megadja, hogy adott figurához a másik figura ellenség-e
 protected static bool isEnemy(Board board, int fr, int fc, int r, int c)
 {
     return board.getFigureAt(r, c).isWhite() != board.getFigureAt(fr, fc).isWhite();
 }
コード例 #3
0
        static bool Equals(Board b1, Board b2)
        {
            if (b1 == null || b2 == null)
                return false;

            int[] dim1 = b1.getDimension();
            int[] dim2 = b2.getDimension();

            if (dim1[0] != dim2[0] || dim1[1] != dim2[1])
                return false;

            for (int i = 0; i < dim1[1]; ++i)
                for (int j = 0; j < dim1[0]; ++j)
                    if (b1.getFigureAt(i, j).getFigureType() != b2.getFigureAt(i, j).getFigureType() ||
                        b1.getFigureAt(i, j).isWhite() != b2.getFigureAt(i, j).isWhite())
                        return false;
            return true;
        }