Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johan Gustav Thrane-Nielsen
inf101.v20.sem2.losning
Commits
49cc2733
Commit
49cc2733
authored
Mar 25, 2020
by
Anna Maria Eilertsen
Browse files
refactored code for checking winner + wincondition
parent
9f5902ce
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/inf101/v20/sem2/mnkgames/MNKGame.java
View file @
49cc2733
...
...
@@ -65,7 +65,7 @@ public abstract class MNKGame {
grid
.
set
(
x
,
y
,
currentPlayer
);
if
(
getWinner
(
x
,
y
)!=
Piece
.
NONE
)
{
if
(
checkWinCondition
(
x
,
y
)
)
{
winnerPiece
=
currentPlayer
;
}
...
...
@@ -76,11 +76,15 @@ public abstract class MNKGame {
return
winnerPiece
!=
Piece
.
NONE
;
}
public
Piece
getWinner
(
int
x
,
int
y
)
{
public
Piece
getWinner
()
{
return
winnerPiece
;
}
private
boolean
checkWinCondition
(
int
x
,
int
y
)
{
int
count
=
0
;
Piece
current
=
grid
.
get
(
x
,
y
);
if
(
current
==
Piece
.
NONE
)
return
Piece
.
NONE
;
return
false
;
System
.
out
.
println
();
System
.
out
.
println
(
"Currently at "
+
x
+
","
+
y
+
" value "
+
current
);
...
...
@@ -98,7 +102,7 @@ public abstract class MNKGame {
count
++;
}
if
(
count
==
k
)
return
current
;
return
true
;
}
count
=
0
;
...
...
@@ -114,7 +118,7 @@ public abstract class MNKGame {
count
++;
}
if
(
count
==
k
)
return
current
;
return
true
;
}
count
=
0
;
...
...
@@ -131,7 +135,7 @@ public abstract class MNKGame {
count
++;
}
if
(
count
==
k
)
return
current
;
return
true
;
}
count
=
0
;
...
...
@@ -148,9 +152,9 @@ public abstract class MNKGame {
count
++;
}
if
(
count
==
k
)
return
current
;
return
true
;
}
return
Piece
.
NONE
;
return
false
;
}
@Override
...
...
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