package ru.job4j.chess.model;

import ru.job4j.chess.exceptions.FigureNotFoundException;
import ru.job4j.chess.exceptions.ImpossibleMoveException;
import ru.job4j.chess.exceptions.OccupiedWayException;

/**
 * This class describes board of chess.
 *
 * @author Kuvykh Vasily (mailto:basil135@mail.ru)
 * @version $Id$
 * @since 20.04.2017
 */
public class Board {

    /**
     * parameter size is size of a square bord of chess.
     */
    private int size = 8;
    /**
     * parameter figure is a figure of chess that shoud be move.
     */
    private Figure figure;
    /**
     * parameter figures is double array of figures as board of chess.
     */
    private Figure[][] figures = new Figure[size][size];

    /**
     * method take a figure from figures array at position cell and return it.
     *
     * @param cell is position of figure at figures array
     * @return return a figure at position cell
     */
    public Figure getFigure(final Cell cell) {
        return this.figures[cell.getX()][cell.getY()];
    }

    /**
     * method set a figure to array figures to position cell.
     *
     * @param cell is position at array figures
     */
    public void setFigure(final Cell cell) {
        this.figure = figures[cell.getX()][cell.getY()];
    }

    /**
     * method tests figure to move from source position to destination position.
     *
     * @param source is a source position at array figures
     * @param dest is destination position at array figures
     * @return true if figure set at destination position and remove from source position
     * @throws ImpossibleMoveException if figure can't be moved like that
     * @throws OccupiedWayException if way of figure is occupied by other figures
     * @throws FigureNotFoundException if figure is not found at source position
     */
    public boolean move(final Cell source, final Cell dest) throws ImpossibleMoveException,
                                                                    OccupiedWayException, FigureNotFoundException {

        figure = getFigure(source);

        if (figure == null) {
            throw new FigureNotFoundException();
        }

        Cell[] way = figure.way(dest);

        for (Cell cell : way) {
            if (getFigure(cell) != null) {
                throw new OccupiedWayException();
            }
        }

        setFigure(dest);
        figure = null;
        setFigure(source);

        return true;

    }

}

@@ -469,116 +469,8 @@
 /**%0A
-     * parameter figure is a figure of chess that shoud be move.%0A     */%0A    private Figure figure;%0A    /**%0A
     
@@ -722,43 +722,25 @@
  is 
-position of figure at figures array
+cell of the board
 %0A   
@@ -766,33 +766,16 @@
 a figure
- at position cell
 %0A     */
@@ -979,41 +979,24 @@
 ram 
-cell is position at array
+figure is
  figure
-s
 %0A   
@@ -1028,33 +1028,37 @@
 igure(final 
-Cell cell
+Figure figure
 ) %7B%0A        
@@ -1072,44 +1072,66 @@
 gure
- = 
+s%5B
 figure
-s%5Bcell.getX()%5D%5Bcell.getY()%5D
+.position.getX()%5D%5Bfigure.position.getY()%5D = figure
 ;%0A  
@@ -1894,32 +1894,39 @@
 tion %7B%0A%0A        
+Figure 
 figure = getFigu
@@ -1922,25 +1922,45 @@
 e = 
-getFigure(source)
+figures%5Bsource.getX()%5D%5Bsource.getY()%5D
 ;%0A%0A 
@@ -2116,24 +2116,25 @@
 ll : way) %7B%0A
+%0A
             
@@ -2141,34 +2141,248 @@
 if (
-getFigure(cell) != null) %7B
+figures%5Bcell.getX()%5D%5Bcell.getY()%5D != null) %7B%0A                if (dest.getX() == cell.getX() && figures%5Bcell.getX()%5D%5Bcell.getY()%5D.fraction != figure.fraction && figure.getClass() != Pawn.class) %7B%0A                    break;%0A                %7D%0A
 %0A   
@@ -2420,32 +2420,33 @@
 WayException();%0A
+%0A
             %7D%0A  
@@ -2466,23 +2466,32 @@
     
-setF
+//f
 igure
-(
+.position = 
 dest
-)
 ;%0A  
@@ -2506,15 +2506,44 @@
 gure
- = null
+s%5Bdest.getX()%5D%5Bdest.getY()%5D = figure
 ;%0A  
@@ -2552,25 +2552,52 @@
     
-setF
+f
 igure
-(source)
+s%5Bsource.getX()%5D%5Bsource.getY()%5D = null
 ;%0A%0A 

Refactor Board.java