Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Othelo
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
9628055
Othelo
Commits
5ae794c4
Commit
5ae794c4
authored
Mar 31, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add possible moves
parent
c8e2482c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
50 deletions
+109
-50
Main.class
out/production/Othello/Main.class
+0
-0
Map.class
out/production/Othello/Map.class
+0
-0
Main.java
src/Main.java
+10
-4
Map.java
src/Map.java
+99
-46
No files found.
out/production/Othello/Main.class
View file @
5ae794c4
No preview for this file type
out/production/Othello/Map.class
View file @
5ae794c4
No preview for this file type
src/Main.java
View file @
5ae794c4
...
...
@@ -6,12 +6,18 @@ public class Main {
while
(
true
)
{
String
white
=
"| \u26AA |"
;
String
black
=
"| \u26AB |"
;
System
.
out
.
println
(
"Black's turn"
);
map
.
putDisk
(
black
);
System
.
out
.
println
(
"Black's turn
:
"
);
boolean
checkBlack
=
map
.
putDisk
(
black
);
map
.
print
();
System
.
out
.
println
(
"White's turn"
);
map
.
putDisk
(
white
);
System
.
out
.
println
(
"White's turn :"
);
boolean
checkWhite
=
map
.
putDisk
(
white
);
if
(
checkBlack
&&
checkWhite
||
map
.
fullMap
())
{
System
.
out
.
println
(
"game is over !"
);
map
.
findWinner
();
break
;
}
map
.
print
();
}
}
}
src/Map.java
View file @
5ae794c4
...
...
@@ -34,8 +34,15 @@ public class Map {
}
}
public
boolean
getTurn
()
{
return
turn
;
public
boolean
fullMap
()
{
boolean
check
=
true
;
for
(
int
row
=
0
;
row
<
8
;
row
++)
{
for
(
int
col
=
0
;
col
<
8
;
col
++)
{
if
(
checkColor
(
row
,
col
).
equals
(
empty
))
check
=
false
;
}
}
return
check
;
}
public
int
getColNum
(
String
c
)
{
...
...
@@ -69,21 +76,34 @@ public class Map {
return
empty
;
}
public
boolean
checkPutDisk
(
int
row
,
int
col
)
{
public
boolean
checkPossibleMove
(
String
Color
)
{
int
counter
=
0
;
for
(
int
row
=
0
;
row
<
8
;
row
++)
{
for
(
int
col
=
0
;
col
<
8
;
col
++)
{
if
(
checkColor
(
row
,
col
).
equals
(
empty
))
{
if
(
checkPutDisk
(
row
,
col
,
Color
))
{
counter
++;
}
}
}
}
return
counter
!=
0
;
}
public
boolean
checkPutDisk
(
int
row
,
int
col
,
String
Color
)
{
int
counter
=
0
;
for
(
int
plusRow
=
-
1
;
plusRow
<
2
;
plusRow
++)
{
for
(
int
plusCol
=
-
1
;
plusCol
<
2
;
plusCol
++)
{
String
main
=
checkColor
(
row
,
col
);
int
Row
=
row
+
plusRow
;
int
Col
=
col
+
plusCol
;
if
(!(
plusCol
==
0
&&
plusRow
==
0
))
{
if
(
Row
>=
0
&&
Row
<
8
&&
Col
>=
0
&&
Col
<
8
)
{
if
(!
checkColor
(
Row
,
Col
).
equals
(
main
)
&&
!
checkColor
(
Row
,
Col
).
equals
(
empty
))
{
if
(!
checkColor
(
Row
,
Col
).
equals
(
Color
)
&&
!
checkColor
(
Row
,
Col
).
equals
(
empty
))
{
while
(
true
)
{
Row
+=
plusRow
;
Col
+=
plusCol
;
if
(
Row
>=
0
&&
Row
<
8
&&
Col
>=
0
&&
Col
<
8
)
{
if
(
checkColor
(
Row
,
Col
).
equals
(
main
))
{
if
(
checkColor
(
Row
,
Col
).
equals
(
Color
))
{
counter
++;
break
;
}
...
...
@@ -98,25 +118,55 @@ public class Map {
return
counter
!=
0
;
}
public
void
putDisk
(
String
Color
)
{
System
.
out
.
println
(
"Enter Number of row and letter of column :"
);
Scanner
scan
=
new
Scanner
(
System
.
in
);
int
row
=
scan
.
nextInt
();
row
=
row
-
1
;
String
colLetter
=
scan
.
next
();
int
col
=
getColNum
(
colLetter
);
if
(
checkPutDisk
(
row
,
col
))
{
ArrayList
<
String
>
temp
=
map
.
get
(
row
);
if
(
temp
.
get
(
col
).
equals
(
empty
))
{
temp
.
remove
(
col
);
temp
.
add
(
col
,
Color
);
map
.
remove
(
row
);
map
.
add
(
row
,
temp
);
public
void
findWinner
()
{
int
counterBlack
=
0
;
int
counterWhite
=
0
;
for
(
int
row
=
0
;
row
<
8
;
row
++)
{
for
(
int
col
=
0
;
col
<
8
;
col
++)
{
if
(
checkColor
(
row
,
col
).
equals
(
black
))
counterBlack
++;
if
(
checkColor
(
row
,
col
).
equals
(
white
))
counterWhite
++;
}
}
if
(
counterBlack
>
counterWhite
)
System
.
out
.
println
(
"Black won ! Number of disks: "
+
counterBlack
);
if
(
counterWhite
>
counterBlack
)
System
.
out
.
println
(
"White won ! Number of disks: "
+
counterWhite
);
if
(
counterBlack
==
counterWhite
)
System
.
out
.
println
(
"Equal !"
);
}
public
boolean
putDisk
(
String
Color
)
{
if
(
checkPossibleMove
(
Color
))
{
System
.
out
.
println
(
"Enter Number of row and letter of column :"
);
Scanner
scan
=
new
Scanner
(
System
.
in
);
int
row
=
scan
.
nextInt
();
row
=
row
-
1
;
String
colLetter
=
scan
.
next
();
int
col
=
getColNum
(
colLetter
);
if
(
col
!=
8
)
{
if
(
checkPutDisk
(
row
,
col
,
Color
))
{
ArrayList
<
String
>
temp
=
map
.
get
(
row
);
if
(
temp
.
get
(
col
).
equals
(
empty
))
{
temp
.
remove
(
col
);
temp
.
add
(
col
,
Color
);
map
.
remove
(
row
);
map
.
add
(
row
,
temp
);
}
checkNeighbor
(
row
,
col
);
}
else
{
System
.
out
.
println
(
"choose right position !"
);
putDisk
(
Color
);
}
}
else
{
System
.
out
.
println
(
"wrong input !"
);
putDisk
(
Color
);
}
checkNeighbor
(
row
,
col
)
;
return
false
;
}
else
{
System
.
out
.
println
(
"
choose right position
"
);
putDisk
(
Color
)
;
System
.
out
.
println
(
"
pass !
"
);
return
true
;
}
}
...
...
@@ -130,40 +180,43 @@ public class Map {
if
(
Row
>=
0
&&
Row
<
8
&&
Col
>=
0
&&
Col
<
8
)
{
if
(!
checkColor
(
Row
,
Col
).
equals
(
main
)
&&
!
checkColor
(
Row
,
Col
).
equals
(
empty
))
{
boolean
check
=
true
;
while
(
true
)
{
if
(
check
)
{
Row
+=
plusRow
;
Col
+=
plusCol
;
if
(
checkColor
(
Row
,
Col
).
equals
(
main
))
{
while
(
true
)
{
Row
-=
plusRow
;
Col
-=
plusCol
;
if
(
checkColor
(
Row
,
Col
).
equals
(
main
))
{
check
=
false
;
break
;
}
else
{
ArrayList
<
String
>
temp
=
map
.
get
(
Row
);
temp
.
remove
(
Col
);
temp
.
add
(
Col
,
main
);
map
.
remove
(
Row
);
map
.
add
(
Row
,
temp
);
if
(
Row
>=
0
&&
Row
<
8
&&
Col
>=
0
&&
Col
<
8
)
{
if
(
checkColor
(
Row
,
Col
).
equals
(
main
))
{
while
(
true
)
{
Row
-=
plusRow
;
Col
-=
plusCol
;
if
(
Row
>=
0
&&
Row
<
8
&&
Col
>=
0
&&
Col
<
8
)
{
if
(
checkColor
(
Row
,
Col
).
equals
(
main
))
{
check
=
false
;
break
;
}
else
{
ArrayList
<
String
>
temp
=
map
.
get
(
Row
);
temp
.
remove
(
Col
);
temp
.
add
(
Col
,
main
);
map
.
remove
(
Row
);
map
.
add
(
Row
,
temp
);
}
}
}
}
}
if
(
checkColor
(
Row
,
Col
).
equals
(
empty
))
{
check
=
false
;
break
;
}
if
(
Row
<
0
||
Row
>
7
||
Col
<
0
||
Col
>
7
)
{
check
=
false
;
break
;
if
(
checkColor
(
Row
,
Col
).
equals
(
empty
))
{
// check = false;
break
;
}
// if (Row < 0 || Row > 7 || Col < 0 || Col > 7) {
// check = false;
// break
;
// }
}
}
else
break
;
}
}
}
}
}
...
...
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