Skip to content
Permalink
Browse files

Added new result function for State4

  • Loading branch information
joesweeney committed Apr 5, 2017
1 parent a8a92df commit 8a170ef450373ca0db4ef0aabeebe743da231427
Showing with 35 additions and 7 deletions.
  1. +27 −7 src/CheckersGameState4.java
  2. +4 −0 src/Move4.java
  3. +4 −0 src/Piece.java
@@ -120,16 +120,36 @@ char spotContains(int row, int col){
//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.
@@ -34,6 +34,10 @@ else if(dest == 3) {
return new int[2];
}

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

// Returns the string representation of a move
public String toString(){
String output = "";
@@ -8,4 +8,8 @@ public Piece(char t, int r, int c) {
_row = r;
_col = c;
}

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

0 comments on commit 8a170ef

Please sign in to comment.
You can’t perform that action at this time.