import java.util.*; /** * This class defines what a move is and provides methods for * generating moves for a player or for a piece. * There are two fields, both ints, start and end. * start is the number of position of the piece before the move is made, while * end is the number of the position where the piece ends up after making * the move. */ public class aMove{ private int start; private int end; /** * The start and end are both initialized to -1. This is an ileagal move. */ public aMove(){ this.start =-1; this.end = -1; } /** * Start is set to be i, and end is set to be j. * There is no checking as to whether this move is legal. */ public aMove(int i, int j){ this.start =i; this.end =j; } /** * Start is set to be i, and end is set to be j. * There is no checking as to whether this move is legal. */ public void Set(int i, int j){ start =i; end =j; } /** * Returns start */ public int GetStart(){ return start; } /** * Returns end */ public int GetEnd(){ return end; } /** * Given a CheckerBoard and a player, returns a LinkedList of aMoves * that includes all legal moves (but no jumps) that the player can make. * @parameters player must be either 'p' or 'o'. */ static public LinkedList GetMoves(CheckerBoard b, char c){ LinkedList l = new LinkedList(); int i; char player; if(c=='p'||c=='P'){ player ='p';} else { if (c=='o'||c=='O') {player = 'o';} else{player ='e';} } switch(player){ case 'p': for(i=0;i<32;i++){ if(b.Piece(i)=='p'||b.Piece(i)=='P'){ l.addAll(GetMoves(b,i)); } } break; case 'o': for(i=0;i<32;i++){ if(b.Piece(i)=='o'||b.Piece(i)=='O'){ l.addAll(GetMoves(b,i)); } } break; default: break; } return l; } /** * Given a checkerboard and an int specifying a board position, returns * a LinkedList of all possible moves (but no jumps) that can be made * by the piece in that position. */ static public LinkedList GetMoves(CheckerBoard b, int pos){ LinkedList l = new LinkedList(); ArrayList nbrs = new ArrayList(); char piece; int size,i,place; aMove m; // System.out.println("The position is " + pos); piece = b.board[pos].piece; // System.out.println("The piece is " + piece); nbrs = b.board[pos].GetNeighbours(); switch(piece){ case 'e': break; case 'p': /* process neighbours */ size = nbrs.size(); for(i=0;ipos)){ /* there is a move */ m = new aMove(pos,place); l.add(m); } } break; case 'o': /* process neighbours */ size = nbrs.size(); for(i=0;i27 && piece=='p'){ newb.SetPiece(end,'P'); } if(end<5 && end>-1 && piece =='o'){ newb.SetPiece(end,'O'); } //newb.SetPiece(m.GetEnd(),piece); //newb.SetPiece(m.GetStart(),'e'); return newb; } }