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
02b9c5d1
Commit
02b9c5d1
authored
Mar 17, 2019
by
Jason Riggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
ffc256ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
10 deletions
+37
-10
mainOthello.cpp
mainOthello.cpp
+37
-10
No files found.
mainOthello.cpp
View file @
02b9c5d1
...
...
@@ -5,19 +5,23 @@ using namespace std;
int
main
()
{
int
seed
=
0
;
bool
winner
=
false
;
int
turn
=
1
;
int
difficulty
=
0
;
int
x
,
y
;
bool
winner
=
false
;
// Seeding random number genrator
cout
<<
"Please enter a random seed: "
;
cin
>>
seed
;
srand
(
seed
);
srand
(
seed
);
cout
<<
endl
;
//
ask for difficulty level
//
Header
cout
<<
"Welcome to Othello!"
<<
endl
;
cout
<<
"the game of Reversi"
<<
endl
;
cout
<<
endl
;
// ask for difficulty level
cout
<<
"What difficulty would you like to play against:"
<<
endl
;
cout
<<
"1) Easy"
<<
endl
;
cout
<<
"2) Medium"
<<
endl
;
...
...
@@ -26,31 +30,47 @@ int main() {
cout
<<
"Enter your choice: "
;
cin
>>
difficulty
;
// Error checking for difficulty
while
(
cin
.
fail
()){
cin
.
clear
();
cin
.
ignore
(
100
,
'\n'
);
cout
<<
"Invalid selection."
<<
endl
;
cout
<<
"What difficulty would you like to play against:"
<<
endl
;
cout
<<
"1) Easy"
<<
endl
;
cout
<<
"2) Medium"
<<
endl
;
cout
<<
"3) Hard"
<<
endl
;
cout
<<
"4) 2 Player"
<<
endl
;
cout
<<
"Enter your choice: "
;
cin
>>
difficulty
;
}
// start the game
displayBoard
board
;
board
.
start
();
board
.
printBoard
();
cout
<<
"X goes first."
<<
endl
;
do
{
board
.
printBoard
();
// Ask for players move
cout
<<
"Enter the (X,Y) coordinates of where you would like to place a chip: "
;
int
x
,
y
;
cin
>>
x
>>
y
;
// Player one's move
if
(
turn
==
1
)
{
// Check fo valid move
if
(
board
.
isValidAdjacent
(
x
-
1
,
y
-
1
,
'O'
)
&&
board
.
isValidFlip
(
x
-
1
,
y
-
1
,
'X'
)){
// Player moves
board
.
playerMove1
(
x
,
y
);
// Check for flips in every direction
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'
);
// Change to player 2
turn
++
;
}
else
{
...
...
@@ -58,22 +78,29 @@ int main() {
}
// Player two's Move
}
else
if
(
turn
==
2
)
{
// Check fo valid move
if
(
board
.
isValidAdjacent
(
x
-
1
,
y
-
1
,
'X'
)
&&
board
.
isValidFlip
(
x
-
1
,
y
-
1
,
'O'
)){
// Player moves
board
.
playerMove2
(
x
,
y
);
// Check for flips in every direction
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'
);
// Change to player 1
turn
--
;
}
else
{
// Prints invalid and then asks for another move
cout
<<
"Invalid Move!"
<<
endl
;
}
}
board
.
printBoard
();
}
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