Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Christian Rippe
CPTR142_AI_Game
Commits
ad421650
Commit
ad421650
authored
Mar 20, 2019
by
Jason Riggs
Browse files
change
parent
67835c58
Changes
4
Hide whitespace changes
Inline
Side-by-side
AIplayer.h
View file @
ad421650
...
...
@@ -8,8 +8,6 @@ class displayBoard;
class
Cell
;
class
AIplayer
{
public:
AIplayer
()
{
srand
(
0
);
}
// basic constructor to seed random number generator
AIplayer
(
int
seed
)
{
srand
(
seed
);
}
// constructor to seed random number generator with desired seed
pair
<
int
,
int
>
move1
(
displayBoard
AImove
);
// easy move
pair
<
int
,
int
>
move2
(
displayBoard
AImove
);
// hard move mutator
private:
// not used
...
...
Cell.cpp
View file @
ad421650
...
...
@@ -6,7 +6,6 @@
using
namespace
std
;
bool
Cell
::
isLegalPlacementfor
(
int
x
,
int
y
,
char
board
[][
8
],
char
playDisc
,
char
oppDisc
)
{
cout
<<
"Looking at "
<<
x
<<
" "
<<
y
<<
" to place "
<<
(
char
)
playDisc
<<
endl
;
vector
<
Directions
>
directions
;
Cell
current
(
x
-
1
,
y
-
1
);
...
...
@@ -17,62 +16,53 @@ bool Cell::isLegalPlacementfor(int x, int y, char board[][8], char playDisc, cha
Cell
north
(
x
-
1
,
y
-
2
);
if
(
north
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
north
.
NORTH
);
cout
<<
"N "
<<
north
.
x
<<
" "
<<
north
.
y
<<
endl
;
}
Cell
northEast
(
x
,
y
-
2
);
if
(
northEast
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
northEast
.
NORTHEAST
);
cout
<<
"NE "
<<
northEast
.
x
<<
" "
<<
northEast
.
y
<<
endl
;
}
Cell
east
(
x
,
y
-
1
);
if
(
east
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
EAST
);
cout
<<
"E "
<<
east
.
x
<<
" "
<<
east
.
y
<<
endl
;
}
Cell
southEast
(
x
,
y
);
if
(
southEast
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
SOUTHEAST
);
cout
<<
"SE "
<<
southEast
.
x
<<
" "
<<
southEast
.
y
<<
endl
;
}
Cell
south
(
x
-
1
,
y
);
if
(
south
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
SOUTH
);
cout
<<
"S "
<<
south
.
x
<<
" "
<<
south
.
y
<<
endl
;
}
Cell
southWest
(
x
-
2
,
y
);
if
(
southWest
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
SOUTHWEST
);
cout
<<
"SW "
<<
southWest
.
x
<<
" "
<<
southWest
.
y
<<
endl
;
}
Cell
west
(
x
-
2
,
y
-
1
);
if
(
west
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
WEST
);
cout
<<
"W "
<<
west
.
x
<<
" "
<<
west
.
y
<<
endl
;
}
Cell
northWest
(
x
-
2
,
y
-
2
);
if
(
northWest
.
isOccupied
(
board
,
oppDisc
))
{
directions
.
push_back
(
NORTHWEST
);
cout
<<
"NW "
<<
northWest
.
x
<<
" "
<<
northWest
.
y
<<
endl
;
}
for
(
int
i
=
0
;
i
<
directions
.
size
();
i
++
)
{
cout
<<
directions
.
at
(
i
)
<<
endl
;
}
//
for (int i = 0; i < directions.size(); i++) {
//
cout << directions.at(i) << endl;
//
}
for
(
auto
direction
:
directions
)
{
try
{
int
value
=
current
.
sequenceLength
(
direction
,
board
,
oppDisc
,
""
);
cout
<<
"For Direction "
<<
direction
<<
" there was a value of "
<<
value
<<
endl
;
if
(
value
>
0
)
{
return
true
;
}
}
catch
(
runtime_error
&
excpt
)
{
cout
<<
excpt
.
what
()
<<
endl
;
//
cout << excpt.what() << endl;
}
}
return
false
;
...
...
@@ -80,7 +70,6 @@ bool Cell::isLegalPlacementfor(int x, int y, char board[][8], char playDisc, cha
int
Cell
::
sequenceLength
(
Directions
direction
,
char
board
[][
8
],
char
playDisc
,
string
indent
)
{
int
x1
,
y1
;
cout
<<
indent
<<
"Entering sequenceLength with "
<<
x
+
1
<<
" "
<<
y
+
1
<<
" Looking for "
<<
(
char
)
playDisc
<<
endl
;
switch
(
direction
)
{
case
NORTH
:
x1
=
x
;
...
...
@@ -116,24 +105,19 @@ int Cell::sequenceLength(Directions direction, char board[][8], char playDisc, s
default:
exit
(
1
);
}
cout
<<
indent
<<
"New sequenceLength with "
<<
x1
+
1
<<
" "
<<
y1
+
1
<<
endl
;
if
(
x1
<
0
||
x1
>=
8
||
y1
<
0
||
y1
>=
8
)
{
cout
<<
"Off the Board!"
<<
endl
;
throw
runtime_error
(
"Invalid Sequence"
);
}
Cell
sequence
(
x1
,
y1
);
if
(
board
[
x1
][
y1
]
==
' '
)
{
cout
<<
indent
<<
"Found a space. Treat as invalid"
<<
endl
;
throw
runtime_error
(
"Invalid Input"
);
}
if
(
board
[
x1
][
y1
]
!=
playDisc
)
{
cout
<<
indent
<<
"Found
\'
"
<<
(
char
)
board
[
x1
][
y1
]
<<
"
\'
Returning 0"
<<
endl
;
return
0
;
}
int
result
=
(
1
+
sequence
.
sequenceLength
(
direction
,
board
,
playDisc
,
" "
+
indent
));
cout
<<
indent
<<
"Found
\'
"
<<
(
char
)
board
[
x1
][
y1
]
<<
"
\'
Returning "
<<
result
<<
endl
;
return
result
;
}
...
...
Cell.h
View file @
ad421650
...
...
@@ -14,7 +14,6 @@ class Cell {
bool
isOccupied
(
char
board
[][
8
],
char
disc
);
int
x
,
y
;
private:
};
#endif
mainOthello.cpp
View file @
ad421650
...
...
@@ -15,14 +15,8 @@ int main() {
pair
<
int
,
int
>
AImove
;
bool
winner
=
false
;
// Seeding random number genrator
cout
<<
"Please enter a random seed: "
;
cin
>>
seed
;
srand
(
seed
);
cout
<<
endl
;
// Creates AI
AIplayer
AIturn
(
seed
)
;
AIplayer
AIturn
;
// Header
cout
<<
"Welcome to Othello!"
<<
endl
;
...
...
@@ -97,7 +91,6 @@ int main() {
// Player two's Move
}
else
if
(
turn
==
2
)
{
AImove
=
AIturn
.
move1
(
board
);
cout
<<
AImove
.
first
<<
" "
<<
AImove
.
second
<<
endl
;
aiX
=
AImove
.
first
;
aiY
=
AImove
.
second
;
//Check fo valid move
...
...
@@ -165,7 +158,6 @@ int main() {
// Player two's Move
}
else
if
(
turn
==
2
)
{
AImove
=
AIturn
.
move2
(
board
);
cout
<<
AImove
.
first
<<
" "
<<
AImove
.
second
<<
endl
;
aiX
=
AImove
.
first
;
aiY
=
AImove
.
second
;
// Check fo valid move
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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