diff --git a/src/CheckersGameState4.java b/src/CheckersGameState4.java index a889c89..51ca040 100644 --- a/src/CheckersGameState4.java +++ b/src/CheckersGameState4.java @@ -24,22 +24,27 @@ public class CheckersGameState4 implements CheckersGameState{ _player = player; } public static void main(String[] args){ //for testing - // Random r = new Random(); - // CheckersGameState4 state = new CheckersGameState4(); - // System.out.println("This is the initial board followed by an entire game played."); - // System.out.println("We do this by always choosing a random move."); - // state.printState(); - // List actions = state.actions(); - // while(actions.size() > 0){ - // for(Move move : actions) { - // System.out.println(move+" ~~ "); - // } - // state = (CheckersGameState4)state.result(actions.get(r.nextInt(actions.size()))); - // state.printState(); - // actions = state.actions(); - //} + Random r = new Random(); + CheckersGameState4 state = new CheckersGameState4(); + System.out.println("This is the initial board followed by an entire game played."); + System.out.println("We do this by always choosing a random move."); + state.printState(); + List actions = state.actions(); + while(actions.size() > 0){ + System.out.println("Possible actions: "); + for(Move move : actions) { + System.out.println(move); + } + + Move action = actions.get(r.nextInt(actions.size())); + System.out.println("Chosen action: " + action); + state = (CheckersGameState4)state.result(action); + state.printState(); + actions = state.actions(); + } + System.out.println("Diamond Test Case"); ArrayList p = new ArrayList(); - p.add(new Piece('b', 5, 2)); + p.add(new Piece('B', 5, 2)); p.add(new Piece('w', 4, 1)); p.add(new Piece('w', 4, 3)); p.add(new Piece('w', 2, 3)); @@ -49,6 +54,7 @@ public class CheckersGameState4 implements CheckersGameState{ for(Move m: cg.actions()){ System.out.println(m); } + //cg.printState(); } @@ -120,11 +126,8 @@ public class CheckersGameState4 implements CheckersGameState{ for(int i = 0; i<4; i++){ if(neigh[i] == 'x') avail.add(new Move4(p, i)); if(isJump(p._row, p._col, i, neigh)){ - System.out.println("Jump Available"); jumps.addAll(computeJumps(p, i, null)); - System.out.println("" + jumps.isEmpty()); - } //do something with this - //check for jumps + } } } } @@ -138,7 +141,9 @@ public class CheckersGameState4 implements CheckersGameState{ jumpto = dest(jumpto[0], jumpto[1], index); Piece item = spotContains(jumpto[0], jumpto[1]); if(item!=null){ - if(item._empty) return true; + if(item._empty) { + return true; + } } } return false; @@ -148,24 +153,28 @@ public class CheckersGameState4 implements CheckersGameState{ int[] nextSpot = dest(p, neighborIndex); Piece captured = spotContains(nextSpot[0], nextSpot[1]); Move4 last = lastMove; + int saverow = p._row; + int savecol = p._col; if(last == null) { // This is the first jump // Make our move last = new Move4(p, dest(captured, neighborIndex), captured); } + p._row = -1; + p._col = -1; // Check to see if we can keep going // if we can, jumps.addAll(computeJumps(p, newgoodindex, nextMove)) // else, add(nextMove) int lastRow = last._path[last._path.length-2]; - int lastCol = last._path[last._path.length-2]; + int lastCol = last._path[last._path.length-1]; Piece[] newneighbors = neighborPieces(lastRow, lastCol, p); for(int i = 0; i newPieces = new ArrayList(); for(Piece p : _pieces){ boolean addPiece = true; if(p == m._piece) { Piece clone = p.clone(); - clone._row = m._path[m._path.length-2]; //is this actually changing the piece that belongs to _pieces? + clone._row = m._path[m._path.length-2]; clone._col = m._path[m._path.length-1]; - if(m._path[2] == 7 && m._piece._token == 'w'){ + if(m._path[m._path.length-2] == 7 && m._piece._token == 'w'){ clone._token = 'W'; //king me } - if(m._path[2] == 0 && m._piece._token == 'b'){ + if(m._path[m._path.length-2] == 0 && m._piece._token == 'b'){ clone._token = 'B'; //king me } newPieces.add(clone); @@ -259,14 +274,15 @@ public class CheckersGameState4 implements CheckersGameState{ } } return new CheckersGameState4((_player+1)%2, newPieces); - } - return null; + //} +// return null; } public void printState (){ char[][] board = new char[8][8]; for(Piece p: _pieces){ board[p._row][p._col] = p._token; } + System.out.println("player: " + player()); for(int i = 7; i>=0; i--){ for(int j= 0; j<8; j++){ if(board[i][j]== '\u0000') System.out.print("-"); @@ -274,5 +290,6 @@ public class CheckersGameState4 implements CheckersGameState{ } System.out.println(""); } + System.out.println(""); } } diff --git a/src/output4.txt b/src/output4.txt new file mode 100644 index 0000000..200724a --- /dev/null +++ b/src/output4.txt @@ -0,0 +1,984 @@ +This is the initial board followed by an entire game played. +We do this by always choosing a random move. +player: black +-b-b-b-b +b-b-b-b- +-b-b-b-b +-------- +-------- +w-w-w-w- +-w-w-w-w +w-w-w-w- + +Possible actions: +(5:1)(4:0) +(5:1)(4:2) +(5:3)(4:2) +(5:3)(4:4) +(5:5)(4:4) +(5:5)(4:6) +(5:7)(4:6) +Chosen action: (5:5)(4:4) +player: white +-b-b-b-b +b-b-b-b- +-b-b---b +----b--- +-------- +w-w-w-w- +-w-w-w-w +w-w-w-w- + +Possible actions: +(2:0)(3:1) +(2:2)(3:1) +(2:2)(3:3) +(2:4)(3:3) +(2:4)(3:5) +(2:6)(3:5) +(2:6)(3:7) +Chosen action: (2:2)(3:3) +player: black +-b-b-b-b +b-b-b-b- +-b-b---b +----b--- +---w---- +w---w-w- +-w-w-w-w +w-w-w-w- + +Possible actions: +(4:4)(2:2) +Chosen action: (4:4)(2:2) +player: white +-b-b-b-b +b-b-b-b- +-b-b---b +-------- +-------- +w-b-w-w- +-w-w-w-w +w-w-w-w- + +Possible actions: +(1:1)(3:3) +(1:3)(3:1) +Chosen action: (1:3)(3:1) +player: black +-b-b-b-b +b-b-b-b- +-b-b---b +-------- +-w------ +w---w-w- +-w---w-w +w-w-w-w- + +Possible actions: +(6:4)(5:5) +(6:6)(5:5) +(5:1)(4:0) +(5:1)(4:2) +(5:3)(4:2) +(5:3)(4:4) +(5:7)(4:6) +Chosen action: (5:3)(4:2) +player: white +-b-b-b-b +b-b-b-b- +-b-----b +--b----- +-w------ +w---w-w- +-w---w-w +w-w-w-w- + +Possible actions: +(3:1)(5:3) +Chosen action: (3:1)(5:3) +player: black +-b-b-b-b +b-b-b-b- +-b-w---b +-------- +-------- +w---w-w- +-w---w-w +w-w-w-w- + +Possible actions: +(6:2)(4:4) +(6:4)(4:2) +Chosen action: (6:4)(4:2) +player: white +-b-b-b-b +b-b---b- +-b-----b +--b----- +-------- +w---w-w- +-w---w-w +w-w-w-w- + +Possible actions: +(2:0)(3:1) +(2:4)(3:3) +(2:4)(3:5) +(2:6)(3:5) +(2:6)(3:7) +(1:1)(2:2) +(0:2)(1:3) +(0:4)(1:3) +Chosen action: (2:6)(3:5) +player: black +-b-b-b-b +b-b---b- +-b-----b +--b----- +-----w-- +w---w--- +-w---w-w +w-w-w-w- + +Possible actions: +(7:3)(6:4) +(7:5)(6:4) +(6:2)(5:3) +(4:2)(3:1) +(4:2)(3:3) +(6:6)(5:5) +(5:1)(4:0) +(5:7)(4:6) +Chosen action: (7:3)(6:4) +player: white +-b---b-b +b-b-b-b- +-b-----b +--b----- +-----w-- +w---w--- +-w---w-w +w-w-w-w- + +Possible actions: +(2:0)(3:1) +(2:4)(3:3) +(3:5)(4:4) +(3:5)(4:6) +(1:1)(2:2) +(1:5)(2:6) +(1:7)(2:6) +(0:2)(1:3) +(0:4)(1:3) +Chosen action: (0:2)(1:3) +player: black +-b---b-b +b-b-b-b- +-b-----b +--b----- +-----w-- +w---w--- +-w-w-w-w +w---w-w- + +Possible actions: +(6:4)(5:3) +(6:4)(5:5) +(6:2)(5:3) +(4:2)(3:1) +(4:2)(3:3) +(6:6)(5:5) +(5:1)(4:0) +(5:7)(4:6) +Chosen action: (5:1)(4:0) +player: white +-b---b-b +b-b-b-b- +-------b +b-b----- +-----w-- +w---w--- +-w-w-w-w +w---w-w- + +Possible actions: +(2:0)(3:1) +(2:4)(3:3) +(3:5)(4:4) +(3:5)(4:6) +(1:1)(2:2) +(1:5)(2:6) +(1:7)(2:6) +(1:3)(2:2) +Chosen action: (1:1)(2:2) +player: black +-b---b-b +b-b-b-b- +-------b +b-b----- +-----w-- +w-w-w--- +---w-w-w +w---w-w- + +Possible actions: +(6:4)(5:3) +(6:4)(5:5) +(6:0)(5:1) +(6:2)(5:1) +(6:2)(5:3) +(4:2)(3:1) +(4:2)(3:3) +(6:6)(5:5) +(4:0)(3:1) +(5:7)(4:6) +Chosen action: (6:0)(5:1) +player: white +-b---b-b +--b-b-b- +-b-----b +b-b----- +-----w-- +w-w-w--- +---w-w-w +w---w-w- + +Possible actions: +(2:0)(3:1) +(2:4)(3:3) +(3:5)(4:4) +(3:5)(4:6) +(2:2)(3:1) +(2:2)(3:3) +(1:5)(2:6) +(1:7)(2:6) +(0:0)(1:1) +Chosen action: (1:7)(2:6) +player: black +-b---b-b +--b-b-b- +-b-----b +b-b----- +-----w-- +w-w-w-w- +---w-w-- +w---w-w- + +Possible actions: +(7:1)(6:0) +(6:4)(5:3) +(6:4)(5:5) +(6:2)(5:3) +(4:2)(3:1) +(4:2)(3:3) +(6:6)(5:5) +(4:0)(3:1) +(5:7)(4:6) +Chosen action: (7:1)(6:0) +player: white +-----b-b +b-b-b-b- +-b-----b +b-b----- +-----w-- +w-w-w-w- +---w-w-- +w---w-w- + +Possible actions: +(2:0)(3:1) +(2:4)(3:3) +(3:5)(4:4) +(3:5)(4:6) +(2:2)(3:1) +(2:2)(3:3) +(2:6)(3:7) +(0:0)(1:1) +(0:6)(1:7) +Chosen action: (3:5)(4:4) +player: black +-----b-b +b-b-b-b- +-b-----b +b-b-w--- +-------- +w-w-w-w- +---w-w-- +w---w-w- + +Possible actions: +(6:4)(5:3) +(6:4)(5:5) +(6:2)(5:3) +(4:2)(3:1) +(4:2)(3:3) +(6:6)(5:5) +(4:0)(3:1) +(5:7)(4:6) +Chosen action: (4:2)(3:3) +player: white +-----b-b +b-b-b-b- +-b-----b +b---w--- +---b---- +w-w-w-w- +---w-w-- +w---w-w- + +Possible actions: +(2:4)(4:2) +Chosen action: (2:4)(4:2) +player: black +-----b-b +b-b-b-b- +-b-----b +b-w-w--- +-------- +w-w---w- +---w-w-- +w---w-w- + +Possible actions: +(5:1)(3:3)(1:1) +Chosen action: (5:1)(3:3)(1:1) +player: white +-----b-b +b-b-b-b- +-------b +b---w--- +-------- +w-----w- +-b-w-w-- +w---w-w- + +Possible actions: +(0:0)(2:2) +Chosen action: (0:0)(2:2) +player: black +-----b-b +b-b-b-b- +-------b +b---w--- +-------- +w-w---w- +---w-w-- +----w-w- + +Possible actions: +(6:0)(5:1) +(6:4)(5:3) +(6:4)(5:5) +(6:2)(5:1) +(6:2)(5:3) +(6:6)(5:5) +(4:0)(3:1) +(5:7)(4:6) +Chosen action: (4:0)(3:1) +player: white +-----b-b +b-b-b-b- +-------b +----w--- +-b------ +w-w---w- +---w-w-- +----w-w- + +Possible actions: +(2:0)(4:2) +(2:2)(4:0) +Chosen action: (2:2)(4:0) +player: black +-----b-b +b-b-b-b- +-------b +w---w--- +-------- +w-----w- +---w-w-- +----w-w- + +Possible actions: +(6:0)(5:1) +(6:4)(5:3) +(6:4)(5:5) +(6:2)(5:1) +(6:2)(5:3) +(6:6)(5:5) +(5:7)(4:6) +Chosen action: (6:4)(5:5) +player: white +-----b-b +b-b---b- +-----b-b +w---w--- +-------- +w-----w- +---w-w-- +----w-w- + +Possible actions: +(2:0)(3:1) +(4:4)(5:3) +(1:5)(2:4) +(2:6)(3:5) +(2:6)(3:7) +(4:0)(5:1) +(1:3)(2:2) +(1:3)(2:4) +(0:6)(1:7) +Chosen action: (4:0)(5:1) +player: black +-----b-b +b-b---b- +-w---b-b +----w--- +-------- +w-----w- +---w-w-- +----w-w- + +Possible actions: +(6:0)(4:2) +(5:5)(3:3) +(6:2)(4:0) +Chosen action: (6:2)(4:0) +player: white +-----b-b +b-----b- +-----b-b +b---w--- +-------- +w-----w- +---w-w-- +----w-w- + +Possible actions: +(2:0)(3:1) +(4:4)(5:3) +(1:5)(2:4) +(2:6)(3:5) +(2:6)(3:7) +(1:3)(2:2) +(1:3)(2:4) +(0:6)(1:7) +Chosen action: (1:3)(2:2) +player: black +-----b-b +b-----b- +-----b-b +b---w--- +-------- +w-w---w- +-----w-- +----w-w- + +Possible actions: +(5:5)(3:3)(1:1) +Chosen action: (5:5)(3:3)(1:1) +player: white +-----b-b +b-----b- +-------b +b------- +-------- +w-----w- +-b---w-- +----w-w- + +Possible actions: +(2:0)(3:1) +(1:5)(2:4) +(2:6)(3:5) +(2:6)(3:7) +(0:4)(1:3) +(0:6)(1:7) +Chosen action: (2:6)(3:5) +player: black +-----b-b +b-----b- +-------b +b------- +-----w-- +w------- +-b---w-- +----w-w- + +Possible actions: +(6:0)(5:1) +(1:1)(0:0) +(1:1)(0:2) +(7:5)(6:4) +(4:0)(3:1) +(6:6)(5:5) +(5:7)(4:6) +Chosen action: (6:6)(5:5) +player: white +-----b-b +b------- +-----b-b +b------- +-----w-- +w------- +-b---w-- +----w-w- + +Possible actions: +(2:0)(3:1) +(1:5)(2:4) +(1:5)(2:6) +(3:5)(4:4) +(3:5)(4:6) +(0:4)(1:3) +(0:6)(1:7) +Chosen action: (0:4)(1:3) +player: black +-----b-b +b------- +-----b-b +b------- +-----w-- +w------- +-b-w-w-- +------w- + +Possible actions: +(6:0)(5:1) +(1:1)(0:0) +(1:1)(0:2) +(7:5)(6:4) +(7:5)(6:6) +(7:7)(6:6) +(4:0)(3:1) +(5:5)(4:4) +(5:5)(4:6) +(5:7)(4:6) +Chosen action: (7:5)(6:6) +player: white +-------b +b-----b- +-----b-b +b------- +-----w-- +w------- +-b-w-w-- +------w- + +Possible actions: +(2:0)(3:1) +(1:5)(2:4) +(1:5)(2:6) +(3:5)(4:4) +(3:5)(4:6) +(1:3)(2:2) +(1:3)(2:4) +(0:6)(1:7) +Chosen action: (1:3)(2:4) +player: black +-------b +b-----b- +-----b-b +b------- +-----w-- +w---w--- +-b---w-- +------w- + +Possible actions: +(6:0)(5:1) +(1:1)(0:0) +(1:1)(0:2) +(4:0)(3:1) +(5:5)(4:4) +(5:5)(4:6) +(5:7)(4:6) +Chosen action: (5:5)(4:4) +player: white +-------b +b-----b- +-------b +b---b--- +-----w-- +w---w--- +-b---w-- +------w- + +Possible actions: +(3:5)(5:3) +Chosen action: (3:5)(5:3) +player: black +-------b +b-----b- +---w---b +b------- +-------- +w---w--- +-b---w-- +------w- + +Possible actions: +(6:0)(5:1) +(1:1)(0:0) +(1:1)(0:2) +(6:6)(5:5) +(4:0)(3:1) +(5:7)(4:6) +Chosen action: (1:1)(0:2) +player: white +-------b +b-----b- +---w---b +b------- +-------- +w---w--- +-----w-- +--B---w- + +Possible actions: +(2:0)(3:1) +(1:5)(2:6) +(5:3)(6:2) +(5:3)(6:4) +(2:4)(3:3) +(2:4)(3:5) +(0:6)(1:7) +Chosen action: (0:6)(1:7) +player: black +-------b +b-----b- +---w---b +b------- +-------- +w---w--- +-----w-w +--B----- + +Possible actions: +(6:0)(5:1) +(0:2)(1:1) +(0:2)(1:3) +(6:6)(5:5) +(4:0)(3:1) +(5:7)(4:6) +Chosen action: (6:0)(5:1) +player: white +-------b +------b- +-b-w---b +b------- +-------- +w---w--- +-----w-w +--B----- + +Possible actions: +(2:0)(3:1) +(1:5)(2:6) +(5:3)(6:2) +(5:3)(6:4) +(2:4)(3:3) +(2:4)(3:5) +(1:7)(2:6) +Chosen action: (2:0)(3:1) +player: black +-------b +------b- +-b-w---b +b------- +-w------ +----w--- +-----w-w +--B----- + +Possible actions: +(4:0)(2:2) +Chosen action: (4:0)(2:2) +player: white +-------b +------b- +-b-w---b +-------- +-------- +--b-w--- +-----w-w +--B----- + +Possible actions: +(1:5)(2:6) +(5:3)(6:2) +(5:3)(6:4) +(2:4)(3:3) +(2:4)(3:5) +(1:7)(2:6) +Chosen action: (1:7)(2:6) +player: black +-------b +------b- +-b-w---b +-------- +-------- +--b-w-w- +-----w-- +--B----- + +Possible actions: +(5:1)(4:0) +(5:1)(4:2) +(0:2)(1:1) +(0:2)(1:3) +(6:6)(5:5) +(2:2)(1:1) +(2:2)(1:3) +(5:7)(4:6) +Chosen action: (5:7)(4:6) +player: white +-------b +------b- +-b-w---- +------b- +-------- +--b-w-w- +-----w-- +--B----- + +Possible actions: +(5:3)(6:2) +(5:3)(6:4) +(2:4)(3:3) +(2:4)(3:5) +(2:6)(3:5) +(2:6)(3:7) +Chosen action: (2:6)(3:5) +player: black +-------b +------b- +-b-w---- +------b- +-----w-- +--b-w--- +-----w-- +--B----- + +Possible actions: +(5:1)(4:0) +(5:1)(4:2) +(0:2)(1:1) +(0:2)(1:3) +(6:6)(5:5) +(6:6)(5:7) +(2:2)(1:1) +(2:2)(1:3) +(4:6)(3:7) +Chosen action: (2:2)(1:3) +player: white +-------b +------b- +-b-w---- +------b- +-----w-- +----w--- +---b-w-- +--B----- + +Possible actions: +(3:5)(5:7)(7:5) +Chosen action: (3:5)(5:7)(7:5) +player: black +-----W-b +-------- +-b-w---- +-------- +-------- +----w--- +---b-w-- +--B----- + +Possible actions: +(5:1)(4:0) +(5:1)(4:2) +(0:2)(1:1) +(7:7)(6:6) +(1:3)(0:4) +Chosen action: (7:7)(6:6) +player: white +-----W-- +------b- +-b-w---- +-------- +-------- +----w--- +---b-w-- +--B----- + +Possible actions: +(7:5)(5:7) +Chosen action: (7:5)(5:7) +player: black +-------- +-------- +-b-w---W +-------- +-------- +----w--- +---b-w-- +--B----- + +Possible actions: +(5:1)(4:0) +(5:1)(4:2) +(0:2)(1:1) +(1:3)(0:4) +Chosen action: (1:3)(0:4) +player: white +-------- +-------- +-b-w---W +-------- +-------- +----w--- +-----w-- +--B-B--- + +Possible actions: +(1:5)(2:6) +(5:3)(6:2) +(5:3)(6:4) +(2:4)(3:3) +(2:4)(3:5) +(5:7)(6:6) +(5:7)(4:6) +Chosen action: (5:3)(6:4) +player: black +-------- +----w--- +-b-----W +-------- +-------- +----w--- +-----w-- +--B-B--- + +Possible actions: +(0:4)(2:6) +Chosen action: (0:4)(2:6) +player: white +-------- +----w--- +-b-----W +-------- +-------- +----w-B- +-------- +--B----- + +Possible actions: +(6:4)(7:3) +(6:4)(7:5) +(2:4)(3:3) +(2:4)(3:5) +(5:7)(6:6) +(5:7)(4:6) +Chosen action: (2:4)(3:3) +player: black +-------- +----w--- +-b-----W +-------- +---w---- +------B- +-------- +--B----- + +Possible actions: +(5:1)(4:0) +(5:1)(4:2) +(0:2)(1:1) +(0:2)(1:3) +(2:6)(3:5) +(2:6)(3:7) +(2:6)(1:5) +(2:6)(1:7) +Chosen action: (2:6)(3:7) +player: white +-------- +----w--- +-b-----W +-------- +---w---B +-------- +-------- +--B----- + +Possible actions: +(6:4)(7:3) +(6:4)(7:5) +(3:3)(4:2) +(3:3)(4:4) +(5:7)(6:6) +(5:7)(4:6) +Chosen action: (5:7)(4:6) +player: black +-------- +----w--- +-b------ +------W- +---w---B +-------- +-------- +--B----- + +Possible actions: +(3:7)(5:5)(7:3) +Chosen action: (3:7)(5:5)(7:3) +player: white +---B---- +-------- +-b------ +-------- +---w---- +-------- +-------- +--B----- + +Possible actions: +(3:3)(4:2) +(3:3)(4:4) +Chosen action: (3:3)(4:2) +player: black +---B---- +-------- +-b------ +--w----- +-------- +-------- +-------- +--B----- + +Possible actions: +(5:1)(3:3) +Chosen action: (5:1)(3:3) +player: white +---B---- +-------- +-------- +-------- +---b---- +-------- +-------- +--B----- + +Diamond Test Case +player: black +-------- +-------- +--B----- +-w-w---- +-------- +-w-w---- +-------- +-------- + +(5:2)(3:0)(1:2)(3:4)(5:2) +(5:2)(3:4)(1:2)(3:0)(5:2)