Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
Chess
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
9631408
Chess
Commits
633367f9
Commit
633367f9
authored
May 16, 2019
by
kimia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
who's turn?
parent
9dfb84e8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
193 additions
and
176 deletions
+193
-176
Main.java
src/Main.java
+193
-176
No files found.
src/Main.java
View file @
633367f9
...
@@ -6,9 +6,10 @@ public class Main{
...
@@ -6,9 +6,10 @@ public class Main{
*@version 1.0
*@version 1.0
*@since 2019-5-7
*@since 2019-5-7
*/
*/
private
static
char
boardChar
[][]
=
new
char
[
8
][
8
]
;
private
static
char
boardChar
[][]
=
new
char
[
8
][
8
]
;
private
static
void
printBoard
()
{
private
static
void
printBoard
()
{
for
(
int
i
=
1
;
i
<
9
;
++
i
)
{
for
(
int
i
=
1
;
i
<
9
;
++
i
)
{
System
.
out
.
print
(
" "
+
i
)
;
System
.
out
.
print
(
" "
+
i
)
;
}
}
...
@@ -28,7 +29,7 @@ private static void printBoard() {
...
@@ -28,7 +29,7 @@ private static void printBoard() {
}
}
}
}
private
static
void
updateBoard
(
Piece
pw
[],
Piece
pb
[])
{
private
static
void
updateBoard
(
Piece
pw
[],
Piece
pb
[])
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
{
for
(
int
j
=
0
;
j
<
8
;
++
j
)
{
for
(
int
j
=
0
;
j
<
8
;
++
j
)
{
boardChar
[
i
][
j
]
=
' '
;
boardChar
[
i
][
j
]
=
' '
;
...
@@ -54,7 +55,7 @@ private static void updateBoard(Piece pw[], Piece pb[]) {
...
@@ -54,7 +55,7 @@ private static void updateBoard(Piece pw[], Piece pb[]) {
}
}
}
}
private
static
void
checkCondition
(
Cell
board
[][],
Piece
pw
[],
Piece
pb
[])
{
private
static
void
checkCondition
(
Cell
board
[][],
Piece
pw
[],
Piece
pb
[])
{
for
(
Piece
p:
pw
)
{
for
(
Piece
p:
pw
)
{
if
(
p
instanceof
King
)
{
if
(
p
instanceof
King
)
{
int
sw1
=
0
;
int
sw1
=
0
;
...
@@ -79,7 +80,7 @@ private static void checkCondition(Cell board[][], Piece pw[], Piece pb[]) {
...
@@ -79,7 +80,7 @@ private static void checkCondition(Cell board[][], Piece pw[], Piece pb[]) {
}
}
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Scanner
in
=
new
Scanner
(
System
.
in
)
;
Scanner
in
=
new
Scanner
(
System
.
in
)
;
Player
white
=
new
Player
(
Color
.
WHITE
)
;
Player
white
=
new
Player
(
Color
.
WHITE
)
;
Player
black
=
new
Player
(
Color
.
BLACK
)
;
Player
black
=
new
Player
(
Color
.
BLACK
)
;
...
@@ -102,7 +103,8 @@ public static void main(String[] args) {
...
@@ -102,7 +103,8 @@ public static void main(String[] args) {
updateBoard
(
pw
,
pb
)
;
updateBoard
(
pw
,
pb
)
;
printBoard
()
;
printBoard
()
;
while
(
true
)
{
while
(
true
)
{
wORb
++
;
if
(
wORb
%
2
==
0
)
System
.
out
.
println
(
"White player turn"
)
;
else
System
.
out
.
println
(
"Black player turn"
)
;
String
s
=
in
.
nextLine
()
;
String
s
=
in
.
nextLine
()
;
if
(
s
.
length
()==
2
)
{
if
(
s
.
length
()==
2
)
{
for
(
Piece
p:
pw
)
{
for
(
Piece
p:
pw
)
{
...
@@ -135,10 +137,12 @@ public static void main(String[] args) {
...
@@ -135,10 +137,12 @@ public static void main(String[] args) {
}
}
}
}
else
if
(
s
.
length
()==
5
)
{
else
if
(
s
.
length
()==
5
)
{
if
(
wORb
%
2
==
0
)
{
for
(
Piece
p:
pw
)
{
for
(
Piece
p:
pw
)
{
if
(
p
.
getCell
().
getRow
()==
s
.
charAt
(
0
)-
'a'
&&
if
(
p
.
getCell
().
getRow
()==
s
.
charAt
(
0
)-
'a'
&&
p
.
getCell
().
getCol
()+
1
==
s
.
charAt
(
1
)-
'0'
)
{
p
.
getCell
().
getCol
()+
1
==
s
.
charAt
(
1
)-
'0'
)
{
if
(
p
.
isValidMove
(
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
),
board
,
pw
,
pb
))
{
if
(
p
.
isValidMove
(
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
),
board
,
pw
,
pb
))
{
wORb
++
;
Cell
tmp
=
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
)
;
Cell
tmp
=
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
)
;
board
[
p
.
getCell
().
getRow
()][
p
.
getCell
().
getCol
()].
setEmpty
(
true
)
;
board
[
p
.
getCell
().
getRow
()][
p
.
getCell
().
getCol
()].
setEmpty
(
true
)
;
p
.
setCell
(
tmp
)
;
p
.
setCell
(
tmp
)
;
...
@@ -160,10 +164,19 @@ public static void main(String[] args) {
...
@@ -160,10 +164,19 @@ public static void main(String[] args) {
}
}
}
}
}
}
if
(
wORb
%
2
==
0
)
System
.
out
.
println
(
"please enter a valid move!"
)
;
else
{
checkCondition
(
board
,
pw
,
pb
)
;
updateBoard
(
pw
,
pb
)
;
printBoard
()
;
}
}
else
{
for
(
Piece
p:
pb
)
{
for
(
Piece
p:
pb
)
{
if
(
p
.
getCell
().
getRow
()==
s
.
charAt
(
0
)-
'a'
&&
if
(
p
.
getCell
().
getRow
()==
s
.
charAt
(
0
)-
'a'
&&
p
.
getCell
().
getCol
()+
1
==
s
.
charAt
(
1
)-
'0'
)
p
.
getCell
().
getCol
()+
1
==
s
.
charAt
(
1
)-
'0'
)
if
(
p
.
isValidMove
(
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
),
board
,
pw
,
pb
)
)
{
if
(
p
.
isValidMove
(
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
),
board
,
pw
,
pb
)
)
{
wORb
++
;
Cell
tmp
=
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
)
;
Cell
tmp
=
new
Cell
(
s
.
charAt
(
3
)-
'a'
,
s
.
charAt
(
4
)-
'1'
)
;
board
[
p
.
getCell
().
getRow
()][
p
.
getCell
().
getCol
()].
setEmpty
(
true
)
;
board
[
p
.
getCell
().
getRow
()][
p
.
getCell
().
getCol
()].
setEmpty
(
true
)
;
p
.
setCell
(
tmp
)
;
p
.
setCell
(
tmp
)
;
...
@@ -184,15 +197,19 @@ public static void main(String[] args) {
...
@@ -184,15 +197,19 @@ public static void main(String[] args) {
}
}
}
}
}
}
if
(
wORb
%
2
==
1
)
System
.
out
.
println
(
"please enter a valid move!"
)
;
else
{
checkCondition
(
board
,
pw
,
pb
)
;
checkCondition
(
board
,
pw
,
pb
)
;
updateBoard
(
pw
,
pb
)
;
updateBoard
(
pw
,
pb
)
;
printBoard
()
;
printBoard
()
;
}
}
}
}
else
{
else
{
System
.
out
.
println
(
"Please enter a valid input!"
)
;
System
.
out
.
println
(
"Please enter a valid input!"
)
;
}
}
}
}
}
}
}
}
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