/** *A stub class for Player * * @author Matthew Charnetski * @author Anne Feltovich * @author Elizabeth Ottesen * @author Austin Wells * @version 1.0 of March 2000 */ public class CompPlayer implements Player { //Fields // stores number of rows on board. protected int numberofrows; // stores number of columns on board. protected int numberofcolumns; // double array of all positions on board in the form int[row][col]. Zero // is in that location if move is illegal, 1 if move is legal. protected int[][] legalmoves; // stores color. protected String color; // makes a move. public void makeMove(Board board, Rules rules, String color) { this.numberofrows = board.getRowNumber(); // assumes board has a method getROwNumber that tells us // how many rows are in the board. this.numberofcolumns = board.getColumnNumber(); // assumes board has getColumnNumber this.legalmoves = rules.allMoves(); this.color = color; // creates new double array for storing the number pieces captured from // a move at position. int[][] captured = new int[rownumber-1][columnnumber-1]; fillCapturedArray(captured); // chooses best move according to the first of the moves that capture // the most pieces. int bestrow = 0; int bestcol = 0; int maxsofar = 0; for (int i = 0; i < numberofrows; i++) { for (int j = 0; j < numberofcolumns; j++) { if (captured[i][j] > maxsofar) { bestrow = i; bestcol = j; maxsofar = captured[i][j]; } } } // make the move specified above. Piece piece = new Piece(bestrow, bestcol, color); board.makeMove(piece); } // this fills in the captured array define above. public void fillCapturedArray(int[][] captured){ for (int row = 0; row(numberofrows - 1) || currentcolumn<0 || currentcolumn>(numberofcolumns - 1)) { return 0: }//if //if the cursor finds an unoccupied space before closing off the //capture bracket, no captures are made else if(board.isOccupied(currentrow, currentcol)== false) { return 0; }//if //asks board for the piece occupying the current space Piece currentPiece = board.lookUpPiece(currentrow, currentcol); //if the piece is the player's color, then it finds how many pieces are //enclosed in the capture bracket if(currentPiece.getColor == this.color) { if (rowincrement == 0) { return (currentcol-occupiedcol-1); }//if else { return (currentrow-occupiedrow-1); }//else }//if //otherwise recursively call the method, moving the cursor in the //specified direction else{ numCapturedinDirection(occupiedrow, occupiedcol, currentrow + rowincrement, currentcol + rowincrement, rowincrement, columnincrement); }//else }//numCapturedinDirection }//class compPlayer