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
Stefano Cobelli
205_hw02
Commits
3fdfe06d
Commit
3fdfe06d
authored
Nov 11, 2014
by
Stefano Cobelli
Browse files
Board.getSize() added
Autoplayable now only includes decideMove() BlockerPlayer almost completed
parent
2f9e6c00
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/model/Board.java
View file @
3fdfe06d
...
...
@@ -45,6 +45,13 @@ public class Board {
clear
();
}
/**
* @return the size
*/
public
int
getSize
()
{
return
size
;
}
/**
* clears the whole board. Sets states to NONE
*
...
...
src/model/player/AutoPlayable.java
View file @
3fdfe06d
...
...
@@ -14,8 +14,4 @@ package model.player;
public
interface
AutoPlayable
{
public
boolean
decideMove
();
public
int
getDecidedRow
();
public
int
getDecidedCol
();
}
src/model/player/BlockerPlayer.java
View file @
3fdfe06d
...
...
@@ -7,6 +7,8 @@
*/
package
model.player
;
import
java.util.ArrayList
;
import
model.Board
;
import
model.Mark
;
...
...
@@ -31,10 +33,59 @@ public class BlockerPlayer extends Player implements AutoPlayable {
*/
@Override
public
boolean
decideMove
()
{
Mark
[]
marks
=
new
Mark
[
theBoard
.
getSize
()];
// Rows
for
(
int
row
=
0
;
row
<
theBoard
.
getSize
();
row
++)
{
for
(
int
col
=
0
;
col
<
theBoard
.
getSize
();
col
++)
{
marks
[
row
]
=
theBoard
.
getMark
(
row
,
col
);
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
move
(
row
,
checkSpots
(
marks
));
marks
.
}
// Cols
for
(
int
col
=
0
;
col
<
theBoard
.
getSize
();
col
++)
{
for
(
int
row
=
0
;
row
<
theBoard
.
getSize
();
row
++)
{
marks
[
col
]
=
theBoard
.
getMark
(
row
,
col
);
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
marks
.
add
(
theBoard
.
getMark
(
checkSpots
(
marks
),
col
));
marks
.
clear
();
}
// DiagNW
for
(
int
rowCol
=
0
;
rowCol
<
theBoard
.
getSize
();
rowCol
++)
{
marks
.
add
(
theBoard
.
getMark
(
rowCol
,
rowCol
));
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
marks
.
add
(
theBoard
.
getMark
(
checkSpots
(
marks
),
checkSpots
(
marks
)));
marks
.
clear
();
// DiagNE
for
(
int
rowCol
=
0
;
rowCol
<
theBoard
.
getSize
();
rowCol
++)
{
marks
.
add
(
theBoard
.
getMark
(
rowCol
,
theBoard
.
getSize
()
-
rowCol
));
}
if
(
checkSpots
(
marks
)
!=
-
1
)
return
marks
.
add
(
theBoard
.
getMark
(
checkSpots
(
marks
),
checkSpots
(
marks
)));
return
false
;
}
/**
* Checks an array list of marks to see if there's a blocking opertunity
*
* @param mark0
* @param mark1
* @param mark2
* @return the index of the spot to block
*/
public
int
checkSpots
(
Mark
[]
marks
)
{
boolean
openSpot
;
for
(
Mark
i
:
marks
)
{
}
}
/*
* (non-Javadoc)
*
...
...
@@ -58,56 +109,11 @@ public class BlockerPlayer extends Player implements AutoPlayable {
}
/**
* Looks to see if two of the other players marks are in a specified row and
* the spot to block is not taken
*
* @param row
* @return col in spot to block. -1 if can't block
*/
public
int
findTwoInRow
(
int
row
)
{
if
}
/**
* Looks to see if two of the other players marks are in a specified col and
* the spot to block is not taken
*
* @param col
* @return row in spot to block. -1 if can't block
*/
public
int
findTwoInCol
(
int
col
)
{
}
/**
* Looks to see if two of the other players marks are in the NorthEast
* diagnal. returns the row if there's a spot to block
*
* @return row in spot to block. -1 if can't block
*/
public
int
findTwoInDiagNE
()
{
}
/**
* Looks to see if two of the other players marks are in the NorthWest
* diagnal. returns the row if there's a spot to block
*
* @return row in spot to block. -1 if can't block
*/
public
int
findTwoInDiagNW
()
{
}
/**
* Checks three marks to see if there's a blocking opertunity
*
* @param mark0
* @param mark1
* @param mark2
* @return the index of the spot to block
* Utility array that clears an array
*/
public
int
checkThreeSpots
(
Mark
mark0
,
Mark
mark1
,
Mark
mark2
)
{
public
void
clearArray
(
Mark
[]
marks
)
{
for
(
int
i
=
0
;
i
<
theBoard
.
getSize
();
i
++)
{
}
}
}
src/model/player/Player.java
View file @
3fdfe06d
...
...
@@ -17,9 +17,9 @@ import model.Mark;
public
class
Player
{
/** reference to the current board */
pr
ivate
Board
theBoard
;
pr
otected
Board
theBoard
;
/** mark used by player */
pr
ivate
Mark
myMark
;
pr
otected
Mark
myMark
;
/**
* constructor that initializes the board and mark
...
...
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