Skip to content

Commit

Permalink
Adding method to get all the positions of all pieces in a board.
Browse files Browse the repository at this point in the history
  • Loading branch information
skytreader committed Oct 19, 2014
1 parent d85b2a7 commit 226d76f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/skytreader/kode/chesstemplar/Board.java
Expand Up @@ -2,6 +2,8 @@

import java.awt.Point;

import java.util.Set;

import net.skytreader.kode.chesstemplar.pieces.ChessPiece;

/**
Expand Down Expand Up @@ -30,6 +32,11 @@ public interface Board{
null if it is not.
*/
public ChessPiece getPieceAt(int r, int c);

/**
Get a list of positions where there are pieces on the board.
*/
public Set<Point> getPiecePositions();

/**
Move the piece at the location (r1, c1) to location (r2, c2).
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/skytreader/kode/chesstemplar/GridBoard.java
Expand Up @@ -2,6 +2,9 @@

import java.awt.Point;

import java.util.HashSet;
import java.util.Set;

import net.skytreader.kode.chesstemplar.pieces.Bishop;
import net.skytreader.kode.chesstemplar.pieces.ChessPiece;
import net.skytreader.kode.chesstemplar.pieces.King;
Expand Down Expand Up @@ -176,6 +179,11 @@ public ChessPiece getPieceAt(int r, int c){
}
}

@Override
public Set<Point> getPiecePositions(){
return null;
}

@Override
public void move(int r1, int c1, int r2, int c2){
lastSrc = new Point(r1, c1);
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/net/skytreader/kode/chesstemplar/GridBoardTest.java
Expand Up @@ -3,6 +3,8 @@
import java.awt.Point;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import net.skytreader.kode.chesstemplar.pieces.Bishop;
import net.skytreader.kode.chesstemplar.pieces.ChessPiece;
Expand Down Expand Up @@ -101,6 +103,21 @@ public void testRemovePiece(){
testBoard.removePiece(0, 0);
Assert.assertNull(testBoard.getPieceAt(0, 0));
}

@Test
public void testGetPiecePositions(){
Board testBoard = new GridBoard();
HashSet<Point> initialConfig = new HashSet<Point>();

for(int i = 0; i < 8; i++){
initialConfig.add(new Point(0, i));
initialConfig.add(new Point(1, i));
initialConfig.add(new Point(6, i));
initialConfig.add(new Point(7, i));
}

Assert.assertEquals(initialConfig, testBoard.getPiecePositions());
}

/**
We just want to know that the toString() method returns an 8x8 grid.
Expand Down

0 comments on commit 226d76f

Please sign in to comment.