net.japanesechess.util
Class PlyBoardFactory

java.lang.Object
  extended by net.japanesechess.util.PlyBoardFactory

public class PlyBoardFactory
extends java.lang.Object

Given a Handicap, previousBoard and current ply, what should the board look like as a packed byte[] array.

Author:
T. Gene Davis

Field Summary
private  boolean black
           
private  BoardPackUtil bpUtil
           
private  ShogiPly currentPly
           
private  Handicap handicap
           
private  byte[] previousBoard
           
private  ShogiPly previousPly
           
private  boolean wasPromoted
           
private  boolean willPromote
           
 
Constructor Summary
PlyBoardFactory()
           
 
Method Summary
private  int[][] capture(int[][] brd, java.lang.String toSquare)
          Only modifies the int[][] if there is a capture that takes place at the toSquare
private  byte[] drop(Tokens token, java.lang.String toSquare)
           
 void generateAndSetBoard(Handicap handicap, byte[] previousBoard, ShogiPly lastPly, ShogiPly newPly, boolean black)
          Generates the board that this ply creates and passes to the ply for use in board displays.
private  int getColumn(int location)
           
private  int getLocationInt(int x, java.lang.String yS)
          0-80 location of square on board as used by BoardPackUtil.
private  java.lang.String[] getLocations(boolean[][] to)
           
private  int getRowNumber(int location)
           
private  byte[] moveToken(Tokens token, java.lang.String toSquare)
           
private  byte[] moveToken(Tokens token, java.lang.String toSquare, int fromCol)
           
private  byte[] moveToken(Tokens token, java.lang.String toSquare, int fromCol, java.lang.String fromRow)
           
private  byte[] moveToken(Tokens token, java.lang.String toSquare, java.lang.String fromRow)
           
private  byte[] parseNotation(java.lang.String note)
          All the good stuff goes here.
private  java.lang.String rowNumber2Letter(int r)
          Utility for converting zero based row numbers into their proper characters.
private  byte[] tokenCaptures(Tokens token)
          Uses previous ply's x2 and y2 as x2 and y2 for this move.
private  byte[] tokenCaptures(Tokens token, int col)
          Uses previous ply's x2 and y2 as x2 and y2 for this move.
private  byte[] tokenCaptures(Tokens token, int col, java.lang.String row)
          Uses previous ply's x2 and y2 as x2 and y2 for this move.
private  byte[] tokenCaptures(Tokens token, java.lang.String row)
          Uses previous ply's x2 and y2 as x2 and y2 for this move.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handicap

private Handicap handicap

previousBoard

private byte[] previousBoard

previousPly

private ShogiPly previousPly

currentPly

private ShogiPly currentPly

black

private boolean black

willPromote

private boolean willPromote

wasPromoted

private boolean wasPromoted

bpUtil

private BoardPackUtil bpUtil
Constructor Detail

PlyBoardFactory

public PlyBoardFactory()
Method Detail

generateAndSetBoard

public void generateAndSetBoard(Handicap handicap,
                                byte[] previousBoard,
                                ShogiPly lastPly,
                                ShogiPly newPly,
                                boolean black)
Generates the board that this ply creates and passes to the ply for use in board displays. Also, along the way it populates all ply attributes that pertain to the move. Notation and comment where previously populated. This should be the ONLY private method.

Parameters:
handicap - needed because handicaps may have less tokens and undefined padding to fill the unused space
previousBoard - needed to fully interpret notation
lastPly - needed for the notation 'xS' or 'Gx' where a token captures the last moved token at (x2, y2)
newPly - current ply to populate
black - whose turn is it now? black or white.

parseNotation

private byte[] parseNotation(java.lang.String note)
All the good stuff goes here.

Parameters:
note -
Returns:

drop

private byte[] drop(Tokens token,
                    java.lang.String toSquare)

tokenCaptures

private byte[] tokenCaptures(Tokens token,
                             int col,
                             java.lang.String row)
Uses previous ply's x2 and y2 as x2 and y2 for this move.

Parameters:
token - the token that does the capturing.
Returns:

tokenCaptures

private byte[] tokenCaptures(Tokens token,
                             int col)
Uses previous ply's x2 and y2 as x2 and y2 for this move.

Parameters:
token - the token that does the capturing.
Returns:

tokenCaptures

private byte[] tokenCaptures(Tokens token,
                             java.lang.String row)
Uses previous ply's x2 and y2 as x2 and y2 for this move.

Parameters:
token - the token that does the capturing.
Returns:

tokenCaptures

private byte[] tokenCaptures(Tokens token)
Uses previous ply's x2 and y2 as x2 and y2 for this move.

Parameters:
token - the token that does the capturing.
Returns:

getLocations

private java.lang.String[] getLocations(boolean[][] to)

capture

private int[][] capture(int[][] brd,
                        java.lang.String toSquare)
Only modifies the int[][] if there is a capture that takes place at the toSquare

Parameters:
brd -
toSquare -
Returns:

moveToken

private byte[] moveToken(Tokens token,
                         java.lang.String toSquare)

moveToken

private byte[] moveToken(Tokens token,
                         java.lang.String toSquare,
                         int fromCol)

moveToken

private byte[] moveToken(Tokens token,
                         java.lang.String toSquare,
                         java.lang.String fromRow)

moveToken

private byte[] moveToken(Tokens token,
                         java.lang.String toSquare,
                         int fromCol,
                         java.lang.String fromRow)

rowNumber2Letter

private java.lang.String rowNumber2Letter(int r)
Utility for converting zero based row numbers into their proper characters.

Parameters:
r -
Returns:

getRowNumber

private int getRowNumber(int location)

getColumn

private int getColumn(int location)

getLocationInt

private int getLocationInt(int x,
                           java.lang.String yS)
0-80 location of square on board as used by BoardPackUtil.

Parameters:
x -
y -
Returns: