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
80bf4e90
Commit
80bf4e90
authored
Apr 26, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playground -> isCheck added
parent
8519d4bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
113 deletions
+45
-113
PlayGround.java
src/pack/PlayGround.java
+45
-113
No files found.
src/pack/PlayGround.java
View file @
80bf4e90
...
...
@@ -5,7 +5,7 @@ import pack.Nuts.*;
import
java.util.HashMap
;
public
class
PlayGround
{
private
int
[][]
ground
;
private
static
int
[][]
ground
;
private
HashMap
<
Nut
,
Integer
>
nutsID
;
private
Pawn
[]
wPawns
,
bPawns
;
private
Rook
[]
wRooks
,
bRooks
;
...
...
@@ -106,104 +106,19 @@ public class PlayGround {
}
public
void
showPlayGround
()
{
System
.
out
.
print
(
" 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
(
" ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ "
);
}
public
short
canMove
(
String
[]
string
,
int
turn
)
{
int
id1
=
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
)));
int
id2
=
getNutID
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)));
if
(
id1
==
0
)
//6 mabda mohree nist
int
id1
=
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))),
id2
=
getNutID
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)));
if
(
id1
==
0
)
//6 mabda mohree nist
return
6
;
if
(
id1
*
id2
>
0
)
//2 destination is not empty
if
(
id1
*
turn
<
0
)
//7 check turn
return
7
;
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
;
// Todo shayad bekhad on mohre ro bezare jelosh
boolean
check
;
//4 cant move because of check
short
check
;
//4 cant move because of check
for
(
Nut
i
:
nutsID
.
keySet
())
{
j
=
i
;
if
(
nutsID
.
get
(
i
)
==
id1
)
{
...
...
@@ -212,12 +127,9 @@ public class PlayGround {
}
}
if
(
turn
==
1
)
check
=
wKing
.
isCheck
();
else
check
=
bKing
.
isCheck
();
check
=
isCheck
();
j
.
move
(
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))));
if
(
check
)
return
4
;
if
(
check
!=
0
)
return
4
;
j
=
null
;
...
...
@@ -226,7 +138,7 @@ public class PlayGround {
if
(
nutsID
.
get
(
i
)
==
id1
)
{
if
(!
i
.
canMove
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)))))
return
5
;
else
{
if
(
Math
.
abs
(
id1
)
<
9
&&
string
[
0
].
charAt
(
0
)
!=
string
[
1
].
charAt
(
0
)
&&
id2
==
0
)
if
(
Math
.
abs
(
id1
)
<
9
&&
string
[
0
].
charAt
(
0
)
!=
string
[
1
].
charAt
(
0
)
&&
id2
==
0
)
return
5
;
break
;
}
...
...
@@ -236,7 +148,8 @@ public class PlayGround {
// the route can not be traversed
for
(
Nut
i
:
nutsID
.
keySet
())
{
if
(
nutsID
.
get
(
i
)
==
id1
)
{
if
(!
i
.
canRoute
())
return
3
;
if
(!
i
.
canRoute
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))),
getGround
()))
return
3
;
else
break
;
}
}
...
...
@@ -245,33 +158,52 @@ public class PlayGround {
return
1
;
//1 can move
}
//todo first move pawn ke mitone 2 ta bere!
public
void
moveNut
(
String
[]
string
)
{
if
(
getNutID
(
string
[
1
].
charAt
(
0
),
(
short
)
string
[
1
].
charAt
(
1
))
==
0
)
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
))));
break
;
}
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
))));
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
;
}
public
int
getNutID
(
char
c
,
short
s
)
{
return
ground
[
8
-
s
][(
int
)
(
c
)
-
97
];
private
void
removeNut
(
int
id
)
{
for
(
Nut
i
:
nutsID
.
keySet
())
if
(
nutsID
.
get
(
i
)
==
id
)
{
i
.
changeAlive
();
nutsID
.
remove
(
i
,
id
);
break
;
}
}
public
int
getNutID
(
int
i
,
int
j
)
{
return
ground
[
i
][
j
];
public
int
getNutID
(
char
c
,
short
s
)
{
return
ground
[
56
-
s
][(
int
)
(
c
)
-
97
];
}
public
int
[]
getDestination
(
char
c
,
short
s
)
{
int
[]
r
=
new
int
[
2
];
r
[
0
]
=
8
-
s
;
r
[
0
]
=
56
-
s
;
r
[
1
]
=
(
int
)
c
-
97
;
return
r
;
}
public
static
int
[][]
getGround
()
{
return
ground
;
}
public
short
isCheck
()
{
return
0
;
}
}
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