Skip to content

Commit

Permalink
Feat: Add board initialization and update getActions method
Browse files Browse the repository at this point in the history
  • Loading branch information
SverreNystad committed Jan 22, 2024
1 parent 42198de commit 30d7c95
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
public class ConnectFour implements StateHandler {

private int playerToMove;
private Board board;
private final int rowLength = 6;
private final int columnHeight = 7;

public ConnectFour() {
playerToMove = 1;
board = new Board(rowLength, columnHeight);
}

@Override
Expand All @@ -24,16 +28,18 @@ public int toMove() {
@Override
public List<Action> getActions() {
List<Action> actions = new ArrayList<Action>();
for (int i = 0; i < 7; i++) {
actions.add(new Move(i));
for (int x = 0; x < rowLength; x++) {
if (board.getPosition(x, columnHeight-1) == "") {
actions.add(new Move(x));
}
}
return actions;
}

@Override
public StateHandler result(Action action) {
this.playerToMove *= -1;
return null;
return this;
}

@Override
Expand Down

0 comments on commit 30d7c95

Please sign in to comment.