Skip to content

Commit 19e32f3

Browse files
committed
2 parents 0f5bb41 + c1f358a commit 19e32f3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: src/connect4/connectFour/Board.java

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ public class Board implements Grid
99
private int nextPlayer;
1010
private int[][] playerAtPosition;
1111
private ArrayList<Integer> undoList;
12+
13+
public Grid clone() {
14+
Board ret = new Board(rows, cols);
15+
16+
ret.undoList = new ArrayList<Integer>(undoList);
17+
ret.playerAtPosition = new int[rows][cols];
18+
19+
for(int i = 0; i < rows; i++) {
20+
for(int j = 0; j < cols; j++) {
21+
ret.playerAtPosition[i][j] = playerAtPosition[i][j];
22+
}
23+
}
24+
25+
ret.nextPlayer = nextPlayer;
26+
27+
return ret;
28+
}
1229

1330
public Board(int rowsP, int colsP)
1431
{

Diff for: src/connect4/connectFour/Grid.java

+2
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ public interface Grid
7575
public int getWinningPlayer();
7676

7777
public void undo();
78+
79+
public Grid clone();
7880
}

0 commit comments

Comments
 (0)