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
Matt Tower
205_hw02
Commits
4d538c31
Commit
4d538c31
authored
Nov 11, 2014
by
Stefano Cobelli
Browse files
BlockerPanel ready to be tested
parent
3fdfe06d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/model/player/BlockerPlayer.java
View file @
4d538c31
...
...
@@ -7,8 +7,6 @@
*/
package
model.player
;
import
java.util.ArrayList
;
import
model.Board
;
import
model.Mark
;
...
...
@@ -41,7 +39,7 @@ public class BlockerPlayer extends Player implements AutoPlayable {
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
move
(
row
,
checkSpots
(
marks
));
marks
.
marks
=
new
Mark
[
theBoard
.
getSize
()];
}
// Cols
for
(
int
col
=
0
;
col
<
theBoard
.
getSize
();
col
++)
{
...
...
@@ -49,71 +47,48 @@ public class BlockerPlayer extends Player implements AutoPlayable {
marks
[
col
]
=
theBoard
.
getMark
(
row
,
col
);
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
m
arks
.
add
(
theBoard
.
getMark
(
checkSpots
(
marks
),
col
)
)
;
marks
.
clear
();
return
m
ove
(
checkSpots
(
marks
),
col
);
marks
=
new
Mark
[
theBoard
.
getSize
()
]
;
}
// DiagNW
for
(
int
rowCol
=
0
;
rowCol
<
theBoard
.
getSize
();
rowCol
++)
{
marks
.
add
(
theBoard
.
getMark
(
rowCol
,
rowCol
));
marks
[
rowCol
]
=
(
theBoard
.
getMark
(
rowCol
,
rowCol
));
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
marks
.
add
(
theBoard
.
getMark
(
checkSpots
(
marks
),
checkSpots
(
marks
)));
marks
.
clear
();
return
move
(
checkSpots
(
marks
),
checkSpots
(
marks
));
marks
=
new
Mark
[
theBoard
.
getSize
()];
// DiagNE
for
(
int
rowCol
=
0
;
rowCol
<
theBoard
.
getSize
();
rowCol
++)
{
marks
.
add
(
theBoard
.
getMark
(
rowCol
,
theBoard
.
getSize
()
-
rowCol
));
marks
[
rowCol
]
=
theBoard
.
getMark
(
rowCol
,
theBoard
.
getSize
()
-
rowCol
);
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
m
arks
.
add
(
theBoard
.
getMark
(
checkSpots
(
marks
),
checkSpots
(
marks
))
)
;
return
m
ove
(
checkSpots
(
marks
),
theBoard
.
getSize
()
-
checkSpots
(
marks
));
return
false
;
}
/**
* Checks an array list of marks to see if there's a blocking opertunity
* Checks an array of marks to see if there's a blocking opertunity. Array
* could be a row, col, or diag
*
* @param mark0
* @param mark1
* @param mark2
* @param marks
* - array of marks
* @return the index of the spot to block
*/
public
int
checkSpots
(
Mark
[]
marks
)
{
boolean
openSpot
;
for
(
Mark
i
:
marks
)
{
int
openSpot
=
-
1
;
for
(
int
i
=
0
;
i
<
marks
.
length
;
i
++)
{
if
(
marks
[
i
]
==
this
.
getMark
())
return
-
1
;
if
(
marks
[
i
]
==
Mark
.
NONE
)
{
if
(
openSpot
==
-
1
)
return
-
1
;
else
openSpot
=
i
;
}
}
return
openSpot
;
}
/*
* (non-Javadoc)
*
* @see model.player.AutoPlayable#getDecidedRow()
*/
@Override
public
int
getDecidedRow
()
{
// TODO Auto-generated method stub
return
0
;
}
/*
* (non-Javadoc)
*
* @see model.player.AutoPlayable#getDecidedCol()
*/
@Override
public
int
getDecidedCol
()
{
// TODO Auto-generated method stub
return
0
;
}
/**
* Utility array that clears an array
*/
public
void
clearArray
(
Mark
[]
marks
)
{
for
(
int
i
=
0
;
i
<
theBoard
.
getSize
();
i
++)
{
}
}
}
Write
Preview
Supports
Markdown
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