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
9731075
chess
Commits
41971b18
Commit
41971b18
authored
Apr 26, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playground -> show
parent
974a22f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
24 deletions
+139
-24
PlayGround.java
src/pack/PlayGround.java
+139
-24
No files found.
src/pack/PlayGround.java
View file @
41971b18
...
...
@@ -13,9 +13,11 @@ public class PlayGround {
private
Bishop
[]
wBishops
,
bBishops
;
private
Queen
wQueen
,
bQueen
;
private
King
wKing
,
bKing
;
public
boolean
check
;
public
PlayGround
()
{
nutsID
=
new
HashMap
<>();
check
=
false
;
wPawns
=
new
Pawn
[
8
];
bPawns
=
new
Pawn
[
8
];
...
...
@@ -88,8 +90,8 @@ public class PlayGround {
ground
[
0
][
0
]
=
-
10
;
ground
[
0
][
1
]
=
-
12
;
ground
[
0
][
2
]
=
-
14
;
ground
[
0
][
3
]
=
-
1
6
;
ground
[
0
][
4
]
=
-
1
5
;
ground
[
0
][
3
]
=
-
1
5
;
ground
[
0
][
4
]
=
-
1
6
;
ground
[
0
][
5
]
=
-
13
;
ground
[
0
][
6
]
=
-
11
;
ground
[
0
][
7
]
=
-
9
;
...
...
@@ -117,23 +119,22 @@ public class PlayGround {
if
((
Math
.
abs
(
id1
)
<
9
&&
string
[
0
].
charAt
(
0
)
==
string
[
1
].
charAt
(
0
)
&&
id2
!=
0
)
||
(
id1
*
id2
>
0
))
//2 check destination is empty or enemy nut
return
2
;
Nut
j
=
null
;
short
check
;
//4 cant move because of
check
Nut
j
=
null
;
//4
check
for
(
Nut
i
:
nutsID
.
keySet
())
{
j
=
i
;
if
(
nutsID
.
get
(
i
)
==
id1
)
{
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))));
j
=
i
;
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))),
ground
);
break
;
}
}
check
=
isCheck
();
j
.
move
(
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))));
if
(
check
!=
0
)
return
4
;
j
=
null
;
isCheck
(
turn
);
j
.
move
(
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))),
ground
);
if
(
getCheck
())
return
4
;
// on mohre on harekato nemitone bere
//
5
on mohre on harekato nemitone bere
for
(
Nut
i
:
nutsID
.
keySet
())
{
if
(
nutsID
.
get
(
i
)
==
id1
)
{
if
(!
i
.
canMove
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)))))
return
5
;
...
...
@@ -154,26 +155,19 @@ public class PlayGround {
}
}
return
1
;
//1 can move
}
//todo first move pawn ke mitone 2 ta bere!
public
void
moveNut
(
String
[]
string
)
{
int
id2
=
getNutID
(
string
[
1
].
charAt
(
0
),
(
short
)
string
[
1
].
charAt
(
1
)),
id1
=
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
string
[
0
].
charAt
(
1
));
if
(
id2
!=
0
)
removeNut
(
id2
);
for
(
Nut
i
:
nutsID
.
keySet
())
if
(
nutsID
.
get
(
i
)
==
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
)))
)
{
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))));
if
(
nutsID
.
get
(
i
)
==
id1
)
{
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)))
,
ground
);
break
;
}
ground
[
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
string
[
0
].
charAt
(
1
))[
0
]][
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
string
[
0
].
charAt
(
1
))[
1
]]
=
0
;
ground
[
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
string
[
1
].
charAt
(
1
))[
0
]][
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
string
[
1
].
charAt
(
1
))[
1
]]
=
id1
;
}
private
void
removeNut
(
int
id
)
{
...
...
@@ -200,10 +194,131 @@ public class PlayGround {
return
ground
;
}
public
short
isCheck
()
{
public
void
isCheck
(
int
turn
)
{
if
(
turn
==
1
)
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
if
(
bPawns
[
i
].
canCheck
(
wKing
.
getXY
()))
{
check
=
true
;
return
;
}
if
((
bQueen
.
canMove
(
wKing
.
getXY
())
&&
bQueen
.
canRoute
(
wKing
.
getXY
(),
ground
))
||
(
bRooks
[
0
].
canMove
(
wKing
.
getXY
())
&&
bRooks
[
0
].
canRoute
(
wKing
.
getXY
(),
ground
))
||
(
bRooks
[
1
].
canMove
(
wKing
.
getXY
())
&&
bRooks
[
1
].
canRoute
(
wKing
.
getXY
(),
ground
))
||
(
bKnights
[
0
].
canMove
(
wKing
.
getXY
())
&&
bKnights
[
0
].
canRoute
(
wKing
.
getXY
(),
ground
))
||
(
bKnights
[
1
].
canMove
(
wKing
.
getXY
())
&&
bKnights
[
1
].
canRoute
(
wKing
.
getXY
(),
ground
))
||
(
bBishops
[
0
].
canMove
(
wKing
.
getXY
())
&&
bBishops
[
0
].
canRoute
(
wKing
.
getXY
(),
ground
))
||
(
bBishops
[
1
].
canMove
(
wKing
.
getXY
())
&&
bBishops
[
1
].
canRoute
(
wKing
.
getXY
(),
ground
))
)
{
check
=
true
;
return
;
}
}
else
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
if
(
wPawns
[
i
].
canCheck
(
bKing
.
getXY
()))
{
check
=
true
;
return
;
}
if
((
wQueen
.
canMove
(
bKing
.
getXY
())
&&
wQueen
.
canRoute
(
bKing
.
getXY
(),
ground
))
||
(
wRooks
[
0
].
canMove
(
bKing
.
getXY
())
&&
wRooks
[
0
].
canRoute
(
bKing
.
getXY
(),
ground
))
||
(
wRooks
[
1
].
canMove
(
bKing
.
getXY
())
&&
wRooks
[
1
].
canRoute
(
bKing
.
getXY
(),
ground
))
||
(
wKnights
[
0
].
canMove
(
bKing
.
getXY
())
&&
wKnights
[
0
].
canRoute
(
bKing
.
getXY
(),
ground
))
||
(
wKnights
[
1
].
canMove
(
bKing
.
getXY
())
&&
wKnights
[
1
].
canRoute
(
bKing
.
getXY
(),
ground
))
||
(
wBishops
[
0
].
canMove
(
bKing
.
getXY
())
&&
wBishops
[
0
].
canRoute
(
bKing
.
getXY
(),
ground
))
||
(
wBishops
[
1
].
canMove
(
bKing
.
getXY
())
&&
wBishops
[
1
].
canRoute
(
bKing
.
getXY
(),
ground
))
)
{
check
=
true
;
return
;
}
}
check
=
false
;
}
public
boolean
getCheck
()
{
return
check
;
}
public
void
show
()
{
System
.
out
.
print
(
"\n\n a b c d e f g h\n _ _ _ _ _ _ _ _\n"
);
for
(
int
i
=
0
,
j
;
i
<
8
;
i
++)
{
System
.
out
.
print
((
8
-
i
)
+
" "
);
for
(
j
=
0
;
j
<
8
;
j
++)
{
switch
(
ground
[
i
][
j
])
{
case
0
:
System
.
out
.
print
(
"| "
);
break
;
case
1
:
case
2
:
case
3
:
case
4
:
case
5
:
case
6
:
case
7
:
case
8
:
System
.
out
.
print
(
"|P"
);
break
;
case
-
1
:
case
-
2
:
case
-
3
:
case
-
4
:
case
-
5
:
case
-
6
:
case
-
7
:
case
-
8
:
System
.
out
.
print
(
"|p"
);
break
;
case
9
:
case
10
:
System
.
out
.
print
(
"|R"
);
break
;
case
-
9
:
case
-
10
:
System
.
out
.
print
(
"|r"
);
break
;
case
11
:
case
12
:
System
.
out
.
print
(
"|K"
);
break
;
case
-
11
:
case
-
12
:
System
.
out
.
print
(
"|k"
);
break
;
case
13
:
case
14
:
System
.
out
.
print
(
"|B"
);
break
;
case
-
13
:
case
-
14
:
System
.
out
.
print
(
"|b"
);
break
;
case
15
:
System
.
out
.
print
(
"|Q"
);
break
;
case
-
15
:
System
.
out
.
print
(
"|q"
);
break
;
case
16
:
System
.
out
.
print
(
"|X"
);
break
;
case
-
16
:
System
.
out
.
print
(
"|x"
);
}
}
System
.
out
.
print
(
"|\n"
);
}
System
.
out
.
println
(
" ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ "
);
return
0
;
}
}
}
\ 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