Class PlayerAI

java.lang.Object
  extended by Player
      extended by PlayerAI

public class PlayerAI
extends Player

Since:
7/1/2010
Author:
Petri Tuononen

Constructor Summary
PlayerAI(Board board, Move move, int side)
          Constructor
 
Method Summary
 void advance(Player player)
          Advance piece.
 void attack(Player player)
          Tries to capture highest value enemy piece.
 void defense(Player player)
          If piece in danger move to a safe square.
 void doBestMove(Player player)
          Performs the best possible move in different situations.
 java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getAllSquaresPossibleToMove(int side)
          Get all squares pieces are allowed to move.
 java.util.ArrayList<java.util.ArrayList<java.lang.String>> getAllSquaresPossibleToMoveAndPiece(int side)
          Returns two arraylists of piece notations and where they can move.
 java.util.ArrayList<java.util.ArrayList<Piece>> getPiecesPossibleToCapture(int side)
          Get all enemy pieces that can be captured.
 Piece[] highestValuePieceAbleToCapture(int side)
          Returns an array that contains two cells which first cell contains own piece that can be capture highest value enemy piece and second cell contains highest value enemy piece.
 boolean isCheckmate(Player player)
          Check if player's King is in checkmate.
 boolean isSquareSafe(int x, int y, Player player)
          check that enemy can't move to selected square on next round.
 java.util.ArrayList<java.util.ArrayList<Piece>> piecesAbleToCaptureInValueDescOrder(int side)
          Returns an array of enemy pieces that can be captured in value descending order.
 void printHighestValuePieceAbleToCapture(int side)
          Prints the highest value piece that can be captured and piece that can capture it.
 void printPiecesToCaptureAsNotation(int side)
          Prints a list of which own piece can capture enemy piece.
 void sortPieceArray(Piece[] list, int length)
          Sorts an array of Piece objects in ascending order by value.
 
Methods inherited from class Player
getEnemySide, getSide, isOwnPiece, setSide
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlayerAI

public PlayerAI(Board board,
                Move move,
                int side)
Constructor

Parameters:
side -
Method Detail

getAllSquaresPossibleToMove

public java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getAllSquaresPossibleToMove(int side)
Get all squares pieces are allowed to move. First arraylist contains row numbers and second contains column numbers.

Parameters:
side -
Returns:
ArrayList>

getAllSquaresPossibleToMoveAndPiece

public java.util.ArrayList<java.util.ArrayList<java.lang.String>> getAllSquaresPossibleToMoveAndPiece(int side)
Returns two arraylists of piece notations and where they can move.

Parameters:
side -
Returns:
ArrayList>

getPiecesPossibleToCapture

public java.util.ArrayList<java.util.ArrayList<Piece>> getPiecesPossibleToCapture(int side)
Get all enemy pieces that can be captured. Returns an arraylist containing two arraylists. First arraylist indicates own piece that can capture and second arraylist enemy piece to capture.

Parameters:
side -
Returns:
ArrayList>

printPiecesToCaptureAsNotation

public void printPiecesToCaptureAsNotation(int side)
Prints a list of which own piece can capture enemy piece. e.g. a8, a2 (black rook can capture white pawn)

Parameters:
side -

highestValuePieceAbleToCapture

public Piece[] highestValuePieceAbleToCapture(int side)
Returns an array that contains two cells which first cell contains own piece that can be capture highest value enemy piece and second cell contains highest value enemy piece.

Parameters:
side -
Returns:
Piece[]

piecesAbleToCaptureInValueDescOrder

public java.util.ArrayList<java.util.ArrayList<Piece>> piecesAbleToCaptureInValueDescOrder(int side)
Returns an array of enemy pieces that can be captured in value descending order.

Parameters:
side -
Returns:
ArrayList>

isCheckmate

public boolean isCheckmate(Player player)
Check if player's King is in checkmate.

Parameters:
player -
Returns:
boolean

sortPieceArray

public void sortPieceArray(Piece[] list,
                           int length)
Sorts an array of Piece objects in ascending order by value.

Parameters:
list -
length -

printHighestValuePieceAbleToCapture

public void printHighestValuePieceAbleToCapture(int side)
Prints the highest value piece that can be captured and piece that can capture it. Printed in notation format so that first comes own piece then separated by comma the enemy piece.

Parameters:
side -

doBestMove

public void doBestMove(Player player)
Performs the best possible move in different situations.


defense

public void defense(Player player)
If piece in danger move to a safe square.

Parameters:
player -

attack

public void attack(Player player)
Tries to capture highest value enemy piece. Tries to capture second highest and so on if piece that tries capturing would be lost in trade to a less valuable piece. If no piece can be captured move normally.

Parameters:
player -

isSquareSafe

public boolean isSquareSafe(int x,
                            int y,
                            Player player)
check that enemy can't move to selected square on next round.

Parameters:
x -
y -
player -
Returns:
boolean

advance

public void advance(Player player)
Advance piece.

Parameters:
player -