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
24c57f54
Commit
24c57f54
authored
Nov 14, 2014
by
Stefano Cobelli
Browse files
Blocker player appears to be working, ready for junit tests
parent
d2017dac
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/controller/TTTController.java
View file @
24c57f54
...
...
@@ -155,7 +155,6 @@ public class TTTController implements ActionListener {
}
}
if
(
theGame
.
getCurPlayer
()
instanceof
AutoPlayable
)
{
System
.
out
.
println
(
"AI turn"
);
Integer
[]
aiMove
=
((
AutoPlayable
)
theGame
.
getCurPlayer
())
.
decideMove
();
boardPanel
.
getButtonBoard
()[
aiMove
[
0
]][
aiMove
[
1
]]
...
...
src/model/player/BlockerPlayer.java
View file @
24c57f54
...
...
@@ -7,6 +7,7 @@
*/
package
model.player
;
import
java.util.Arrays
;
import
java.util.Random
;
import
model.Board
;
...
...
@@ -39,27 +40,29 @@ public class BlockerPlayer extends Player implements AutoPlayable {
// Rows
for
(
int
row
=
0
;
row
<
theBoard
.
getSize
();
row
++)
{
for
(
int
col
=
0
;
col
<
theBoard
.
getSize
();
col
++)
{
marks
[
row
]
=
theBoard
.
getMark
(
row
,
col
);
marks
[
col
]
=
theBoard
.
getMark
(
row
,
col
);
}
if
(
checkSpots
(
marks
)
!=
-
1
)
{
move
(
row
,
checkSpots
(
marks
));
Integer
[]
answer
=
{
row
,
checkSpots
(
marks
)
};
return
answer
;
}
marks
=
new
Mark
[
theBoard
.
getSize
()]
;
Arrays
.
fill
(
marks
,
null
)
;
}
// Cols
for
(
int
col
=
0
;
col
<
theBoard
.
getSize
();
col
++)
{
for
(
int
row
=
0
;
row
<
theBoard
.
getSize
();
row
++)
{
marks
[
col
]
=
theBoard
.
getMark
(
row
,
col
);
marks
[
row
]
=
theBoard
.
getMark
(
row
,
col
);
}
if
(
checkSpots
(
marks
)
!=
-
1
)
{
move
(
checkSpots
(
marks
),
col
);
Integer
[]
answer
=
{
checkSpots
(
marks
),
col
};
return
answer
;
}
marks
=
new
Mark
[
theBoard
.
getSize
()]
;
Arrays
.
fill
(
marks
,
null
)
;
}
// DiagNW
for
(
int
rowCol
=
0
;
rowCol
<
theBoard
.
getSize
();
rowCol
++)
{
marks
[
rowCol
]
=
(
theBoard
.
getMark
(
rowCol
,
rowCol
));
...
...
@@ -70,6 +73,7 @@ public class BlockerPlayer extends Player implements AutoPlayable {
return
answer
;
}
marks
=
new
Mark
[
theBoard
.
getSize
()];
Arrays
.
fill
(
marks
,
null
);
// DiagNE
for
(
int
rowCol
=
0
;
rowCol
<
theBoard
.
getSize
();
rowCol
++)
{
marks
[
rowCol
]
=
theBoard
.
getMark
(
rowCol
,
(
theBoard
.
getSize
()
-
1
)
...
...
@@ -83,6 +87,8 @@ public class BlockerPlayer extends Player implements AutoPlayable {
return
answer
;
}
System
.
out
.
println
(
"Getting random"
);
Integer
[][]
coors
=
new
Integer
[
theBoard
.
getSize
()
*
theBoard
.
getSize
()][
2
];
int
index
=
0
;
for
(
int
row
=
0
;
row
<
theBoard
.
getSize
();
row
++)
{
...
...
@@ -115,7 +121,7 @@ public class BlockerPlayer extends Player implements AutoPlayable {
if
(
marks
[
i
]
==
this
.
getMark
())
return
-
1
;
if
(
marks
[
i
]
==
Mark
.
NONE
)
{
if
(
openSpot
=
=
-
1
)
if
(
openSpot
!
=
-
1
)
return
-
1
;
else
openSpot
=
i
;
...
...
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