Commit 41b1e007 authored by Robert Yates's avatar Robert Yates

initial commit

parents
File added
import java.util.Scanner;
import javax.lang.model.util.ElementScanner6;
import java.util.Random;
public class App
{
private static int[][] Board = {{0,0,0},{0,0,0},{0,0,0}};
private static String[] PrintValues = {" ","o","x"};
public static String WINCHECK()
{
String output = "";
boolean zerofound = false;
for(int x = 0; x < 3 && !zerofound ; x++)
{
for(int y = 0; y < 3 && !zerofound ; y++)
{
if(Board[x][y] == 0){
zerofound = true;
}
}
}
if(!zerofound)
{
output = "3";
}
for(int i = 0; i < 3; i++)
{
if(Board[i][0] != 0 && Board[i][0] == Board[i][1] && Board[i][0] == Board[i][2])
{
output = String.valueOf(Board[i][0]);
}
}
for(int j = 0; j < 3; j++)
{
if(Board[0][j] != 0 && Board[0][j] == Board[1][j] && Board[0][j] == Board[2][j])
{
output = String.valueOf(Board[0][j]);
}
}
if(Board[0][0] != 0 && Board[0][0] == Board[1][1] && Board[0][0] == Board[2][2])
{
output = String.valueOf(Board[0][0]);
}
else if(Board[0][2] != 0 && Board[0][2] == Board[1][1] && Board[0][2] == Board[2][0])
{
output = String.valueOf(Board[0][2]);
}
return(output);
}
public static void main(String[] args) throws Exception
{
Scanner myObj= new Scanner(System.in);;
boolean turn = true;
while(true)
{
System.out.println("-----");
for(int yp = 2; yp > -1; yp--)
{
System.out.println(PrintValues[Board[0][yp]].toString() + "|" + PrintValues[Board[1][yp]].toString()+ "|" + PrintValues[Board[2][yp]].toString());
System.out.println("-----");
}
String win = WINCHECK();
boolean movevalid = false;
if(win.equals(""))
{
int digit = 1;
if(!turn)
{
digit = 2;
}
String x = "";
String y = "";
while(!movevalid)
{
if(turn)
{
myObj = new Scanner(System.in);
System.out.println("Input A Moves x pos ");
x = myObj.nextLine();
myObj = new Scanner(System.in);
System.out.println("Input A Moves y pos ");
y = myObj.nextLine();
//Integer.parseInt(input)
}
else
{
Random rand = new Random();
// Obtain a number between [0 - 49].
x = String.valueOf(rand.nextInt(4));
y = String.valueOf(rand.nextInt(4));
}
try
{
movevalid = Board[Integer.parseInt(x)][Integer.parseInt(y)] == 0;
}
catch(Exception e){}
}
Board[Integer.parseInt(x)][Integer.parseInt(y)] = digit;
turn=!turn;
}
else if(win.equals("1"))
{
System.out.println("Nout Wins");
break;
}
else if(win.equals("2"))
{
System.out.println("Cross Wins");
break;
}
else if(win.equals("3"))
{
System.out.println("Draw");
break;
}
else
{
System.out.println(win.toString());
break;
}
}
myObj.close();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment