-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New features 2025 #148
Closed
Closed
New features 2025 #148
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
808d25a
initial commit. Structure has already been partially implemented in the
fschledorn 7535a7a
removed old obsolete files
fschledorn df56dd0
added missing chapter on recursion to intro.tex and moved around a few
fschledorn 955e9c7
Revised the Compiling section
fschledorn ee3f40a
Tictactoe (#144)
fschledorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
\chapter{Appendix} | ||
\pagestyle{empty} | ||
|
||
|
||
\pagestyle{fancy} | ||
\input{appendix/cheatsheet_shortcuts} | ||
\input{appendix/cheatsheet_shellcomands} | ||
\input{appendix/coding_style} | ||
\input{appendix/fehler_fehlermeldungen} | ||
|
||
\clearpage | ||
\pagestyle{empty} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include <iostream> | ||
#include <array> | ||
|
||
static std::string fts(int feld) { | ||
switch (feld) { | ||
case 0: | ||
return " "; | ||
case 1: | ||
return "X"; | ||
case 2: | ||
return "O"; | ||
default: | ||
return "?"; | ||
} | ||
} | ||
|
||
int frage_feld_nummer(std::array<int, 9> feld){ | ||
int in = -1; | ||
while (true) { | ||
std::cout << "Gib ein Feld ein (0-8): "; | ||
std::cin >> in; | ||
if (in < 0 || in > 8) { | ||
std::cout << "Ungültige Feldnummer!" << std::endl; | ||
continue; | ||
} | ||
if (feld[in] != 0) { | ||
std::cout << "Feld ist besetzt!" << std::endl; | ||
continue; | ||
} | ||
break; | ||
} | ||
return in; | ||
} | ||
|
||
void gebe_feld_aus(std::array<int, 9> feld){ | ||
std::cout << " | | " << std::endl; | ||
std::cout << " " << fts(feld[0]) << " | " << fts(feld[1]) << " | " << fts(feld[2]) << " " << std::endl; | ||
std::cout << " | | " << std::endl; | ||
std::cout << "---+---+---" << std::endl; | ||
std::cout << " | | " << std::endl; | ||
std::cout << " " << fts(feld[3]) << " | " << fts(feld[4]) << " | " << fts(feld[5]) << " " << std::endl; | ||
std::cout << " | | " << std::endl; | ||
std::cout << "---+---+---" << std::endl; | ||
std::cout << " | | " << std::endl; | ||
std::cout << " " << fts(feld[6]) << " | " << fts(feld[7]) << " | " << fts(feld[8]) << " " << std::endl; | ||
std::cout << " | | " << std::endl; | ||
} | ||
|
||
int gewinnerin(std::array<int, 9> feld){ | ||
// Prüfe Reihen und Spalten | ||
for (int i = 0; i < 3; i++) { | ||
int a = feld[3*i] & feld[3*i+1] & feld[3*i+2]; | ||
int b = feld[3*i] | feld[3*i+1] | feld[3*i+2]; | ||
if (a == b && a != 0) { | ||
return feld[3*i]; | ||
} | ||
a = feld[i] & feld[i+3] & feld[i+6]; | ||
b = feld[i] | feld[i+3] | feld[i+6]; | ||
if (a == b && a != 0) { | ||
return feld[i]; | ||
} | ||
} | ||
// Prüfe Diagonale 1 | ||
int a = feld[0] & feld[4] & feld[8]; | ||
int b = feld[0] | feld[4] | feld[8]; | ||
if (a == b && a != 0) { | ||
return feld[0]; | ||
} | ||
|
||
// Prüfe Diagonale 2 | ||
a = feld[2] & feld[4] & feld[6]; | ||
b = feld[2] | feld[4] | feld[6]; | ||
if (a == b && a != 0) { | ||
return feld[2]; | ||
} | ||
|
||
for (int i = 0; i < 9; i++) { | ||
if (feld[i] == 0) { | ||
return 0; | ||
} | ||
} | ||
return 3; | ||
} | ||
|
||
|
||
|
||
int main() { | ||
// Setup | ||
restart: | ||
std::array<int, 9> spielfeld{0}; | ||
int current_player = 1; | ||
int input_player; | ||
|
||
while (true) { | ||
// Input | ||
input_player = frage_feld_nummer(spielfeld); | ||
|
||
// Update | ||
spielfeld[input_player] = current_player; | ||
int gewinner = gewinnerin(spielfeld); | ||
switch (gewinner) { | ||
case 1: | ||
std::cout << "Spieler 1 ist der Gewinner." << std::endl; | ||
goto restart; | ||
|
||
case 2: | ||
std::cout << "Spieler 2 ist der Gewinner." << std::endl; | ||
goto restart; | ||
|
||
case 3: | ||
std::cout << "Das Spiel endet unentschieden." << std::endl; | ||
goto restart; | ||
|
||
default: | ||
current_player = (current_player == 2) ? 1 : 2; | ||
break; | ||
} | ||
|
||
|
||
// Display | ||
gebe_feld_aus(spielfeld); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ja ist super