Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG1004_2022_group4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Magnus Westerheim Johannessen
PROG1004_2022_group4
Commits
224d653a
Commit
224d653a
authored
3 years ago
by
lokesvelland
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.stud.idi.ntnu.no:magnuswj/prog-1004-2022-group-4
parents
b3cdc68d
bee57832
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/kode/checkmate.cpp
+78
-45
78 additions, 45 deletions
src/kode/checkmate.cpp
with
78 additions
and
45 deletions
src/kode/checkmate.cpp
+
78
−
45
View file @
224d653a
...
@@ -40,9 +40,9 @@ public:
...
@@ -40,9 +40,9 @@ public:
};
};
void
writePlayer
()
const
;
void
writePlayer
()
const
;
void
updatePlayer
();
void
updatePlayer
();
int
playerWin
()
{
wins
=
0
;
};
void
playerWin
()
{
wins
=
0
;};
int
playerDraws
()
{
draws
=
0
;
};
void
playerDraws
()
{
draws
=
0
;};
float
playerScore
()
{
score
=
0
;
};
void
playerScore
()
{
score
=
0
;};
void
calculateScore
();
void
calculateScore
();
void
writeToFilePlayer
(
ofstream
&
out
);
void
writeToFilePlayer
(
ofstream
&
out
);
void
readFromFilePlayer
(
ifstream
&
in
);
void
readFromFilePlayer
(
ifstream
&
in
);
...
@@ -51,10 +51,9 @@ public:
...
@@ -51,10 +51,9 @@ public:
class
Tournament
class
Tournament
{
{
private:
private:
int
tableNr
[
gTables
];
// these will only work if gTables is a const?
vector
<
int
*>
tableNr
;
string
player1
[
gTables
],
vector
<
string
*>
player1
;
player2
[
gTables
];
vector
<
string
*>
player2
;
public:
public:
void
writeTournament
();
void
writeTournament
();
void
fillTableArray
();
void
fillTableArray
();
...
@@ -87,14 +86,18 @@ bool checkPlayers();
...
@@ -87,14 +86,18 @@ bool checkPlayers();
void
skrivMeny
();
void
skrivMeny
();
void
writeToFile
();
void
writeToFile
();
void
readFromFile
();
void
readFromFile
();
void
writeToFileTournament
();
void
readFromFileTournament
();
void
amntTables
();
int
main
()
{
int
main
()
{
char
command
;
char
command
;
// readFromFile();
readFromFile
();
readFromFileTournament
();
// ask for amount of t
ables
amntT
ables
();
skrivMeny
();
skrivMeny
();
command
=
lesChar
(
"
\n
Kommando"
);
command
=
lesChar
(
"
\n
Kommando"
);
...
@@ -114,7 +117,8 @@ int main()
...
@@ -114,7 +117,8 @@ int main()
command
=
lesChar
(
"
\n
Kommando"
);
command
=
lesChar
(
"
\n
Kommando"
);
}
}
// writeToFile();
writeToFileTournament
();
writeToFile
();
return
0
;
return
0
;
}
}
...
@@ -272,12 +276,10 @@ void Tournament::fillTableArray()
...
@@ -272,12 +276,10 @@ void Tournament::fillTableArray()
*
*
* @param out - the file being written to
* @param out - the file being written to
*/
*/
void
Tournament
::
writeToFileTournament
(
ofstream
&
out
)
void
Tournament
::
writeToFileTournament
(
ofstream
&
out
){
{
for
(
int
i
=
0
;
i
<
gTables
;
i
++
)
for
(
int
i
=
0
;
i
<
gTables
;
i
++
){
{
out
<<
player1
[
i
]
out
<<
setw
(
STRLEN
)
<<
player1
[
i
]
<<
setw
(
STRLEN
)
<<
player2
[
i
]
<<
setw
(
STRLEN
)
<<
player2
[
i
]
<<
setw
(
STRLEN
)
<<
tableNr
[
i
]
<<
setw
(
STRLEN
)
<<
tableNr
[
i
]
<<
"
\n
"
;
<<
"
\n
"
;
...
@@ -344,15 +346,33 @@ void enterResults()
...
@@ -344,15 +346,33 @@ void enterResults()
*
*
* @see - calculateScore()
* @see - calculateScore()
*/
*/
void
viewResults
()
void
viewResults
()
{
{
int
temp
[
gPlayers
.
size
()];
for
(
int
i
=
0
;
i
<
gPlayers
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
gPlayers
.
size
();
i
++
){
{
gPlayers
[
i
]
->
calculateScore
();
//Calculates score for every player
gPlayers
[
i
]
->
calculateScore
();
for
(
int
i
=
0
;
i
<
gPlayers
.
size
();
i
++
){
//Sorts scores and puts it in an array
for
(
int
j
=
i
+
1
;
j
<
gPlayers
.
size
();
i
++
){
if
(
gPlayers
[
i
]
->
score
<
gPlayers
[
j
]
->
score
){
temp
[
i
]
=
gPlayers
[
j
]
->
score
;
}
}
}
}
}
}
for
(
int
i
=
0
;
i
<
gPlayers
.
size
();
i
++
){
//For MVP-purposes no scores can be identical
cout
<<
temp
[
i
]
<<
"
\t
"
;
for
(
int
j
=
0
;
j
<
gPlayers
.
size
();
i
++
){
if
(
gPlayers
[
j
]
->
score
==
temp
[
i
]){
cout
<<
gPlayers
[
j
]
->
name
;
}
cout
<<
"
\n
"
;
}
}
}
/**
/**
* Create a new tournament, with black and white players and what table they're playing at
* Create a new tournament, with black and white players and what table they're playing at
* @see writeTournament()
* @see writeTournament()
...
@@ -558,6 +578,19 @@ void readFromFileTournament()
...
@@ -558,6 +578,19 @@ void readFromFileTournament()
infile
.
close
();
infile
.
close
();
}
}
infile
.
close
();
}
else
else
cout
<<
"
\n
Couldn't find tournamentData.dta!
\n
"
;
cout
<<
"
\n
Couldn't find tournamentData.dta!
\n
"
;
}
/**
* Asks user for number of tables
*
*/
void
amntTables
(){
cout
<<
"How many tables do you have?
\n
"
;
gTables
=
lesInt
(
"Tables:"
,
1
,
200
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment