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
65cc3870
Commit
65cc3870
authored
Mar 14, 2019
by
Jason Riggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
e4064e30
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
220 additions
and
17 deletions
+220
-17
Board.cpp
Board.cpp
+180
-3
Board.h
Board.h
+25
-13
mainOthello.cpp
mainOthello.cpp
+15
-1
No files found.
Board.cpp
View file @
65cc3870
...
@@ -44,6 +44,183 @@ void displayBoard::printBoard() {
...
@@ -44,6 +44,183 @@ void displayBoard::printBoard() {
}
}
}
}
char
displayBoard
::
chipCheck
(
int
x
,
int
y
)
{
char
displayBoard
::
getChip
(
int
x
,
int
y
)
{
return
board
[
x
][
y
];
return
board
[
x
-
1
][
y
-
1
];
}
}
void
displayBoard
::
verticalCheck
(
int
x
,
char
chip
)
{
int
firstX
=
0
;
int
secondX
=
0
;
x
-=
1
;
for
(
int
i
=
firstX
;
i
<
8
;
i
++
)
{
if
(
board
[
x
][
i
]
==
chip
)
{
firstX
=
i
;
break
;
}
}
for
(
int
i
=
7
;
i
>
firstX
;
i
--
)
{
if
(
board
[
x
][
i
]
==
chip
)
{
secondX
=
i
;
break
;
}
}
for
(
int
i
=
firstX
;
i
<=
secondX
;
i
++
)
{
board
[
x
][
i
]
=
{
chip
};
}
}
void
displayBoard
::
horizontalCheck
(
int
y
,
char
chip
)
{
int
firstY
=
0
;
int
secondY
=
0
;
y
-=
1
;
for
(
int
i
=
firstY
;
i
<
8
;
i
++
)
{
if
(
board
[
i
][
y
]
==
chip
)
{
firstY
=
i
;
break
;
}
}
for
(
int
i
=
7
;
i
>
firstY
;
i
--
)
{
if
(
board
[
i
][
y
]
==
chip
)
{
secondY
=
i
;
break
;
}
}
for
(
int
i
=
firstY
;
i
<=
secondY
;
i
++
)
{
board
[
i
][
y
]
=
{
chip
};
}
}
void
displayBoard
::
downleftCheck
(
int
x
,
int
y
,
char
chip
)
{
x
-=
1
;
y
-=
1
;
int
firstX
=
x
;
int
firstY
=
y
;
int
secondX
;
int
secondY
;
bool
addChip
=
false
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
board
[
firstX
-
i
][
firstY
+
i
]
==
chip
)
{
secondX
=
firstX
-
i
;
secondY
=
firstY
+
i
;
if
(
secondX
<
8
&&
secondY
<
8
)
{
addChip
=
true
;
}
break
;
}
}
if
(
addChip
==
true
)
{
int
temp
=
firstX
-
secondX
;
int
i
=
1
;
while
(
temp
>
0
)
{
board
[
firstX
-
i
][
firstY
+
i
]
=
{
chip
};
temp
--
;
i
++
;
}
}
}
void
displayBoard
::
upleftCheck
(
int
x
,
int
y
,
char
chip
)
{
x
-=
1
;
y
-=
1
;
int
firstX
=
x
;
int
firstY
=
y
;
int
secondX
;
int
secondY
;
bool
addChip
=
false
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
board
[
firstX
-
i
][
firstY
-
i
]
==
chip
)
{
secondX
=
firstX
-
i
;
secondY
=
firstY
-
i
;
if
(
secondX
<
8
&&
secondY
<
8
)
{
addChip
=
true
;
}
break
;
}
}
if
(
addChip
==
true
)
{
int
temp
=
firstX
-
secondX
;
int
i
=
1
;
while
(
temp
>
0
)
{
board
[
firstX
-
i
][
firstY
-
i
]
=
{
chip
};
temp
--
;
i
++
;
}
}
}
void
displayBoard
::
downrightCheck
(
int
x
,
int
y
,
char
chip
)
{
x
-=
1
;
y
-=
1
;
int
firstX
=
x
;
int
firstY
=
y
;
int
secondX
;
int
secondY
;
bool
addChip
=
false
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
board
[
firstX
+
i
][
firstY
+
i
]
==
chip
)
{
secondX
=
firstX
+
i
;
secondY
=
firstY
+
i
;
if
(
secondX
<
8
&&
secondY
<
8
)
{
addChip
=
true
;
}
break
;
}
}
if
(
addChip
==
true
)
{
int
temp
=
secondX
-
firstX
;
int
i
=
1
;
while
(
temp
>
0
)
{
board
[
firstX
+
i
][
firstY
+
i
]
=
{
chip
};
temp
--
;
i
++
;
}
}
}
void
displayBoard
::
uprightCheck
(
int
x
,
int
y
,
char
chip
)
{
x
-=
1
;
y
-=
1
;
int
firstX
=
x
;
int
firstY
=
y
;
int
secondX
;
int
secondY
;
bool
addChip
=
false
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
board
[
firstX
+
i
][
firstY
-
i
]
==
chip
)
{
secondX
=
firstX
+
i
;
secondY
=
firstY
-
i
;
if
(
secondX
<
8
&&
secondY
<
8
)
{
addChip
=
true
;
}
break
;
}
}
if
(
addChip
==
true
)
{
int
temp
=
secondX
-
firstX
;
int
i
=
1
;
while
(
temp
>
0
)
{
board
[
firstX
+
i
][
firstY
-
i
]
=
{
chip
};
temp
--
;
i
++
;
}
}
}
Board.h
View file @
65cc3870
#include <iostream>
#include <vector>
using
namespace
std
;
class
displayBoard
{
class
displayBoard
{
public:
public:
void
start
();
void
start
();
// mutators and other
void
playerMove1
(
int
x
,
int
y
);
void
playerMove1
(
int
x
,
int
y
);
void
playerMove2
(
int
x
,
int
y
);
void
playerMove2
(
int
x
,
int
y
);
void
printBoard
();
void
printBoard
();
char
chipCheck
(
int
x
,
int
y
);
char
getChip
(
int
x
,
int
y
);
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
);
private:
private:
char
board
[
9
][
9
]
=
{};
char
board
[
8
][
8
]
=
{};
int
x
;
int
x
;
int
y
;
int
y
;
};
};
mainOthello.cpp
View file @
65cc3870
...
@@ -34,7 +34,7 @@ int main() {
...
@@ -34,7 +34,7 @@ int main() {
displayBoard
board
;
displayBoard
board
;
board
.
start
();
board
.
start
();
// loop until finish
do
{
do
{
board
.
printBoard
();
board
.
printBoard
();
cout
<<
"Enter the (X,Y) coordinates of where you would like to place a chip: "
;
cout
<<
"Enter the (X,Y) coordinates of where you would like to place a chip: "
;
...
@@ -44,13 +44,27 @@ int main() {
...
@@ -44,13 +44,27 @@ int main() {
if
(
turn
==
1
)
{
if
(
turn
==
1
)
{
board
.
playerMove1
(
x
,
y
);
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
++
;
turn
++
;
}
else
if
(
turn
==
2
)
{
}
else
if
(
turn
==
2
)
{
board
.
playerMove2
(
x
,
y
);
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
--
;
turn
--
;
}
}
}
while
(
winner
==
false
);
}
while
(
winner
==
false
);
return
0
;
return
0
;
}
}
\ No newline at end of file
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