Anonymous Anonymous - 8 months ago
338 0

No description

Java

chessaf

/**
 *
 * @author Jennifer Sanchez-Garcia
 */
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class TestApplication {
    /**
     * @param args the command line arguments
     */
    
    public static String[][] chessArray = new String [8][8];
    public static ArrayList<ChessItems> arrayList;
    
    public static void main(String[] args) {
        // TODO code application logic here
        AssignBoard(); //will assign board
        PrintBoard(); //prints current state of board
        
    }
      public static void PrintBoard()
      {
         /* for (int x=0; x<8 ;x++)//when prints new row when it completes each loop , should be a Y instead of X to fit with math.
          {
            for (int y=0;y<9;y++)//goes column by column, probably should be X instead of Y again.
            {
                if (y<8)//prints each column out in the current row.
                {
                  System.out.print("|"+ chessArray[x][y]);
                  
                }
                else //when it gets to the 8th index, it will jump to this else, and print a line at the end, then go to the next line
                {
                  System.out.println("|");
                 
                }    
          }
         }
         */
//         for(int i =0; i < arrayList.size()-1; i++){
//             if((i+1)%8 == 0){
//                 System.out.print("|/n");
//             }
//             else{
//                 System.out.print("|" + arrayList.get(i));
//             }
//         
//         }
         for (int x=0; x<8 ;x++)//when prints new row when it completes each loop , should be a Y instead of X to fit with math.
          {
            for (int y=0;y<8;y++)
            { 
                if(y==7){
                    System.out.print("|"+ arrayList.get(x*8+y)+ "|\n");
                } else
                    System.out.print("|" + arrayList.get(x*8+y));
                    }
                    
                       
            }
      }
      
        
      public static void AssignBoard() //assigns pieces
      {
          arrayList = new ArrayList<>();
       for(int i =0; i< 64; i++)
       {
           arrayList.add(null);
       
       }
          //kings and queens
          chessArray [0][4] = "k";
          ChessItems bking = new ChessPiece("k",0,4,8);  
          arrayList.add(bking.returnPosition(), bking);
          chessArray [7][4] = "K";
          ChessItems wking = new ChessPiece("K", 7,4,8);
          arrayList.add(wking.returnPosition(), wking);
          chessArray [0][3] = "q";
          ChessItems bqueen = new ChessPiece("q",0,3,8);
          arrayList.add(bqueen.returnPosition(), bqueen);
          chessArray [7][3] = "Q";
          ChessItems wqueen = new ChessPiece("Q",7,3,8);  
          arrayList.add(wqueen.returnPosition(), wqueen);
          
          //Bishops
          chessArray [0][2] = "b";
          ChessItems bbishop1 = new ChessPiece("b",0,2,8);  
          arrayList.add(bbishop1.returnPosition(), bbishop1);
          chessArray [0][5] = "b";
          ChessItems bbishop2 = new ChessPiece("b",0,5,8);  
          arrayList.add(bbishop2.returnPosition(), bbishop2);
          chessArray [7][2] = "B";
          ChessItems wbishop1 = new ChessPiece("B",7,2,8);  
          arrayList.add(wbishop1.returnPosition(), wbishop1);
          chessArray [7][5] = "B";
          ChessItems wbishop2 = new ChessPiece("B",7,5,8);  
          arrayList.add(wbishop2.returnPosition(), wbishop2);
          //Knights
          chessArray [0][1] = "n";
          ChessItems bknight1 = new ChessPiece("n",0,1,8);  
          arrayList.add(bknight1.returnPosition(), bknight1);
          chessArray [0][6] = "n";
          ChessItems bknight2 = new ChessPiece("n",0,6,8);  
          arrayList.add(bknight2.returnPosition(), bknight2);
          chessArray [7][1] = "N";
          ChessItems wknight1 = new ChessPiece("N",7,1,8);  
          arrayList.add(wknight1.returnPosition(), wknight1);
          chessArray [7][6] = "N";
          ChessItems wknight2 = new ChessPiece("N",7,6,8);  
          arrayList.add(wknight2.returnPosition(), wknight2);
          //Rooks
          chessArray [0][0] = "r";
          ChessItems brook1 = new ChessPiece("r",0,0,8);  
          arrayList.add(brook1.returnPosition(), brook1);
          chessArray [0][7] = "r";
          ChessItems brook2 = new ChessPiece("r",0,7,8);  
          arrayList.add(brook2.returnPosition(), brook2);
          chessArray [7][0] = "R";
          ChessItems wrook1 = new ChessPiece("R",7,0,8);  
          arrayList.add(wrook1.returnPosition(), wrook1);
          chessArray [7][7] = "R";
          ChessItems wrook2 = new ChessPiece("R",7,7,8);  
          arrayList.add(wrook2.returnPosition(), wrook2);
          
          //lowercase pawns
          for (int x=0;x<8;x++)
          {
              chessArray[1][x] = "p";
              arrayList.add(new ChessPiece("p", 1, x, 8));
          }
          
          //uppercase pawns
          for (int x=0;x<8;x++)
          {
              chessArray[6][x] = "P";
              arrayList.add(new ChessPiece("0", 6, x, 8));
          }
          
          //empty spaces between the pieces
          for (int x=0;x<8;x++)
          {
              for(int y=2;y<6;y++)//goes to second third row to 7th
                  
                      {
                        chessArray[y][x] = "0";
                        arrayList.add(new ChessPiece("0", y, x, 8));
                      }
          }
                   
      }

    
             
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download