package semBreak;
import java.io.*;
public class YLingaw {
public static void main (String [] args) throws IOException {
BufferedReader jill = new BufferedReader (new InputStreamReader (System.in));
char[][] board = { {' ','1','2','3',' '},
{'1',' ',' ',' ','1'},
{'2',' ',' ',' ','2'},
{'3',' ',' ',' ','3'},
{' ','1','2','3',' '}};
YLingaw.ehem(board);
int as = 3, o = 3;
boolean team = true; boolean win = false;
do{
if(team){
boolean empty = true;
do{
System.out.print("*: ");
String move = jill.readLine();
int a = Integer.parseInt(String.valueOf(move.charAt(0)));
int b = Integer.parseInt(String.valueOf(move.charAt(1)));
if(board[a][b] == ' '){
board[a][b] = '*';
}
else{
empty = false;
}
}while(!empty);
as--;
team = false;
}
else{
boolean empty = true;
do{
System.out.print("o: ");
String move = jill.readLine();
int a = Integer.parseInt(String.valueOf(move.charAt(0)));
int b = Integer.parseInt(String.valueOf(move.charAt(1)));
if(board[a][b] == ' '){
board[a][b] = 'o';
}
else{
empty = false;
}
}while(!empty);
team = true;
o--;
}
YLingaw.ehem(board);
}while(as >= 0 && o > 0);
boolean done = false;
do{
if(team){
boolean ok = false;
do{
System.out.print("*: ");
String move = jill.readLine();
int a = Integer.parseInt(String.valueOf(move.charAt(0)));
int b = Integer.parseInt(String.valueOf(move.charAt(1)));
int c = Integer.parseInt((String.valueOf(move.charAt(3))));
int d = Integer.parseInt(String.valueOf(move.charAt(4)));
if(board[a][b] == '*' && board[c][d] == ' '){
if((a-c==1 || c-a==1) && b==d){
board[a][b] = ' '; board[c][d] = '*';
ok = true;
}
else if(a==c && (b-d==1||d-b==1)){
board[a][b] = ' '; board[c][d] = '*';
ok = true;
}
else if((a==b&&c==d) &&((a-c==1||c-a==1)) &&(b-d==1||d-b==1)){
board[a][b] = ' '; board[c][d] = '*';
ok = true;
}
else if(a==b&&(((a-c==1||c-a==1)&&b==d)||(b-d==1||d-b==1&&(a==c)))){
board[a][b] = ' '; board[c][d] = '*';
ok = true;
}
}
else{
ok = false;
}
}while(!ok);
team = false;
}
else{
boolean ok = false;
do{
System.out.print("o: ");
String move = jill.readLine();
int a = Integer.parseInt(String.valueOf(move.charAt(0)));
int b = Integer.parseInt(String.valueOf(move.charAt(1)));
int c = Integer.parseInt((String.valueOf(move.charAt(3))));
int d = Integer.parseInt(String.valueOf(move.charAt(4)));
if(board[a][b] == 'o' && board[c][d] == ' '){
if((a-c==1 || c-a==1) && b==d){
board[a][b] = ' '; board[c][d] = 'o';
ok = true;
}
else if(a==c && (b-d==1||d-b==1)){
board[a][b] = ' '; board[c][d] = 'o';
ok = true;
}
else if((a==b&&c==d) &&((a-c==1||c-a==1)) &&(b-d==1||d-b==1)){
board[a][b] = ' '; board[c][d] = 'o';
ok = true;
}
else if(a==b&&(((a-c==1||c-a==1)&&b==d)||(b-d==1||d-b==1&&(a==c)))){
board[a][b] = ' '; board[c][d] = 'o';
ok = true;
}
}
else{
ok = false;
}
}while(!ok);
team = true;
}
YLingaw.ehem(board);
main:for(int x =1; x <= 3; x++){
int same = 0;
for(int y = 1; y <= 3; y++){
if(board[x][y] == '*'){
same++;
}
}
if(same == 3){
done = true;
win = true;
break main;
}
}
if(!done){
main:for(int x = 1; x <= 3; x++){
int same = 0;
for(int y = 1; y <= 3; y++){
if(board[y][x] == '*'){
same++;
}
}
if(same == 3){
done = true;
win = true;
break main;
}
}
}
if(!done){
int same = 0;
for(int x = 1; x <= 3; x++){
if(board[x][x] == '*'){
same++;
}
}
if(same == 3){
done = true;
win = true;
}
}
if(!done){
int same = 0;
for(int x = 1; x <= 3; x++){
int y = 4-x;
if(board[x][y] == '*'){
same++;
}
}
if(same == 3){
done = true;
win = true;
}
}
if(!done){
main:for(int x =1; x <= 3; x++){
int same = 0;
for(int y = 1; y <= 3; y++){
if(board[x][y] == 'o'){
same++;
}
}
if(same == 3){
done = true;
win = false;
break main;
}
}
if(!done){
main:for(int x = 1; x <= 3; x++){
int same = 0;
for(int y = 1; y <= 3; y++){
if(board[y][x] == 'o'){
same++;
}
}
if(same == 3){
done = true;
win = false;
break main;
}
}
}
if(!done){
int same = 0;
for(int x = 1; x <= 3; x++){
if(board[x][x] == 'o'){
same++;
}
}
if(same == 3){
done = true;
win = false;
}
}
if(!done){
int same = 0;
for(int x = 1; x <= 3; x++){
int y = 4-x;
if(board[x][y] == 'o'){
same++;
}
}
if(same == 3){
done = true;
win = false;
}
}
}
}while(!done);
if(win){
System.out.println("Congratulations! * wins!");
}
else{
System.out.println("Congratulations! o wins!");
}
}
public static void ehem(char[][]a){
for(int x = 0; x < 5; x++){
for(int y = 0; y < 5; y++){
System.out.print(a[x][y] + " ");
}
System.out.println();
}
}
}
This is a simple console game. At first three moves you just input the asked ordinate base on the ordinates drawn in the board. The after the first three you need to move the stones you put. To move: input first the stone you want to move and then enter the ordinate where you want to move. My problem is that i made a condition to win. It works if your stones are straight in first column. But if you had straight in second or third there will be interruption. Please help me.