Advertisement
loloof64

ChessMove (Upnp application)

Apr 20th, 2013
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.88 KB | None | 0 0
  1. package com.loloof64.j2se.cling_chess_exp;
  2.  
  3. public class ChessMove {
  4.  
  5.     public int startFile, startRank, endFile, endRank;
  6.    
  7.     public ChessMove(){
  8.        
  9.     }
  10.  
  11.     public ChessMove(int startFile, int startRank, int endFile, int endRank) {
  12.         this.startFile = startFile;
  13.         this.startRank = startRank;
  14.         this.endFile = endFile;
  15.         this.endRank = endRank;
  16.     }
  17.    
  18.     public int packValue(){
  19.         return startFile << 24 | startRank << 16 | endFile << 8 | endRank;
  20.     }
  21.    
  22.     public static ChessMove unpack(int packedValue){
  23.         int eRank = packedValue & 0xFF;
  24.         packedValue >>= 8;
  25.         int eFile = packedValue & 0xFF;
  26.         packedValue >>= 8;
  27.         int sRank = packedValue & 0xFF;
  28.         packedValue >>= 8;
  29.         int sFile = packedValue;
  30.         return new ChessMove(sFile, sRank, eFile, eRank);
  31.     }
  32.    
  33.     public String toString(){
  34.         return String.format("ChessMove[%d %d %d %d]", startFile, startRank, endFile, endRank);
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement