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
26c95b6a
Commit
26c95b6a
authored
Apr 25, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playground -> canMove updated
parent
ca8e1e8e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
23 deletions
+25
-23
PlayGround.java
src/pack/PlayGround.java
+25
-23
No files found.
src/pack/PlayGround.java
View file @
26c95b6a
...
@@ -14,7 +14,6 @@ public class PlayGround {
...
@@ -14,7 +14,6 @@ public class PlayGround {
private
Queen
wQueen
,
bQueen
;
private
Queen
wQueen
,
bQueen
;
private
King
wKing
,
bKing
;
private
King
wKing
,
bKing
;
public
PlayGround
()
{
public
PlayGround
()
{
nutsID
=
new
HashMap
<>();
nutsID
=
new
HashMap
<>();
...
@@ -194,25 +193,20 @@ public class PlayGround {
...
@@ -194,25 +193,20 @@ public class PlayGround {
}
}
public
short
canMove
(
String
[]
string
,
int
turn
)
{
public
short
canMove
(
String
[]
string
,
int
turn
)
{
if
(
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
)))
==
0
)
//6 mabda mohree nist
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
return
6
;
return
6
;
if
(
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
)))
*
getNutID
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)))
>
0
)
//2 destination is not empty
if
(
id1
*
id2
>
0
)
//2 destination is not empty
return
2
;
return
2
;
Nut
j
=
null
;
// Todo shayad bekhad on mohre ro bezare jelosh
// Todo shayad bekhad on mohre ro bezare jelosh
boolean
check
;
//4 cant move because of check
boolean
check
;
//4 cant move because of check
if
(
turn
==
1
)
check
=
wKing
.
isCheck
();
else
check
=
bKing
.
isCheck
();
if
(
check
)
return
4
;
Nut
j
=
null
;
//5 if nut moves, king will be check
for
(
Nut
i
:
nutsID
.
keySet
())
{
for
(
Nut
i
:
nutsID
.
keySet
())
{
j
=
i
;
j
=
i
;
if
(
nutsID
.
get
(
i
)
==
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
)))
)
{
if
(
nutsID
.
get
(
i
)
==
id1
)
{
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))));
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))));
break
;
break
;
}
}
...
@@ -222,21 +216,26 @@ public class PlayGround {
...
@@ -222,21 +216,26 @@ public class PlayGround {
check
=
wKing
.
isCheck
();
check
=
wKing
.
isCheck
();
else
else
check
=
bKing
.
isCheck
();
check
=
bKing
.
isCheck
();
//todo reverse sarbaz mojaze
j
.
move
(
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))));
j
.
move
(
getDestination
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))));
if
(
check
)
return
5
;
if
(
check
)
return
4
;
j
=
null
;
// on mohre on harekato nemitone bere
// on mohre on harekato nemitone bere
for
(
Nut
i
:
nutsID
.
keySet
())
{
for
(
Nut
i
:
nutsID
.
keySet
())
{
if
(
nutsID
.
get
(
i
)
==
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))))
{
if
(
nutsID
.
get
(
i
)
==
id1
)
{
if
(!
i
.
canMove
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)))))
return
7
;
if
(!
i
.
canMove
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
)))))
return
5
;
else
break
;
else
{
if
(
Math
.
abs
(
id1
)
<
9
&&
string
[
0
].
charAt
(
0
)
!=
string
[
1
].
charAt
(
0
)
&&
id2
==
0
)
return
5
;
break
;
}
}
}
}
}
// the route can not be traversed
// the route can not be traversed
for
(
Nut
i
:
nutsID
.
keySet
())
{
for
(
Nut
i
:
nutsID
.
keySet
())
{
if
(
nutsID
.
get
(
i
)
==
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
)))
)
{
if
(
nutsID
.
get
(
i
)
==
id1
)
{
if
(!
i
.
canRoute
())
return
3
;
if
(!
i
.
canRoute
())
return
3
;
else
break
;
else
break
;
}
}
...
@@ -247,6 +246,9 @@ public class PlayGround {
...
@@ -247,6 +246,9 @@ public class PlayGround {
}
}
public
void
moveNut
(
String
[]
string
)
{
public
void
moveNut
(
String
[]
string
)
{
if
(
getNutID
(
string
[
1
].
charAt
(
0
),
(
short
)
string
[
1
].
charAt
(
1
))
==
0
)
for
(
Nut
i
:
nutsID
.
keySet
())
{
for
(
Nut
i
:
nutsID
.
keySet
())
{
if
(
nutsID
.
get
(
i
)
==
getNutID
(
string
[
0
].
charAt
(
0
),
(
short
)
(
string
[
0
].
charAt
(
1
))))
{
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
))));
i
.
move
(
getDestination
(
string
[
1
].
charAt
(
0
),
(
short
)
(
string
[
1
].
charAt
(
1
))));
...
...
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