Programming Sesion #4:The incomplete chess game(CUI)
I wasted a week on this...
I don't know ...what benefit u can make out of this program..but still i m posting it ..
It is a CUI chess which is unfinished...I will try it again with another logic....only pawns will move except Wp8...go through the program and u will understand how it works...
/*
opensource
*/
package chess;
import java.util.*;
import java.io.IOException;
/**
* @author lol ik
*/
public class Board {
int i,j;
public enum Whitepieces {WK,Wp8,Wp1,Wp2,Wp3,Wp4,Wp5,Wp6,Wp7,WE1,WE2,WC1,WC2,WQ,WH1,WH2};
Scanner in=new Scanner(System.in);
public static void main(String[] args) throws IOException
{
int i,j;
String[][] box = new String[8][8];
box[0][0]=" WE1";
box[0][1]=" WH1";
box[0][2]=" WC1";
box[0][3]=" WK ";
box[0][4]=" WQ ";
box[0][5]=" WC2";
box[0][6]=" WH2";
box[0][7]=" WE2";
box[1][1]=" Wp1";
box[1][2]=" Wp2";
box[1][3]=" Wp3";
box[1][4]=" Wp4";
box[1][5]=" Wp5";
box[1][6]=" Wp6";
box[1][7]=" Wp7";
box[1][0]=" Wp8";
box[2][1]=" 17 ";
box[2][2]=" 18 ";
box[2][3]=" 19 ";
box[2][4]=" 20 ";
box[2][5]=" 21 ";
box[2][6]=" 22 ";
box[2][7]=" 23 ";
box[2][0]=" 24 ";
box[3][1]=" 25 ";
box[3][2]=" 26 ";
box[3][3]=" 27 ";
box[3][4]=" 28 ";
box[3][5]=" 29 ";
box[3][6]=" 30 ";
box[3][7]=" 31 ";
box[3][0]=" 32 ";
box[4][1]=" 33 ";
box[4][2]=" 34 ";
box[4][3]=" 35 ";
box[4][4]=" 36 ";
box[4][5]=" 37 ";
box[4][6]=" 38 ";
box[4][7]=" 39 ";
box[4][0]=" 40 ";
box[5][1]=" 41 ";
box[5][2]=" 42 ";
box[5][3]=" 43 ";
box[5][4]=" 44 ";
box[5][5]=" 45 ";
box[5][6]=" 46 ";
box[5][7]=" 47 ";
box[5][0]=" 48 ";
box[6][1]=" Bp1";
box[6][2]=" Bp2";
box[6][3]=" Bp3";
box[6][4]=" Bp4";
box[6][5]=" Bp5";
box[6][6]=" Bp6";
box[6][7]=" Bp7";
box[6][0]=" Bp8";
box[7][0]=" BE1";
box[7][1]=" BH1";
box[7][2]=" BC1";
box[7][3]=" BQ ";
box[7][4]=" BK ";
box[7][5]=" BC2";
box[7][6]=" BH2";
box[7][7]=" BE2";
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
//board program ends here
System.out.println("");
System.out.println("Player Turn");
Scanner in=new Scanner(System.in);
int flag=0;
int cont=0;
int jag=0;
int z;
String choice;
int f=0;
int q=0;
while(jag==0)
{
while(cont==0)
{
try{
choice=in.nextLine();
switch(Whitepieces.valueOf(choice))
{
case WK:
{
System.out.println("kaka ki jai");
cont=1;
}
break;
//pawn movements with numbers.
case Wp8:
{
int a=in.nextInt();
if (a==24&&flag==0)
{
String temp=box [1][0];
box [1][0]= box [2][0];
box [2][0]= temp;
flag=1;
}
else if (a==40&&flag==2)
{
String temp=box [3][0];
box [3][0] =box [4][0];
box [4][0] =temp;
flag=3;
}
else if (flag==0&&a==32)
{
String temp=box[1][0];
box [1][0] =box[3][0];
box [3][0] =temp;
flag=2;
}
else if(flag==1&&a==32)
{
String temp=box[2][0];
box [2][0] =box[3][0];
box [3][0] =temp;
flag=2;
}
else if(a==48&&flag==3)
{
String temp=box[4][0];
box [4][0] =box[5][0];
box [5][0] =temp;
flag=4;
}
//open source
//lol ik
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
cont=1;
break;
}
case Wp1:
{
int a=in.nextInt();
if (a==17&&flag==0)
{
String temp=box [1][1];
box [1][1]= box [2][1];
box [2][1]= temp;
flag=1;
}
else if (a==33&&flag==2)
{
String temp=box [3][1];
box [3][1] =box [4][1];
box [4][1] =temp;
flag=3;
}
else if (flag==0&&a==25)
{
String temp=box[1][1];
box [1][1] =box[3][1];
box [3][1] =temp;
flag=2;
}
else if(flag==1&&a==25)
{
String temp=box[2][1];
box [2][1] =box[3][1];
box [3][1] =temp;
flag=2;
}
else if(a==41&&flag==3)
{
String temp=box[4][1];
box [4][1] =box[5][1];
box [5][1] =temp;
flag=4;
}
//open source
//lol ik
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
break;
}
case Wp2:
{ int p;
int a=in.nextInt();
if(a==18)
p=1;
else if(a==26&&flag==1)
p=2;
else if(a==34)
p=3;
else if(a==42)
p=4;
else if(a==26&&flag==0)
{
String k =box[3][2];
box[3][2]=box[1][2];
box[1][2]=k;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
flag=1;
}
break;
}
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
String temp=box[p+1][2];
box[p+1][2]=box[p][2];
box[p][2] =temp;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
break;
}
case Wp3:
{ int p;
int a=in.nextInt();
if(a==19)
p=1;
else if(a==27&&flag==1)
p=2;
else if(a==35)
p=3;
else if(a==43)
p=4;
else if(a==27&&flag==0)
{
String k=box[3][3];
box[3][3]=box[1][3];
box[1][3] =k;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
flag=1;
}
break;
}
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
String temp=box[p+1][3];
box[p+1][3]=box[p][3];
box[p][3] =temp;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
break;
}
case Wp5:
{ int p;
int a=in.nextInt();
if(a==21)
p=1;
else if(a==29&&flag==1)
p=2;
else if(a==37)
p=3;
else if(a==45)
p=4; else if(a==29&&flag==0)
{
String k=box[3][5];
box[3][5]=box[1][5];
box[1][5] =k;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
flag=1;
}
break;
}
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
String temp=box[p+1][5];
box[p+1][5]=box[p][5];
box[p][5] =temp;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
break;
}
case Wp4:
{ int p;
int a=in.nextInt();
if(a==20)
{p=1;}
else if(a==28&&flag==1)
{p=2;
}
else if(a==36)
{p=3;}
else if(a==44)
{ p=4; }
else if(a==28&&flag==0)
{
String k=box[3][4];
box[3][4]=box[1][4];
box[1][4] =k;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
flag=1;
}
break;
}
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
String temp=box[p+1][4];
box[p+1][4]=box[p][4];
box[p][4] =temp;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
break;
}
case Wp6:
{ int p;
int a=in.nextInt();
if(a==22)
{p=1;}
else if(a==30&&flag==1)
{p=2;
}
else if(a==38)
{p=3;}
else if(a==46)
{ p=4; }
else if(a==30&&flag==0)
{
String k=box[3][6];
box[3][6]=box[1][6];
box[1][6] =k;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
flag=1;
}
break;
}
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
String temp=box[p+1][6];
box[p+1][6]=box[p][6];
box[p][6] =temp;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}//Samurai X
break;
}
case Wp7:
{ int p;
int a=in.nextInt();
if(a==23)
{p=1;}
else if(a==31&&flag==1)
{p=2;
}
else if(a==39)
{p=3;}
else if(a==47)
{ p=4; }
else if(a==31&&flag==0)
{
String k=box[3][7];
box[3][7]=box[1][7];
box[1][7] =k;
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
flag=1;
}
break;
}
else
{
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
System.out.println(/*lol ik*/"");
System.out.println(/*lol ik*/"Invalid Move "+a);
break;
}
String temp=box[p+1][7];
box[p+1][7]=box[p][7];
box[p][7] =temp;
//lol ik @opensource
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
break;
}
//Finally White Pawn Movement Ends
case WE1:
{
int o,s=0;
outerloop:
for(o=q;o<8;o++)
{
String temp=box[f][o];
for (int w =0; w <4 ; w++)
{
if(temp.charAt(w)== ('W'))
{
break outerloop; //Recognizing white piece
}
else
s++;
}
}
outer:
if((s/4)>0)
{
String a=in.next();
String Str=" "+a+" ";
for(q=0; q < 8; q++)
{
if(box[0][q].equals(Str))
{
String temp=box[f][q];
box[f][q]=box[f][0];
box[f][0] =temp;
o=q;
break outer;
}
}
}
for(i=0;i<8;i++)
{
System.out.println();
for(j=0;j<8;j++)
{
System.out.print(box[i][j]);
}
}
}
break;
default :
{
System.out.println("wrong input");
}
}
}
catch (Exception e)
{
System.out.println("");
System.out.println("Player Turn");
cont=1;
}
}
while(cont==1)
{
System.out.println("Comp Turn");
cont=0;
break;
}
}
}
}
I will try to make more post from today....
posted by lol ik
Comments
Post a Comment