import java.util.*; /** * This class defines what a jump is and provides methods for obtaining jumps. * A jump is a LinkedList of Integers. The first element in the list is * the starting position of the piece, the other elements are the positions on * the board where the piece lands after jumping over an opponent's piece. */ public class Jump{ /** * Given a CheckerBoard and a player, returns a LinkedList containing * all jumps that the player can make. * Note that player must be 'p','P', 'o', or 'O'. */ public static LinkedList GetJumps(CheckerBoard b, char player){ LinkedList jmplist = new LinkedList(); LinkedList tmp = new LinkedList(); int i; switch(player){ case 'p':case 'P': for(i=0;i<32;i++){ if(b.Piece(i)=='p'||b.Piece(i)=='P'){ tmp = GetJumps(b,i); if(tmp!=null){ jmplist.addAll(GetJumps(b,i)); } // else{System.out.println("Bad");} } } break; case 'o': case 'O': for(i=0;i<32;i++){ if(b.Piece(i)=='o'||b.Piece(i)=='O'){ tmp = GetJumps(b,i); if(tmp!=null){ jmplist.addAll(GetJumps(b,i)); } } } break; default: break; } return jmplist; } /** * Given a CheckerBoard and a position on the board, returns a LinkedList * all possible jumps the piece at the position can make. */ public static LinkedList GetJumps(CheckerBoard b, int p){ /* returns a linked list of all jumps for position p */ LinkedList l = new LinkedList(); Integer x = new Integer(p); int i,j,k; LinkedList tmp = new LinkedList(); LinkedList tmp1 = new LinkedList(); LinkedList tmplist = new LinkedList(); tmp1.add(x); l.add(tmp1); // now have the start on the list // System.out.println("GetJumps b,p"); // if(MoreJumps(b,l)){System.out.println("Nice");} //else{System.out.println("Bad");} while(MoreJumps(b,l)){ // System.out.println("About to expand"); tmplist = new LinkedList(); tmplist=Expand(b, l); // System.out.println("Size after expansions is " + tmplist.size()); // System.out.println("GetJumps: size of jumps is " + ((LinkedList)tmplist.getFirst()).size()); l= new LinkedList(); l= (LinkedList)tmplist.clone(); } /* now need to process the list to get rid of nonexpanded jumps */ // System.out.println("Size of list is " + l.size()); for(i=0;i1){ tmp.add(l.get(i)); } } if(tmp.size()<1){ return null;} else{return tmp;} } private static LinkedList Expand(CheckerBoard b, LinkedList l){ int i,position; CheckerBoard newb; LinkedList jmp = new LinkedList(); LinkedList returnlst = new LinkedList(); LinkedList newjump = new LinkedList(); ArrayList nbrs = new ArrayList(); ArrayList jmps = new ArrayList(); int j,k,x,y; //System.out.println("Expand"); i=0; //System.out.println(l.size()); while(ipos &&(b.Piece(over)=='o'||b.Piece(over)=='O')){ // System.out.println("Maybe jump!!"); /* maybe can jump */ /* must now check landing position */ for(j=0;j27){ newb.SetPiece(land,'P'); } else{ if(piece =='o' && land<4 && land>-1){ newb.SetPiece(land,'O'); } else{ newb.SetPiece(land,piece); } } newb.SetPiece(over,'e'); newb.SetPiece(start,'e'); return newb; } private static int GetOver(CheckerBoard b,int start, int land){ /* return -1 is no match */ ArrayList nbrs_start = new ArrayList(); ArrayList nbrs_land = new ArrayList(); int i,j,over; boolean match = false; int x,y; // System.out.println("GetOver: " + start +" " + land); nbrs_start = b.board[start].GetNeighbours(); nbrs_land = b.board[land].GetNeighbours(); over =-1; i=0; while(!match && i