package de.fesere.tictactoe.model;

public class Board {

    Marker[][] rows = new Marker[3][3];

    public Board() {
        initializeRows();
    }

    private void initializeRows() {
        for (int i = 0; i < rows.length; i++) {
            initilizeRow(i);
        }
    }

    private void initilizeRow(int rowIndex) {
        for (int i = 0; i < rows[rowIndex].length; i++) {
            rows[rowIndex][i] = Marker.EMPTY;
        }
    }


    public Line getRow(int rowIndex) {
        return new Line(rows[rowIndex]);
    }

    public Line getColumn(int columnIndex) {
        Marker[] columnMarkers = getColumnMarkers(columnIndex);
        return new Line(columnMarkers);
    }

    private Marker[] getColumnMarkers(int columnIndex) {
        Marker[] result = new Marker[3];
        for (int i = 0; i < 3; i++) {
            result[i] = rows[i][columnIndex];
        }

        return result;
    }

    public Line getDiagonal(Diagonal diagonal) {
        Marker[] diagonalMarkers = getDiagonalMarkers(diagonal);

        return new Line(diagonalMarkers);
    }

    private Marker[] getDiagonalMarkers(Diagonal diagonal) {
        Marker[] diagonalMarkers = new Marker[3];
        for (int i = 0; i < 3; i++) {
            diagonalMarkers[i] = rows[diagonal.counter(i)][i];
        }
        return diagonalMarkers;
    }

    public Board mark(int rowIndex, int columnIndex, Marker marker) {
        rows[rowIndex][columnIndex] = marker;
        return this;
    }
}

@@ -29,16 +29,42 @@
 model;%0A%0A
+import java.util.Arrays;%0A%0A
 public c
@@ -164,32 +164,389 @@
 eRows();%0A    %7D%0A%0A
+    public Board(Board board, int markedRow, int markedColumn, Marker marker) %7B%0A        duplicateBoard(board);%0A        rows%5BmarkedRow%5D%5BmarkedColumn%5D = marker;%0A    %7D%0A%0A    private void duplicateBoard(Board board) %7B%0A        for(int rowIndex = 0; rowIndex %3C 3; rowIndex++) %7B%0A            rows%5BrowIndex%5D = Arrays.copyOf(board.rows%5BrowIndex%5D, 3);%0A        %7D%0A    %7D%0A%0A
     private void
@@ -1797,28 +1797,46 @@
        r
-ows%5B
+eturn new Board(this, 
 rowIndex
 %5D%5Bcolumn
@@ -1827,18 +1827,18 @@
 rowIndex
-%5D%5B
+, 
 columnIn
@@ -1844,39 +1844,17 @@
 ndex
-%5D =
+,
  marker
-;%0A        return this
+)
 ;%0A  

Make the board immutable