Advertisement
calcpage

Chess960V1.java

Feb 29th, 2012
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.56 KB | None | 0 0
  1. /*
  2. Chess960V1.java     MrG     2012.0227
  3. purpose:    randomly find one 960 Fischer Random Chess Board
  4. required file:  Chess960V1.java             main class
  5. translator: javac Chess960V1.java
  6. interpreter:    java Chess960V1
  7. */
  8.  
  9. //imported classes
  10. import java.util.Random;
  11.  
  12. //main class
  13. public class Chess960V1
  14. {
  15.     public static void main(String[] args)
  16.     {
  17.         String[] whitePieces = new String[8];
  18.         darkBishop(whitePieces);
  19.         lightBishop(whitePieces);
  20.         setQueen(whitePieces);
  21.         setKnight(whitePieces);
  22.         setKnight(whitePieces);
  23.         doLastStep(whitePieces);
  24.         System.out.println(toString(whitePieces));
  25.     }
  26.  
  27.     public static void doLastStep(String[] wP)
  28.     {
  29.         int pos = 0;
  30.         while(wP[pos]!=null)
  31.         {
  32.             pos++;
  33.         }
  34.         wP[pos]="R";
  35.         while(wP[pos]!=null)
  36.         {
  37.             pos++;
  38.         }
  39.         wP[pos]="K";
  40.         while(wP[pos]!=null)
  41.         {
  42.             pos++;
  43.         }
  44.         wP[pos]="R";
  45.     }
  46.  
  47.     public static void setQueen(String[] wP)
  48.     {
  49.         int pos;
  50.         Random die = new Random();
  51.         do
  52.         {
  53.             pos=die.nextInt(8);
  54.         }
  55.         while(wP[pos]!=null);
  56.         wP[pos]="Q";
  57.     }
  58.  
  59.     public static void setKnight(String[] wP)
  60.     {
  61.         int pos;
  62.         Random die = new Random();
  63.         do
  64.         {
  65.             pos=die.nextInt(8);
  66.         }
  67.         while(wP[pos]!=null);
  68.         wP[pos]="N";
  69.     }
  70.  
  71.     public static void darkBishop(String[] wP)
  72.     {
  73.         Random die = new Random();
  74.         wP[die.nextInt(4)*2]="B";
  75.     }
  76.  
  77.     public static void lightBishop(String[] wP)
  78.     {
  79.         Random die = new Random();
  80.         wP[1+die.nextInt(4)*2]="B";
  81.     }
  82.  
  83.     public static String toString(String[] wP)
  84.     {
  85.         String temp = "";
  86.         for(int k=0; k<wP.length; k++)
  87.         {
  88.             temp += wP[k];
  89.         }
  90.         return temp;
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement