Advertisement
calcpage

APCS_CH8_Chess960R1.java

Feb 28th, 2013
264
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     2013.0226
  3. purpose:    randomly generate 1 of the 960 Fischer Random Chess Boards
  4. required file:  Chess960V1.java                 main class
  5. translator: javac Chess960V1.java
  6. interpreter:    java Chess960V1
  7. */
  8.  
  9. import java.util.Random;
  10.  
  11. public class Chess960V1
  12. {
  13.     public static void main(String[] args)
  14.     {
  15.         String[] whitePieces = new String[8];
  16.         darkBishop(whitePieces);
  17.         lightBishop(whitePieces);
  18.         setQueen(whitePieces);
  19.         setKnight(whitePieces);
  20.         setKnight(whitePieces);
  21.         doRook(whitePieces);
  22.         doKing(whitePieces);
  23.         doRook(WhitePieces);
  24.         System.out.println(toString(whitePieces));
  25.     }
  26.  
  27.     public static void darkBishop(String[] wP)
  28.     {
  29.         Random die = new Random();
  30.         wP[die.nextInt(4)*2]="B";
  31.     }
  32.  
  33.     public static void lightBishop(String[] wP)
  34.     {
  35.         Random die = new Random();
  36.         wP[die.nextInt(4)*2+1]="B";
  37.     }
  38.  
  39.     public static void setQueen(String[] wP)
  40.     {
  41.         int pos;
  42.         Random die = new Random();
  43.         do
  44.             pos = die.nextInt(8);
  45.         while(wP[pos]!=null);
  46.         wP[pos]="Q";
  47.     }
  48.  
  49.     public static void setKnight(String[] wP)
  50.     {
  51.         int pos;
  52.         Random die = new Random();
  53.         do
  54.             pos = die.nextInt(8);
  55.         while(wP[pos]!=null);
  56.         wP[pos]="N";
  57.     }
  58.  
  59.     public static void doRook(String[] wP)
  60.     {
  61.         int pos=0;
  62.         while(wP[pos]!=null)
  63.         {
  64.             pos++;
  65.         }
  66.         wP[pos]="R";
  67.     }
  68.  
  69.     public static void doKing(String[] wP)
  70.     {
  71.         int pos=0;
  72.         while(wP[pos]!=null)
  73.         {
  74.             pos++;
  75.         }
  76.         wP[pos]="K";
  77.     }
  78.  
  79.     public static String toString(String[] wP)
  80.     {
  81.         String temp = "";
  82.         for(int k=0; k<wP.length; k++)
  83.         {
  84.             temp += wP[k];
  85.         }
  86.         return temp;
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement