Skip to content
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
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@ dir: files/*
@cp files/vector.cpp vorkurs/lektion15/. > /dev/null
@cp files/warnings.cpp vorkurs/lektion16/. > /dev/null
@cp files/warnprim.cpp vorkurs/lektion16/. > /dev/null
@cp files/tictactoe.cpp vorkurs/lektion17/. > /dev/null
@cp files/tictactoe.cpp vorkurs/lektion14/. > /dev/null
@cp files/assemble.cpp vorkurs/lektion18/. > /dev/null
@echo "TTT-Dateien kompilieren…"
@g++ -c -o vorkurs/lektion17/tictactoe.o files/ttt_closed/tictactoe.cpp > /dev/null
@g++ -c -o vorkurs/lektion19/frage_feld_nummer.o files/ttt_closed/frage_feld_nummer.cpp > /dev/null
@g++ -c -o vorkurs/lektion19/gewinnerin.o files/ttt_closed/gewinnerin.cpp > /dev/null
@g++ -c -o vorkurs/lektion19/gebe_feld_aus.o files/ttt_closed/gebe_feld_aus.cpp > /dev/null
@echo "Vorkurs-Verzeichnis erstellt."
@echo "Wenn du das Verzeichnis überall hin kopiert hast, nutze "make nodir", um sicherzustellen, dass das Skript nächstes Jahr wieder funktioniert"

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions appendix/intro.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\chapter{Appendix}
\pagestyle{empty}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ja ist super



\pagestyle{fancy}
\input{appendix/cheatsheet_shortcuts}
\input{appendix/cheatsheet_shellcomands}
\input{appendix/coding_style}
\input{appendix/fehler_fehlermeldungen}

\clearpage
\pagestyle{empty}

50 changes: 0 additions & 50 deletions basics/tictactoe2.tex

This file was deleted.

24 changes: 0 additions & 24 deletions classes/classes.tex

This file was deleted.

9 changes: 0 additions & 9 deletions classes/content.txt

This file was deleted.

24 changes: 0 additions & 24 deletions classes/enum.tex

This file was deleted.

12 changes: 0 additions & 12 deletions classes/intro.tex

This file was deleted.

53 changes: 0 additions & 53 deletions classes/struct.tex

This file was deleted.

124 changes: 124 additions & 0 deletions files/solutions/tictactoe.cpp
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;
}
Loading
Loading