Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
CPTR142_AI_Game
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Rippe
CPTR142_AI_Game
Commits
9702aeaa
Commit
9702aeaa
authored
Mar 14, 2019
by
Jason Riggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
ad8b15bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
25 deletions
+94
-25
Board.cpp
Board.cpp
+60
-9
Board.h
Board.h
+5
-0
mainOthello.cpp
mainOthello.cpp
+29
-16
No files found.
Board.cpp
View file @
9702aeaa
...
...
@@ -12,19 +12,13 @@ void displayBoard::start() {
}
void
displayBoard
::
playerMove1
(
int
x
,
int
y
)
{
if
(
x
>
8
||
x
<
0
||
y
>
8
||
y
<
0
)
{
cout
<<
endl
<<
"Invalid (X,Y) coordinates."
<<
endl
<<
endl
;
}
else
{
board
[
x
-
1
][
y
-
1
]
=
{
'X'
};
}
board
[
x
-
1
][
y
-
1
]
=
{
'X'
};
}
void
displayBoard
::
playerMove2
(
int
x
,
int
y
)
{
if
(
x
>
8
||
x
<
0
||
y
>
8
||
y
<
0
)
{
cout
<<
endl
<<
"Invalid (X,Y) coordinates."
<<
endl
<<
endl
;
}
else
{
board
[
x
-
1
][
y
-
1
]
=
{
'O'
};
}
}
void
displayBoard
::
printBoard
()
{
...
...
@@ -224,3 +218,60 @@ void displayBoard::uprightCheck(int x,int y,char chip) {
}
}
bool
displayBoard
::
isValidAdjacent
(
int
row
,
int
col
,
char
oppTurn
)
{
if
(
board
[
row
+
1
][
col
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
-
1
][
col
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
][
col
+
1
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
][
col
-
1
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
-
1
][
col
-
1
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
-
1
][
col
+
1
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
+
1
][
col
-
1
]
==
oppTurn
)
{
return
true
;
}
else
if
(
board
[
row
+
1
][
col
+
1
]
==
oppTurn
)
{
return
true
;
}
return
false
;
}
bool
displayBoard
::
isValidFlip
(
int
row
,
int
col
,
char
playerTurn
)
{
for
(
int
i
=
2
;
i
<
8
;
i
++
)
{
if
(
board
[
row
][
col
+
i
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
][
col
-
i
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
+
i
][
col
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
-
i
][
col
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
+
i
][
col
+
i
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
+
i
][
col
-
i
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
-
i
][
col
+
i
]
==
playerTurn
)
{
return
true
;
}
else
if
(
board
[
row
-
i
][
col
-
i
]
==
playerTurn
)
{
return
true
;
}
}
return
false
;
}
\ No newline at end of file
Board.h
View file @
9702aeaa
...
...
@@ -12,12 +12,17 @@ class displayBoard {
void
playerMove2
(
int
x
,
int
y
);
void
printBoard
();
char
getChip
(
int
x
,
int
y
);
// Checks to flip peices
void
verticalCheck
(
int
x
,
char
chip
);
void
horizontalCheck
(
int
y
,
char
chip
);
void
upleftCheck
(
int
x
,
int
y
,
char
chip
);
void
downleftCheck
(
int
x
,
int
y
,
char
chip
);
void
uprightCheck
(
int
x
,
int
y
,
char
chip
);
void
downrightCheck
(
int
x
,
int
y
,
char
chip
);
// Player movement error checking
bool
isValidAdjacent
(
int
row
,
int
col
,
char
oppTurn
);
bool
isValidFlip
(
int
row
,
int
col
,
char
playerTurn
);
private:
char
board
[
8
][
8
]
=
{};
int
x
;
...
...
mainOthello.cpp
View file @
9702aeaa
...
...
@@ -43,23 +43,36 @@ int main() {
cin
>>
x
>>
y
;
if
(
turn
==
1
)
{
board
.
playerMove1
(
x
,
y
);
board
.
verticalCheck
(
x
,
'X'
);
board
.
horizontalCheck
(
y
,
'X'
);
board
.
uprightCheck
(
x
,
y
,
'X'
);
board
.
upleftCheck
(
x
,
y
,
'X'
);
board
.
downrightCheck
(
x
,
y
,
'X'
);
board
.
downleftCheck
(
x
,
y
,
'X'
);
turn
++
;
if
(
board
.
isValidAdjacent
(
x
-
1
,
y
-
1
,
'O'
)){
board
.
playerMove1
(
x
,
y
);
board
.
verticalCheck
(
x
,
'X'
);
board
.
horizontalCheck
(
y
,
'X'
);
board
.
uprightCheck
(
x
,
y
,
'X'
);
board
.
upleftCheck
(
x
,
y
,
'X'
);
board
.
downrightCheck
(
x
,
y
,
'X'
);
board
.
downleftCheck
(
x
,
y
,
'X'
);
turn
++
;
}
else
{
cout
<<
"Invalid Move!"
<<
endl
;
}
}
else
if
(
turn
==
2
)
{
board
.
playerMove2
(
x
,
y
);
board
.
verticalCheck
(
x
,
'O'
);
board
.
horizontalCheck
(
y
,
'O'
);
board
.
uprightCheck
(
x
,
y
,
'O'
);
board
.
upleftCheck
(
x
,
y
,
'O'
);
board
.
downrightCheck
(
x
,
y
,
'O'
);
board
.
downleftCheck
(
x
,
y
,
'O'
);
turn
--
;
if
(
isValidAdjacent
(
x
-
1
,
y
-
1
,
'X'
)){
board
.
playerMove2
(
x
,
y
);
board
.
verticalCheck
(
x
,
'O'
);
board
.
horizontalCheck
(
y
,
'O'
);
board
.
uprightCheck
(
x
,
y
,
'O'
);
board
.
upleftCheck
(
x
,
y
,
'O'
);
board
.
downrightCheck
(
x
,
y
,
'O'
);
board
.
downleftCheck
(
x
,
y
,
'O'
);
turn
--
;
}
else
{
cout
<<
"Invalid Move!"
<<
endl
;
}
}
}
while
(
winner
==
false
);
...
...
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