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
c8e2482c
Commit
c8e2482c
authored
Mar 30, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fisrt upload
parents
Pipeline
#3063
failed with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
214 additions
and
0 deletions
+214
-0
Othello.iml
Othello.iml
+12
-0
Othello.kotlin_module
out/production/Othello/META-INF/Othello.kotlin_module
+0
-0
Main.class
out/production/Othello/Main.class
+0
-0
Map.class
out/production/Othello/Map.class
+0
-0
Main.java
src/Main.java
+17
-0
Map.java
src/Map.java
+185
-0
No files found.
Othello.iml
0 → 100644
View file @
c8e2482c
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
out/production/Othello/META-INF/Othello.kotlin_module
0 → 100644
View file @
c8e2482c
File added
out/production/Othello/Main.class
0 → 100644
View file @
c8e2482c
File added
out/production/Othello/Map.class
0 → 100644
View file @
c8e2482c
File added
src/Main.java
0 → 100644
View file @
c8e2482c
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
Map
map
=
new
Map
();
map
.
print
();
while
(
true
)
{
String
white
=
"| \u26AA |"
;
String
black
=
"| \u26AB |"
;
System
.
out
.
println
(
"Black's turn"
);
map
.
putDisk
(
black
);
map
.
print
();
System
.
out
.
println
(
"White's turn"
);
map
.
putDisk
(
white
);
map
.
print
();
}
}
}
src/Map.java
0 → 100644
View file @
c8e2482c
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Scanner
;
import
java.util.SortedMap
;
public
class
Map
{
private
ArrayList
<
ArrayList
>
map
;
private
boolean
turn
;
private
String
empty
;
private
String
white
;
private
String
black
;
public
Map
()
{
empty
=
"| |"
;
white
=
"| ⚪ |"
;
black
=
"| ⚫ |"
;
map
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
ArrayList
<
String
>
cul
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
if
(
i
==
3
&&
j
==
3
)
cul
.
add
(
"| \u26AA |"
);
else
if
(
i
==
4
&&
j
==
3
)
cul
.
add
(
"| \u26AB |"
);
else
if
(
i
==
3
&&
j
==
4
)
cul
.
add
(
"| \u26AB |"
);
else
if
(
i
==
4
&&
j
==
4
)
cul
.
add
(
"| \u26AA |"
);
else
cul
.
add
(
"| |"
);
}
map
.
add
(
cul
);
}
}
public
boolean
getTurn
()
{
return
turn
;
}
public
int
getColNum
(
String
c
)
{
if
(
c
.
equals
(
"A"
))
return
0
;
if
(
c
.
equals
(
"B"
))
return
1
;
if
(
c
.
equals
(
"C"
))
return
2
;
if
(
c
.
equals
(
"D"
))
return
3
;
if
(
c
.
equals
(
"E"
))
return
4
;
if
(
c
.
equals
(
"F"
))
return
5
;
if
(
c
.
equals
(
"G"
))
return
6
;
if
(
c
.
equals
(
"H"
))
return
7
;
else
return
8
;
}
public
String
checkColor
(
int
row
,
int
col
)
{
ArrayList
<
String
>
temp
=
map
.
get
(
row
);
if
(
temp
.
get
(
col
).
equals
(
white
))
return
white
;
if
(
temp
.
get
(
col
).
equals
(
black
))
return
black
;
else
return
empty
;
}
public
boolean
checkPutDisk
(
int
row
,
int
col
)
{
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
))
{
while
(
true
)
{
Row
+=
plusRow
;
Col
+=
plusCol
;
if
(
Row
>=
0
&&
Row
<
8
&&
Col
>=
0
&&
Col
<
8
)
{
if
(
checkColor
(
Row
,
Col
).
equals
(
main
))
{
counter
++;
break
;
}
}
else
break
;
}
}
}
}
}
}
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
);
}
checkNeighbor
(
row
,
col
);
}
else
{
System
.
out
.
println
(
"choose right position"
);
putDisk
(
Color
);
}
}
public
void
checkNeighbor
(
int
row
,
int
col
)
{
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
))
{
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
(
checkColor
(
Row
,
Col
).
equals
(
empty
))
{
check
=
false
;
break
;
}
if
(
Row
<
0
||
Row
>
7
||
Col
<
0
||
Col
>
7
)
{
check
=
false
;
break
;
}
}
else
break
;
}
}
}
}
}
}
}
public
void
print
()
{
System
.
out
.
println
(
" A B C D E F G H "
);
System
.
out
.
println
(
" +----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+"
);
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
System
.
out
.
print
(
i
+
1
);
System
.
out
.
println
(
" "
+
(
map
.
get
(
i
).
toString
()).
replace
(
"["
,
""
)
.
replace
(
"]"
,
""
).
replace
(
","
,
""
));
System
.
out
.
println
(
" +----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+"
);
}
}
}
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