Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added new result function for State4
  • Loading branch information
joesweeney committed Apr 5, 2017
1 parent a8a92df commit 8a170ef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/CheckersGameState4.java
Expand Up @@ -120,16 +120,36 @@ public class CheckersGameState4 implements CheckersGameState{
//return resulting state from taking move x
public CheckersGameState result (Move x){
Move4 m = (Move4) x;
Piece[] captures = m.capturedPieces();
//Piece[] pieces;
if(m._path.length == 4){ //only src and dest
m._piece._row = m._path[2]; //is this actually changing the piece that belongs to _pieces?
m._piece._col = m._path[3];
if(m._path[2] == 7 && m._piece._token == 'w'){
m._piece._token = 'W'; //king me
}
if(m._path[2] == 0 && m._piece._token == 'b'){
m._piece._token = 'B'; //king me
ArrayList<Piece> newPieces = new ArrayList<Piece>();
for(Piece p : _pieces){
boolean addPiece = true;
if(p == m._piece) {
Piece clone = p.clone();
clone._row = m._path[2]; //is this actually changing the piece that belongs to _pieces?
clone._col = m._path[3];
if(m._path[2] == 7 && m._piece._token == 'w'){
clone._token = 'W'; //king me
}
if(m._path[2] == 0 && m._piece._token == 'b'){
clone._token = 'B'; //king me
}
newPieces.add(clone);
addPiece = false;
}
for(Piece c : captures) {
if(c==p){
addPiece = false;
break;
}
}
if(addPiece){
newPieces.add(p.clone());
}
}
return new CheckersGameState4((_player+1)%2, newPieces);
}
//else consider jumps.
//remove from array list if captured.
Expand Down
4 changes: 4 additions & 0 deletions src/Move4.java
Expand Up @@ -34,6 +34,10 @@ public class Move4 implements Move{
return new int[2];
}

public Piece[] capturedPieces(){
return null;
}

// Returns the string representation of a move
public String toString(){
String output = "";
Expand Down
4 changes: 4 additions & 0 deletions src/Piece.java
Expand Up @@ -8,4 +8,8 @@ class Piece{
_row = r;
_col = c;
}

public Piece clone() {
return new Piece(_token, _row, _col);
}
}

0 comments on commit 8a170ef

Please sign in to comment.