Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Programming
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
robert.yates
Java Programming
Commits
41b1e007
Commit
41b1e007
authored
Feb 14, 2022
by
Robert Yates
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
App.class
App.class
+0
-0
NoutsAndCrosses.java
NoutsAndCrosses.java
+135
-0
No files found.
App.class
0 → 100644
View file @
41b1e007
File added
NoutsAndCrosses.java
0 → 100644
View file @
41b1e007
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment