Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Ultima{
  4.   private static String[][] tabla = new String[ 10 ][ 10 ];
  5.   private static int player;
  6.  
  7.   static int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
  8.   static int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };
  9.  
  10.   public static void init(){
  11.     player = 0;
  12.    
  13.     for( int i = 0; i <= 9; ++i )
  14.       for( int j = 0; j <= 9; ++j )
  15.         tabla[i][j] = "empt";
  16.      
  17.     for( int i = 1; i <= 8; ++i )
  18.       tabla[2][i] = "wpaw";
  19.     for( int i = 1; i <= 8; ++i )
  20.       tabla[7][i] = "bpaw";
  21.  
  22.     tabla[1][1] = "wimm";
  23.     tabla[1][2] = "wlon";
  24.     tabla[1][3] = "wcha";
  25.     tabla[1][4] = "wkin";
  26.     tabla[1][5] = "wwit";
  27.     tabla[1][6] = "wcha";
  28.     tabla[1][7] = "wlon";
  29.     tabla[1][8] = "wcoo";
  30.  
  31.    
  32.     tabla[8][1] = "bcoo";
  33.     tabla[8][2] = "blon";
  34.     tabla[8][3] = "bcha";
  35.     tabla[8][4] = "bwit";
  36.     tabla[8][5] = "bkin";
  37.     tabla[8][6] = "bcha";
  38.     tabla[8][7] = "blon";
  39.     tabla[8][8] = "bimm";
  40.   }
  41.  
  42.   public static String fieldState( String field ){
  43.     int s = (int) ( field.charAt( 0 ) - 'A' + 1 );
  44.     int r = (int) ( field.charAt( 1 ) - '0' );
  45.     return tabla[r][s];
  46.   }
  47.  
  48.   public static boolean outOfBounds( int r, int s ){
  49.     return r >= 1 && r <= 8 && s >= 1 && s <= 8;
  50.   }
  51.  
  52.   public static String checkQueen( int r, int s ){
  53.     String ret = "";
  54.     for( int d = 0; d < 8; ++d ){
  55.       int rt = r;
  56.       int st = s;
  57.  
  58.       while( true ){
  59.         rt += dx[d];
  60.         st += dy[d];
  61.         if( outOfBounds( rt, st ) || tabla[rt][st] != "empt" ) break;
  62.         ret += Integer.toString( rt ) + Integer.toString( st );
  63.       }
  64.     }
  65.     return ret;
  66.   }
  67.  
  68.   public static void main( String[] args ){
  69.     init();
  70.   }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement