Android Open Source - android-chess Pos






From Project

Back to project page android-chess.

License

The source code is released under:

MIT License

If you think the Android project android-chess listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jwtc.chess;
//w w  w .j a  v a  2s. c  o m
// Pos - Wrapper class for a position or square on the board
// Provides only static methods
// A position is an integer between 0 and 63 for the 64 squares
// This part of the code is given under Pos to "free up" some lines in ChessBoard.
// In ChessBoard all other positional related stuff is done

public class Pos
{
  // returns positional value [0-63] for squares [a8-h1]
  // when a position cannot be created a message is sent on console out (co).
  // used to initialize values, no speed needed
  public static int fromString(final String s)
  {
    //if(s.length() != 2)
    //  co.pl("Cannot create Pos from: " + s);
    char c = s.charAt(0);
    //if(c < 'a' || c > 'h')  
    //  co.pl("Cannot create Pos from: " + c);
    int col, row = Integer.parseInt(s.substring(1));
    col = (int)c - (int)'a';
    
    return ((8-row) * 8) + col;
  }

  // returns positional value [0-63] from a column and row.
  // @col the column [0-7] (left to right)
  // @row the row [0-7] (top to bottom)
  // no check for invalid row or col is done for reasons of speed
  public static final int fromColAndRow(final int col, final int row)
  {
    return (row * 8) + col;
  }
  
  // returns the row [0-7] from top to bottom; ie values in [a8-h8] return 0.
  public static int row(final int val)
  {
    return (val >> 3) & 7;
  }
  //  returns the column [0-7] from left to right; ie values in [a8-a8] return 0.
  public static int col(final int val)
  {
    return val % 8;
  }

  // returns string representation of the value; ie "d5"
  // @val positional value [0-63] - no check on valid range
  public static String toString(final int val)
  {
    return "" + ((char)(Pos.col(val) + (int)'a')) + "" + (8-Pos.row(val));
  }
  
  // returns string representation of the row of val - human represented so from bottom to top ["1"-"8"]
  public static String rowToString(final int val)
  {
    return "" + (8-Pos.row(val));  
  }
  // returns string representation of the column. ["a"-"h"]
  public static String colToString(final int val)
  {
    return "" + ((char)(Pos.col(val) + (int)'a'));
  }
}




Java Source Code List

jwtc.android.chess.ChessFieldView.java
jwtc.android.chess.ChessImageView.java
jwtc.android.chess.ChessPreferences.java
jwtc.android.chess.ChessViewBase.java
jwtc.android.chess.ChessView.java
jwtc.android.chess.GamesListView.java
jwtc.android.chess.HtmlActivity.java
jwtc.android.chess.ImageCacheObject.java
jwtc.android.chess.MyBaseActivity.java
jwtc.android.chess.MyPGNProvider.java
jwtc.android.chess.PGNView.java
jwtc.android.chess.SaveGameDlg.java
jwtc.android.chess.UI.java
jwtc.android.chess.convergence.Connection.java
jwtc.android.chess.convergence.ConvergenceActivity.java
jwtc.android.chess.convergence.RestServer.java
jwtc.android.chess.iconifiedlist.IconifiedTextListAdapter.java
jwtc.android.chess.iconifiedlist.IconifiedTextView.java
jwtc.android.chess.iconifiedlist.IconifiedText.java
jwtc.android.chess.ics.CustomCommands.java
jwtc.android.chess.ics.ICSChatDlg.java
jwtc.android.chess.ics.ICSChessView.java
jwtc.android.chess.ics.ICSClient.java
jwtc.android.chess.ics.ICSConfirmDlg.java
jwtc.android.chess.ics.ICSMatchDlg.java
jwtc.android.chess.ics.TelnetSocket.java
jwtc.android.chess.ics.TimesealInputStream.java
jwtc.android.chess.ics.TimesealOutputStream.java
jwtc.android.chess.ics.TimesealPipe.java
jwtc.android.chess.ics.TimesealingSocket.java
jwtc.android.chess.puzzle.ChessViewPractice.java
jwtc.android.chess.puzzle.ChessViewPuzzle.java
jwtc.android.chess.puzzle.MyPuzzleProvider.java
jwtc.android.chess.puzzle.practice.java
jwtc.android.chess.puzzle.puzzle.java
jwtc.android.chess.tools.FileListView.java
jwtc.android.chess.tools.PGNProcessor.java
jwtc.android.chess.tools.importactivity.java
jwtc.android.chess.tools.pgntool.java
jwtc.android.chess.main.java
jwtc.android.chess.options.java
jwtc.android.chess.setup.java
jwtc.android.chess.start.java
jwtc.android.timeseal.TimesealingSocket.java
jwtc.android.timeseal.streams.a.java
jwtc.android.timeseal.streams.b.java
jwtc.android.timeseal.streams.c.java
jwtc.chess.ChessPuzzleProvider.java
jwtc.chess.GameControl.java
jwtc.chess.JNI.java
jwtc.chess.Move.java
jwtc.chess.PGNColumns.java
jwtc.chess.PGNEntry.java
jwtc.chess.PGNProvider.java
jwtc.chess.Pos.java
jwtc.chess.Valuation.java
jwtc.chess.algorithm.SearchAlgorithmRunner.java
jwtc.chess.algorithm.UCIWrapper.java
jwtc.chess.board.BoardConstants.java
jwtc.chess.board.BoardHashKeys.java
jwtc.chess.board.BoardMembers.java
jwtc.chess.board.BoardStatics.java
jwtc.chess.board.ChessBoard.java