Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
Othello_9731301
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
9731301
Othello_9731301
Commits
b95e5b9d
Commit
b95e5b9d
authored
Apr 01, 2020
by
9731301
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add calculations the winner Othello class
parent
afc1cdc2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
391 additions
and
47 deletions
+391
-47
workspace.xml
.idea/workspace.xml
+31
-21
Othello.class
out/production/MyOthello/Othello.class
+0
-0
User.class
out/production/MyOthello/User.class
+0
-0
Othello.java
src/Othello.java
+329
-14
User.java
src/User.java
+31
-12
No files found.
.idea/workspace.xml
View file @
b95e5b9d
...
...
@@ -2,6 +2,10 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"7be08370-19a4-4528-ab9b-d4cb0ec736c4"
name=
"Default Changelist"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/out/production/MyOthello/Othello.class"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/out/production/MyOthello/Othello.class"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/out/production/MyOthello/User.class"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/out/production/MyOthello/User.class"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/Othello.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/Othello.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/User.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/User.java"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
...
...
@@ -60,7 +64,9 @@
<workItem
from=
"1585656097487"
duration=
"2378000"
/>
<workItem
from=
"1585659438353"
duration=
"9321000"
/>
<workItem
from=
"1585687211713"
duration=
"16102000"
/>
<workItem
from=
"1585733466673"
duration=
"3956000"
/>
<workItem
from=
"1585733466673"
duration=
"4235000"
/>
<workItem
from=
"1585743679588"
duration=
"17656000"
/>
<workItem
from=
"1585769658377"
duration=
"6434000"
/>
</task>
<servers
/>
</component>
...
...
@@ -68,45 +74,49 @@
<option
name=
"version"
value=
"1"
/>
</component>
<component
name=
"WindowStateProjectService"
>
<state
x=
"574"
y=
"97"
key=
"#com.intellij.ide.util.MemberChooser"
timestamp=
"15857
36657332
"
>
<state
x=
"574"
y=
"97"
key=
"#com.intellij.ide.util.MemberChooser"
timestamp=
"15857
72436513
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
x=
"574"
y=
"97"
key=
"#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824"
timestamp=
"15857
36657332
"
/>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.bottom"
timestamp=
"1585738348489
"
>
<state
x=
"574"
y=
"97"
key=
"#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824"
timestamp=
"15857
72436513
"
/>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.bottom"
timestamp=
"1585776104986
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"1585738348489
"
/>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.center"
timestamp=
"1585738348488
"
>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"1585776104986
"
/>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.center"
timestamp=
"1585776104985
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824"
timestamp=
"1585738348488
"
/>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.left"
timestamp=
"1585738348488
"
>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824"
timestamp=
"1585776104985
"
/>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.left"
timestamp=
"1585776104985
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824"
timestamp=
"1585738348488
"
/>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.right"
timestamp=
"1585738348488
"
>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824"
timestamp=
"1585776104985
"
/>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.right"
timestamp=
"1585776104985
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
250"
key=
"GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824"
timestamp=
"1585738348488
"
/>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.bottom"
timestamp=
"1585671521268
"
>
<state
width=
"1493"
height=
"
63"
key=
"GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824"
timestamp=
"1585776104985
"
/>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.bottom"
timestamp=
"1585762030361
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"1585671521268
"
/>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.center"
timestamp=
"1585671521268
"
>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"1585762030361
"
/>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.center"
timestamp=
"1585762030361
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824"
timestamp=
"1585671521268
"
/>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.left"
timestamp=
"1585671521267
"
>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824"
timestamp=
"1585762030361
"
/>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.left"
timestamp=
"1585762030361
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824"
timestamp=
"1585671521267
"
/>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.right"
timestamp=
"1585671521268
"
>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824"
timestamp=
"1585762030361
"
/>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.right"
timestamp=
"1585762030361
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"
182"
key=
"GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824"
timestamp=
"1585671521268
"
/>
<state
x=
"813"
y=
"283"
key=
"com.intellij.ide.util.TipDialog"
timestamp=
"15857
3347164
5"
>
<state
width=
"1493"
height=
"
331"
key=
"GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824"
timestamp=
"1585762030361
"
/>
<state
x=
"813"
y=
"283"
key=
"com.intellij.ide.util.TipDialog"
timestamp=
"15857
6971102
5"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
x=
"813"
y=
"283"
key=
"com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824"
timestamp=
"1585733471645"
/>
<state
x=
"813"
y=
"283"
key=
"com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824"
timestamp=
"1585769711025"
/>
<state
x=
"431"
y=
"145"
width=
"672"
height=
"678"
key=
"search.everywhere.popup"
timestamp=
"1585744923229"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
x=
"431"
y=
"145"
width=
"672"
height=
"678"
key=
"search.everywhere.popup/0.0.1536.824@0.0.1536.824"
timestamp=
"1585744923229"
/>
</component>
</project>
\ No newline at end of file
out/production/MyOthello/Othello.class
View file @
b95e5b9d
No preview for this file type
out/production/MyOthello/User.class
View file @
b95e5b9d
No preview for this file type
src/Othello.java
View file @
b95e5b9d
...
...
@@ -8,6 +8,7 @@ public class Othello {
ArrayList
<
Block
>
blocks
=
new
ArrayList
<
Block
>();
User
user1
=
new
User
();
User
user2
=
new
User
();
User
chosenUser
=
new
User
();
Character
c
=
'n'
;
int
numberOfEmptyBlocksAtTheEnd
=
0
;
int
row
;
...
...
@@ -35,11 +36,11 @@ public class Othello {
user1
.
setName
(
sc
.
nextLine
().
trim
());
while
(!(
c
.
equals
(
'b'
)
||
c
.
equals
(
'w'
)))
{
System
.
out
.
println
(
"plz enter user1 color w or b"
);
c
=
sc
.
next
().
charAt
(
0
);
c
=
sc
.
next
Line
().
charAt
(
0
);
user1
.
setColor
(
c
);
}
System
.
out
.
println
(
"plz enter user2 name"
);
user2
.
setName
(
sc
.
next
());
user2
.
setName
(
sc
.
next
Line
().
trim
());
if
(
user1
.
getColor
().
equals
(
'w'
))
user2
.
setColor
(
'b'
);
else
...
...
@@ -64,13 +65,28 @@ public class Othello {
while
(
true
)
{
System
.
out
.
println
(
"plz enter your choice for example :3 a"
);
chosenBlock
.
changeColor
();
System
.
out
.
println
(
"turn is for : "
+
chosenBlock
.
getColor
());
if
(
chosenUser
.
equals
(
user1
)){
chosenUser
=
user2
;
}
else
{
chosenUser
=
user1
;
}
System
.
out
.
println
(
"turn is for : "
+
chosenUser
.
getName
()+
" that color is:"
+
chosenUser
.
getColor
()+
" plz enter your choice for example: 3 a"
);
String
input
=
sc
.
nextLine
().
trim
();
String
[]
inputArray
=
input
.
split
(
" "
);
System
.
out
.
println
(
inputArray
[
0
]);
row
=
Integer
.
parseInt
(
inputArray
[
0
])-
1
;
if
(
row
>
8
||
row
<=
0
){
System
.
out
.
println
(
" enter again correctly"
);
if
(
chosenUser
.
equals
(
user1
)){
chosenUser
=
user2
;
}
else
{
chosenUser
=
user1
;
}
continue
;
}
if
(
inputArray
[
1
].
toLowerCase
().
equals
(
"a"
))
column
=
0
;
else
if
(
inputArray
[
1
].
toLowerCase
().
equals
(
"b"
))
...
...
@@ -88,39 +104,317 @@ public class Othello {
else
if
(
inputArray
[
1
].
toLowerCase
().
equals
(
"h"
))
column
=
7
;
else
{
System
.
out
.
println
(
"enter again correctly"
);
break
;
System
.
out
.
println
(
" enter again correctly"
);
if
(
chosenUser
.
equals
(
user1
)){
chosenUser
=
user2
;
}
else
{
chosenUser
=
user1
;
}
continue
;
}
chosenBlock
.
setRow
(
row
);
chosenBlock
.
setColumn
(
column
);
System
.
out
.
println
(
" a b c d e f g h "
);
for
(
int
i
=
0
;
i
<
8
;
i
++){
System
.
out
.
print
(
i
+
1
+
" "
);
for
(
int
j
=
0
;
j
<
8
;
j
++){
int
flag
=
0
;
int
flag1
=
0
;
// to check if neighbor has same color stop checking
int
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
int
flag3
=
0
;
for
(
Block
b
:
blocks
){
if
(
b
.
getRow
()
==
i
&&
b
.
getColumn
()
==
j
){
System
.
out
.
print
(
b
.
getColor
()+
" "
);
if
(
b
.
getColumn
()
==
column
&&
b
.
getRow
()
==
row
){
if
((
b
.
getColor
().
equals
(
'b'
)
||
b
.
getColor
().
equals
(
'w'
)
)){
flag
=
1
;
}
else
{
//check down
for
(
int
i
=
row
+
1
;
i
<
8
;
i
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
+
1
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
// flag1 is to stop loop if down neighbor has same color
break
;
}
if
(
flag2
==
1
)
{
// to not change " w b b b w b b w " to "w w w w w w w w"
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getRow
()
==
i
&&
block1
.
getColumn
()
==
column
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
rowIndex
=
row
;
rowIndex
<=
block1
.
getRow
();
rowIndex
++)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getColumn
()
==
column
&&
block2
.
getRow
()
==
rowIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
//check up
flag1
=
0
;
//flag1 is to stop loop if up neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
row
-
1
;
i
>=
0
;
i
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getRow
()
==
chosenBlock
.
getRow
()
-
1
&&
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getRow
()
==
i
&&
block1
.
getColumn
()
==
column
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
rowIndex
=
row
;
rowIndex
>=
block1
.
getRow
();
rowIndex
--)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getColumn
()
==
column
&&
block2
.
getRow
()
==
rowIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
//check right
flag1
=
0
;
// flag1 is to stop loop if right neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
column
+
1
;
i
<
8
;
i
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getColumn
()
==
i
&&
block1
.
getRow
()
==
row
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
columnIndex
=
column
;
columnIndex
<=
block1
.
getRow
();
columnIndex
++)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getRow
()
==
row
&&
block2
.
getColumn
()
==
columnIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
//check left
flag1
=
0
;
// flag1 is to stop loop if left neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
column
-
1
;
i
>=
0
;
i
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getColumn
()
==
i
&&
block1
.
getRow
()
==
row
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
columnIndex
=
column
;
columnIndex
>=
block1
.
getRow
();
columnIndex
--)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getRow
()
==
row
&&
block2
.
getColumn
()
==
columnIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
//check down and right
flag1
=
0
;
// flag1 is to stop loop if down_right neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
column
+
1
,
j
=
row
+
1
;
i
<
8
&&
j
<
8
;
i
++,
j
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
+
1
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getColumn
()
==
i
&&
block1
.
getRow
()
==
j
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
columnIndex
=
column
,
rowIndex
=
row
;
rowIndex
<=
block1
.
getRow
()
&&
rowIndex
<=
block1
.
getRow
();
columnIndex
++,
rowIndex
++)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getRow
()
==
rowIndex
&&
block2
.
getColumn
()
==
columnIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
{
break
;
}
}
//check down and left
flag1
=
0
;
// flag1 is to stop loop if down_left neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
column
-
1
,
j
=
row
+
1
;
i
>
-
1
&&
j
<
8
;
i
--,
j
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
+
1
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getColumn
()
==
i
&&
block1
.
getRow
()
==
j
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
columnIndex
=
column
,
rowIndex
=
row
;
rowIndex
>=
block1
.
getColumn
()
&&
rowIndex
<=
block1
.
getRow
();
columnIndex
--,
rowIndex
++)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getRow
()
==
rowIndex
&&
block2
.
getColumn
()
==
columnIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
//check up and right
flag1
=
0
;
// flag1 is to stop loop if up_right neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
column
+
1
,
j
=
row
-
1
;
i
<
8
&&
j
>
-
1
;
i
++,
j
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
-
1
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getColumn
()
==
i
&&
block1
.
getRow
()
==
j
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
columnIndex
=
column
,
rowIndex
=
row
;
columnIndex
<=
block1
.
getColumn
()
&&
rowIndex
>=
block1
.
getRow
();
columnIndex
++,
rowIndex
--)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getRow
()
==
rowIndex
&&
block2
.
getColumn
()
==
columnIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
//check up and left
flag1
=
0
;
// flag1 is to stop loop if up_left neighbor has same color
flag2
=
0
;
// to not change " w b b b w b b w " to "w w w w w w w w"
for
(
int
i
=
column
-
1
,
j
=
row
-
1
;
i
>
-
1
&&
j
>
-
1
;
i
--,
j
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
chosenBlock
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
chosenBlock
.
getRow
()
-
1
&&
(
block1
.
getColor
().
equals
(
chosenUser
.
getColor
())
||
block1
.
getColor
().
equals
(
'n'
)))
{
flag1
=
1
;
break
;
}
if
(
flag2
==
1
)
{
break
;
}
if
(!
block1
.
getColor
().
equals
(
'n'
)
&&
block1
.
getColumn
()
==
i
&&
block1
.
getRow
()
==
j
&&
block1
.
getColor
().
equals
(
chosenUser
.
getColor
()))
{
for
(
int
columnIndex
=
column
,
rowIndex
=
row
;
columnIndex
>=
block1
.
getColumn
()
&&
rowIndex
>=
block1
.
getRow
();
columnIndex
--,
rowIndex
--)
{
for
(
Block
block2
:
blocks
)
{
if
(
block2
.
getRow
()
==
rowIndex
&&
block2
.
getColumn
()
==
columnIndex
)
{
//change color of blocks in 2 blocks with same color
block2
.
setColor
(
chosenUser
.
getColor
());
flag2
=
1
;
flag3
=
1
;
}
}
}
}
}
if
(
flag1
==
1
)
break
;
}
}
}
}
if
(
flag3
==
0
){
System
.
out
.
println
(
"you entered wrong block try again"
);
if
(
chosenUser
.
equals
(
user1
)){
chosenUser
=
user2
;
}
else
{
chosenUser
=
user1
;
}
}
if
(
flag
==
1
){
System
.
out
.
println
(
"block is not empty try again"
);
if
(
chosenUser
.
equals
(
user1
)){
chosenUser
=
user2
;
}
else
{
chosenUser
=
user1
;
}
}
else
{
System
.
out
.
println
(
" a b c d e f g h "
);
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
System
.
out
.
print
(
i
+
1
+
" "
);
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
for
(
Block
b
:
blocks
)
{
if
(
b
.
getRow
()
==
i
&&
b
.
getColumn
()
==
j
)
{
System
.
out
.
print
(
b
.
getColor
()
+
" "
);
}
}
}
System
.
out
.
println
();
}
}
for
(
Block
b
:
blocks
){
if
(
b
.
getColor
().
equals
(
user1
.
getColor
())){
user1
.
addBlock
(
b
);
user2
.
removeBlock
(
b
);
}
else
if
(
b
.
getColor
().
equals
(
user2
.
getColor
())){
user2
.
addBlock
(
b
);
user1
.
removeBlock
(
b
);
}
else
{
user1
.
removeBlock
(
b
);
user2
.
removeBlock
(
b
);
numberOfEmptyBlocksAtTheEnd
++;
}
System
.
out
.
println
(
user1
.
getName
()
+
" = "
+
user1
.
getUserBlocks
().
size
()+
"_______"
+
user2
.
getName
()
+
" = "
+
user2
.
getUserBlocks
().
size
());
if
(
user1
.
isAvailableBlockToPick
(
b
,
blocks
)){
user1
.
addAvailableBlockToPick
(
b
);
}
...
...
@@ -134,6 +428,27 @@ public class Othello {
user2
.
removeAvailableBlockToPick
(
b
);
}
}
System
.
out
.
println
(
user1
.
getName
()
+
" = "
+
user1
.
getUserBlocks
().
size
()+
"_______"
+
user2
.
getName
()
+
" = "
+
user2
.
getUserBlocks
().
size
());
if
(
chosenUser
.
getAvailableBlocksToPick
().
size
()
==
0
)
{
System
.
out
.
println
(
"pass"
);
continue
;
}
if
(
user1
.
getAvailableBlocksToPick
().
size
()
==
0
&&
user2
.
getAvailableBlocksToPick
().
size
()
==
0
){
if
(
user1
.
getUserBlocks
()
==
user2
.
getUserBlocks
()){
System
.
out
.
println
(
"equal "
+
user1
.
getUserBlocks
());
break
;
}
else
if
(
user1
.
getUserBlocks
().
size
()
>
user2
.
getUserBlocks
().
size
()){
System
.
out
.
println
(
user1
.
getName
()
+
" = "
+
user1
.
getUserBlocks
().
size
()+
numberOfEmptyBlocksAtTheEnd
+
"_______"
+
user2
.
getName
()
+
" = "
+
user2
.
getUserBlocks
().
size
());
System
.
out
.
println
(
user1
.
getName
()
+
" won"
);
break
;
}
else
{
System
.
out
.
println
(
user1
.
getName
()
+
" = "
+
user1
.
getUserBlocks
().
size
()
+
"_______"
+
user2
.
getName
()
+
" = "
+
user2
.
getUserBlocks
().
size
()
+
numberOfEmptyBlocksAtTheEnd
);
System
.
out
.
println
(
user2
.
getName
()+
" won"
);
break
;
}
}
}
}
...
...
src/User.java
View file @
b95e5b9d
...
...
@@ -14,9 +14,13 @@ public class User {
userBlocks
.
add
(
block
);
}
public
void
removeBlock
(
Block
block
){
userBlocks
.
remove
(
block
);
}
public
boolean
isAvailableBlockToPick
(
Block
block
,
ArrayList
<
Block
>
blocks
)
{
int
i
,
j
;
int
flag1
=
0
;
int
flag1
=
0
;
// for checking neighbors has same color in each step or not
int
flag2
=
0
;
int
flag3
=
0
;
// to know you can pick an empty block with help of checking changing color
if
(!
block
.
getColor
().
equals
(
'n'
))
{
...
...
@@ -26,7 +30,7 @@ public class User {
//check down
for
(
i
=
block
.
getRow
();
i
>
8
;
i
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
get
Row
()
==
block
.
getRow
()
+
1
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
get
Column
()
==
block
.
getColumn
()
&&
block1
.
getRow
()
==
block
.
getRow
()
+
1
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -46,9 +50,9 @@ public class User {
//check up
flag1
=
0
;
flag2
=
0
;
for
(
i
=
block
.
getRow
()
-
1
;
i
>
=
0
;
i
--)
{
// find the next block with chosen block color
for
(
i
=
block
.
getRow
()
-
1
;
i
>
-
1
;
i
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getRow
()
==
block
.
getRow
()
-
1
&&
block1
.
getColumn
()
==
block
.
getColumn
()
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getRow
()
==
block
.
getRow
()
-
1
&&
block1
.
getColumn
()
==
block
.
getColumn
()
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -70,7 +74,7 @@ public class User {
flag2
=
0
;
for
(
i
=
block
.
getColumn
()
+
1
;
i
<
8
;
i
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
block
.
getRow
()
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
block
.
getRow
()
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -90,9 +94,9 @@ public class User {
//check left
flag1
=
0
;
flag2
=
0
;
for
(
i
=
block
.
getColumn
()
-
1
;
i
>
=
0
;
i
--)
{
// find the next block with chosen block color
for
(
i
=
block
.
getColumn
()
-
1
;
i
>
-
1
;
i
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
block
.
getRow
()
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
block
.
getRow
()
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -115,7 +119,7 @@ public class User {
flag2
=
0
;
for
(
i
=
block
.
getColumn
()
+
1
,
j
=
block
.
getRow
()
-
1
;
i
<
8
&&
j
>
-
1
;
i
++,
j
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
block
.
getRow
()
+
1
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
block
.
getRow
()
+
1
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -137,7 +141,7 @@ public class User {
flag2
=
0
;
for
(
i
=
block
.
getColumn
()
-
1
,
j
=
block
.
getRow
()
+
1
;
i
>
-
1
&&
j
<
8
;
i
--,
j
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
block
.
getRow
()
+
1
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
block
.
getRow
()
+
1
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -159,7 +163,7 @@ public class User {
flag2
=
0
;
for
(
i
=
block
.
getColumn
()
+
1
,
j
=
block
.
getRow
()
+
1
;
i
<
8
&&
j
<
8
;
i
++,
j
++)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
block
.
getRow
()
-
1
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
+
1
&&
block1
.
getRow
()
==
block
.
getRow
()
-
1
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -179,9 +183,9 @@ public class User {
//check up and left
flag1
=
0
;
flag2
=
0
;
for
(
i
=
block
.
getColumn
()
-
1
,
j
=
block
.
getRow
()
-
1
;
i
<
-
1
&&
j
<
-
1
;
i
--,
j
--)
{
// find the next block with chosen block color
for
(
i
=
block
.
getColumn
()
-
1
,
j
=
block
.
getRow
()
-
1
;
i
>
-
1
&&
j
>
-
1
;
i
--,
j
--)
{
// find the next block with chosen block color
for
(
Block
block1
:
blocks
)
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
block
.
getRow
()
-
1
&&
block1
.
getColor
().
equals
(
color
))
{
if
(
block1
.
getColumn
()
==
block
.
getColumn
()
-
1
&&
block1
.
getRow
()
==
block
.
getRow
()
-
1
&&
(
block1
.
getColor
().
equals
(
color
)
||
block1
.
getColor
().
equals
(
'n'
)
))
{
flag1
=
1
;
break
;
}
...
...
@@ -238,5 +242,20 @@ public class User {
this
.
name
=
name
;
}
public
ArrayList
<
Block
>
getAvailableBlocksToPick
()
{
return
availableBlocksToPick
;
}
public
void
setAvailableBlocksToPick
(
ArrayList
<
Block
>
availableBlocksToPick
)
{
this
.
availableBlocksToPick
=
availableBlocksToPick
;
}
public
ArrayList
<
Block
>
getUserBlocks
()
{
return
userBlocks
;
}
public
void
setUserBlocks
(
ArrayList
<
Block
>
userBlocks
)
{
this
.
userBlocks
=
userBlocks
;
}
}
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