16 Commits
Author SHA1 Message Date
bhattini101169 bf9b1bc1dc Dateien nach "/" hochladen 2025-12-22 15:55:14 +00:00
bhattini101169 b70424b24c Merge remote-tracking branch 'origin/master' 2025-12-22 16:52:51 +01:00
bhattini101169 b829d1b699 commit 2025-12-22 16:52:08 +01:00
bidlingmaieran101448 8f35533e85 Dateien nach "/" hochladen 2025-12-22 15:47:25 +00:00
Anke 1396ad6883 serielle Basisversion & parallele_zeileverlegung angefangen 2025-12-22 14:44:37 +01:00
Anke eb47581c1d serielle Basisversion 2025-12-15 15:19:28 +01:00
Anke 8c28df46c3 seriell 2025-12-15 14:24:16 +01:00
Anke 726f3acfc8 seriell 2025-12-15 14:24:09 +01:00
Anke 3e4d49fe26 GameState Aufgabe 2025-12-08 18:20:49 +01:00
aksaiyan18-design 0e28bbbf41 Flexible Würfelanzahl 2025-12-08 16:00:12 +01:00
Anke ac117a847b CMakeLists für Windows und Mac 2025-11-24 21:55:17 +01:00
aksaiyan18-design fb5673287a Alles gerettet 2025-11-24 18:20:35 +01:00
aksaiyan18-design 5e544891b4 adding gitignore 2025-11-24 17:17:46 +01:00
aksaiyan18-design 43d06f786f gitignore 2025-11-24 17:16:40 +01:00
aksaiyan18-design ebc86d529a idea problem 2025-11-24 16:36:13 +01:00
aksaiyan18-design 199e862239 unötiger commit 2025-11-24 16:21:00 +01:00
12 changed files with 452 additions and 41 deletions

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
.idea
cmake-build-debug
+34 -17
View File
@@ -1,35 +1,52 @@
cmake_minimum_required(VERSION 3.28) cmake_minimum_required(VERSION 3.28)
project(Prog3B) project(Prog3B)
set(EXECUTABLE_NAME Prog3B) set(EXECUTABLE_NAME Prog3B)
# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set the default build type if not specified # Default build type
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif() endif()
# Quell- und Header-Dateien
set(SRC_FILES set(SRC_FILES
${CMAKE_CURRENT_LIST_DIR}/main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp ${CMAKE_CURRENT_LIST_DIR}/src/gamecube.cpp
${CMAKE_CURRENT_LIST_DIR}/src/gamematrix.cpp
includes/gamestate.h
src/seriell.cpp
) )
#automatisch hinzufügen
file(GLOB SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp")
set(INCLUDE_DIRS set(INCLUDE_DIRS
${CMAKE_CURRENT_LIST_DIR}/linux ${CMAKE_CURRENT_LIST_DIR}/includes
${CMAKE_CURRENT_LIST_DIR}/raylib
) )
# Executable erstellen
add_executable(${EXECUTABLE_NAME} ${SRC_FILES}) add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/linux/libgamematrix.a
${CMAKE_CURRENT_LIST_DIR}/linux/libraylib.a
)
# Checks if OSX and links appropriate frameworks (Only required on MacOS) # Include-Verzeichnisse hinzufügen
if (APPLE) target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
target_link_libraries(Prog3B "-framework IOKit")
target_link_libraries(Prog3B "-framework Cocoa")
target_link_libraries(Prog3B "-framework OpenGL") # Nur noch raylib und systemabhängige Libraries linken
if(WIN32)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/windows/libraylib.a
winmm
)
endif()
# macOS
if(APPLE)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/mac_arm/libraylib.a
"-framework Cocoa"
"-framework IOKit"
"-framework OpenGL"
)
endif() endif()
View File
File renamed without changes.
+5
View File
@@ -16,4 +16,9 @@ public:
// Verschiebung // Verschiebung
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos); static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
// 4x4 Einheitsmatrix
static std::array<std::array<double,4>,4> identity(); // <-- add this
}; };
+17
View File
@@ -0,0 +1,17 @@
//
// Created by Anke Bidlingmaier on 08.12.25.
//
#pragma once
#ifndef PROG3B_GAMESTATE_H
#define PROG3B_GAMESTATE_H
enum class GameState
{
Idle, // kein Würfel offen, Eingabe erlaubt
OneFlipped, // ein Würfel offen
CheckingMatch, // zwei Würfel vollständig aufgeklappt, Vergleich läuft
LockInput // Würfel drehen gerade – Eingabe kurz blockiert
};
#endif //PROG3B_GAMESTATE_H
+94
View File
@@ -0,0 +1,94 @@
#include <vector>
#include <chrono>
#include <iostream>
#include <omp.h>
#include <cstdlib>
#include <ctime>
// Zufallsmatrizen erzeugen
void generateRandomMatrices(int n,
std::vector<std::vector<double>>& A,
std::vector<std::vector<double>>& B)
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
A.resize(n, std::vector<double>(n));
B.resize(n, std::vector<double>(n));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
A[i][j] = static_cast<double>(rand()) / RAND_MAX * 10.0;
B[i][j] = static_cast<double>(rand()) / RAND_MAX * 10.0;
}
}
// Serielle Matrizenmultiplikation
std::vector<std::vector<double>> matmul_serial(
const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
for (int k = 0; k < p; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
// Spaltenparallel (Column-parallel)
std::vector<std::vector<double>> matmul_column_parallel(
const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
#pragma omp parallel for
for (int j = 0; j < m; ++j) // Spalten parallel
for (int i = 0; i < n; ++i)
for (int k = 0; k < p; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
// -----------------------------
int main()
{
int N = 500;
std::vector<std::vector<double>> A, B;
generateRandomMatrices(N, A, B);
// Serielle Version
auto start = std::chrono::steady_clock::now();
auto C_serial = matmul_serial(A, B);
auto end = std::chrono::steady_clock::now();
std::cout << "Serial multiplication took: "
<< std::chrono::duration<double>(end - start).count() << "s\n";
// Spaltenparallel
start = std::chrono::steady_clock::now();
auto C_col = matmul_column_parallel(A, B);
end = std::chrono::steady_clock::now();
std::cout << "Column-parallel multiplication took: "
<< std::chrono::duration<double>(end - start).count() << "s\n";
// Vergleich
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (C_serial[i][j] != C_col[i][j])
{
std::cout << "Mismatch at " << i << "," << j << "\n";
return 1;
}
std::cout << "All results match!\n";
return 0;
}
+94
View File
@@ -0,0 +1,94 @@
#include <vector>
#include <chrono>
#include <iostream>
#include <omp.h>
#include <cstdlib>
#include <ctime>
// Zufallsmatrizen erzeugen
void generateRandomMatrices(int n,
std::vector<std::vector<double>>& A,
std::vector<std::vector<double>>& B)
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
A.resize(n, std::vector<double>(n));
B.resize(n, std::vector<double>(n));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
A[i][j] = static_cast<double>(rand()) / RAND_MAX * 10.0;
B[i][j] = static_cast<double>(rand()) / RAND_MAX * 10.0;
}
}
// Serielle Matrizenmultiplikation
std::vector<std::vector<double>> matmul_serial(
const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
for (int k = 0; k < p; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
// Parallele Zeilenzerlegung
std::vector<std::vector<double>> matmul_row_parallel(
const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
#pragma omp parallel for
for (int i = 0; i < n; ++i) // Zeilen parallel
for (int j = 0; j < m; ++j)
for (int k = 0; k < p; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
// -----------------------------
int main()
{
int N = 500;
std::vector<std::vector<double>> A, B;
generateRandomMatrices(N, A, B);
// Serielle Version
auto start = std::chrono::steady_clock::now();
auto C_serial = matmul_serial(A, B);
auto end = std::chrono::steady_clock::now();
std::cout << "Serial multiplication took: "
<< std::chrono::duration<double>(end - start).count() << "s\n";
// Zeilenparallel
start = std::chrono::steady_clock::now();
auto C_row = matmul_row_parallel(A, B);
end = std::chrono::steady_clock::now();
std::cout << "Row-parallel multiplication took: "
<< std::chrono::duration<double>(end - start).count() << "s\n";
// Vergleich
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (C_serial[i][j] != C_row[i][j])
{
std::cout << "Mismatch at " << i << "," << j << "\n";
return 1;
}
std::cout << "All results match!\n";
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 560 KiB

+67
View File
@@ -0,0 +1,67 @@
#include <vector>
#include <chrono>
#include <iostream>
// Funktion erzeugt zwei Matrizen A und B der Größe n x n mit Zufallswerten
void generateRandomMatrices(int n,
std::vector<std::vector<double>>& A,
std::vector<std::vector<double>>& B,
double min_val = 0.0,
double max_val = 10.0)
{
// Zufallsgenerator initialisieren
std::srand(static_cast<unsigned int>(std::time(nullptr)));
A.resize(n, std::vector<double>(n));
B.resize(n, std::vector<double>(n));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
double r1 = static_cast<double>(std::rand()) / RAND_MAX; // 0..1
double r2 = static_cast<double>(std::rand()) / RAND_MAX; // 0..1
A[i][j] = min_val + r1 * (max_val - min_val);
B[i][j] = min_val + r2 * (max_val - min_val);
}
}
// Matrizenmultiplikation
std::vector<std::vector<double>> matmul(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
if (A[0].size() != B.size())
throw std::runtime_error("Matrixgrößen passen nicht.");
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
for (int k = 0; k < p; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
int main()
{
int N = 500; // z.B. 500x500
std::vector<std::vector<double>> A, B;
auto start = std::chrono::steady_clock::now();
generateRandomMatrices(N, A, B);
auto C_serial = matmul(A, B);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "Took: " << diff.count() << "s\n";
return 0;
}
//
// Created by Anke Bidlingmaier on 15.12.25.
+17 -6
View File
@@ -1,16 +1,27 @@
#include "gamecube.h" #include "gamecube.h"
// Konstanten für Rotation und Matrixgröße
constexpr float ROTATION_HALF = 90.0f;
constexpr float ROTATION_FULL = 180.0f;
// Standardfarben
const Color DEFAULT_COLOR = GRAY;
const Color WIRES_COLOR = BLACK;
gamecube::gamecube(const Vec3 &pos, Color col) gamecube::gamecube(const Vec3 &pos, Color col)
: position(pos), color(col) {} : position(pos), color(col) {}
// ✅ Klar strukturierte Funktion
void gamecube::Update(float flipSpeed) void gamecube::Update(float flipSpeed)
{ {
if (flippingForward) if (flippingForward)
{ {
rotation += flipSpeed; rotation += flipSpeed;
if (rotation >= 180.0f) if (rotation >= ROTATION_FULL) // ⚠️ Magic Number
{ {
rotation = 180.0f; rotation = ROTATION_FULL; // ⚠️ Magic Number
flippingForward = false; flippingForward = false;
flipped = true; flipped = true;
} }
@@ -30,7 +41,7 @@ void gamecube::Update(float flipSpeed)
void gamecube::FlipForward() { flippingForward = true; } void gamecube::FlipForward() { flippingForward = true; }
void gamecube::FlipBackward() { flippingBackward = true; } void gamecube::FlipBackward() { flippingBackward = true; }
bool gamecube::IsFlipped() const { return flipped; } bool gamecube::IsFlipped() const { return flipped; } // ✅ Getter sauber, const korrekt
bool gamecube::IsMatched() const { return matched; } bool gamecube::IsMatched() const { return matched; }
void gamecube::SetMatched(bool m) { matched = m; } void gamecube::SetMatched(bool m) { matched = m; }
@@ -52,12 +63,12 @@ void gamecube::Draw() const
f[j * 4 + i] = model[i][j]; f[j * 4 + i] = model[i][j];
rlMultMatrixf(f); rlMultMatrixf(f);
if (rotation < 90.0f) if (rotation < ROTATION_HALF) // ⚠️ Magic Number
DrawCube({0,0,0}, 1,1,1, GRAY); DrawCube({0,0,0}, 1,1,1, DEFAULT_COLOR);
else else
DrawCube({0,0,0}, 1,1,1, color); DrawCube({0,0,0}, 1,1,1, color);
DrawCubeWires({0,0,0}, 1,1,1, BLACK); DrawCubeWires({0,0,0}, 1,1,1,WIRES_COLOR);
rlPopMatrix(); rlPopMatrix();
} }
+77
View File
@@ -0,0 +1,77 @@
#include "gamematrix.h"
#include <cmath>
#include <stdexcept>
// Matrix Multiplikation
std::array<std::array<double,4>,4> gameMatrix::matmul(
const std::array<std::array<double,4>,4>& A,
const std::array<std::array<double,4>,4>& B)
{
std::array<std::array<double,4>,4> result = {0};
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
{
result[i][j] = 0.0;
for (int k = 0; k < 4; ++k)
result[i][j] += A[i][k] * B[k][j];
}
return result;
}
// Rotationsmatrix
std::array<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis)
{
double angle_rad = angle_deg * M_PI / 180.0;
double c = std::cos(angle_rad);
double s = std::sin(angle_rad);
std::array<std::array<double,4>,4> R = identity();
switch (axis)
{
case 'x': case 'X':
R[1][1] = c; R[1][2] = -s;
R[2][1] = s; R[2][2] = c;
break;
case 'y': case 'Y':
R[0][0] = c; R[0][2] = s;
R[2][0] = -s; R[2][2] = c;
break;
case 'z': case 'Z':
R[0][0] = c; R[0][1] = -s;
R[1][0] = s; R[1][1] = c;
break;
default:
throw std::invalid_argument("Invalid axis for rotation (use x, y, or z)");
}
return R;
}
// Einheitsmatrix-Matrix
std::array<std::array<double,4>,4> gameMatrix::identity()
{
std::array<std::array<double,4>,4> I = {0};
for (int i = 0; i < 4; ++i)
I[i][i] = 1.0;
return I;
}
// Translation
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double,3>& pos)
{
std::array<std::array<double,4>,4> T = identity();
T[0][3] = pos[0];
T[1][3] = pos[1];
T[2][3] = pos[2];
return T;
}
+45 -18
View File
@@ -1,12 +1,22 @@
#include "gamecube.h" #include "gamecube.h"
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>
#include <vector>
#include <iostream>
#include "gamestate.h"
// ----------------------------------------------------------- // -----------------------------------------------------------
// 3D Memory Game – Hauptprogramm // 3D Memory Game – Hauptprogramm mit flexibler Paaranzahl
// ----------------------------------------------------------- // -----------------------------------------------------------
int main() int main()
{ {
// ✅ Schritt 1: Anzahl der Paare eingeben
int numPairs;
std::cout << "Geben Sie die Anzahl der Paare ein (2-10): ";
std::cin >> numPairs;
if(numPairs < 2) numPairs = 2;
if(numPairs > 10) numPairs = 10;
// Zufall initialisieren // Zufall initialisieren
srand(time(NULL)); srand(time(NULL));
@@ -21,45 +31,50 @@ int main()
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE; camera.projection = CAMERA_PERSPECTIVE;
// Nur 3 Farben für 3 Paare // Farben generieren (maximal 10 Farben)
Color colors[] = { RED, GREEN, BLUE }; Color baseColors[10] = { RED, GREEN, BLUE, ORANGE, PURPLE, GOLD, PINK, BROWN, SKYBLUE, LIME };
std::vector<Color> colors(baseColors, baseColors + numPairs);
// 6 Karten-Positionen im 3x2 Raster // Positionen dynamisch berechnen (Raster 3 Spalten)
std::vector<Vec3> positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}}; std::vector<Vec3> positions;
for (int i = 0; i < numPairs*2; ++i)
positions.push_back({ float(i % 3) * 2 - 2, 0, float(i / 3) * 2 - 2 });
// Farben doppelt in einen Pool legen und mischen // Farben doppelt in einen Pool legen und mischen
std::vector<Color> colorPool; std::vector<Color> colorPool;
for (int i = 0; i < 3; i++) for (int i = 0; i < numPairs; i++)
{ {
colorPool.push_back(colors[i]); colorPool.push_back(colors[i]);
colorPool.push_back(colors[i]); colorPool.push_back(colors[i]);
} }
// Fisher-Yates Shuffle mit rand() // Fisher-Yates Shuffle mit rand()
for (int i = colorPool.size() - 1; i > 0; --i) for (int i = colorPool.size() - 1; i > 0; --i)
{ {
int j = rand() % (i + 1); // Zufallsindex von 0 bis i int j = rand() % (i + 1);
std::swap(colorPool[i], colorPool[j]); std::swap(colorPool[i], colorPool[j]);
} }
// Karten/Würfel erstellen // Karten/Würfel erstellen
std::vector<gamecube> cubes; std::vector<gamecube> cubes;
for (int i = 0; i < 6; i++) for (int i = 0; i < numPairs*2; i++)
cubes.emplace_back(positions[i], colorPool[i]); cubes.emplace_back(positions[i], colorPool[i]);
gamecube* first = nullptr; gamecube* first = nullptr;
gamecube* second = nullptr; gamecube* second = nullptr;
float flipSpeed = 5.0f; // Drehgeschwindigkeit float flipSpeed = 5.0f;
bool gameWon = false; bool gameWon = false;
GameState state = GameState::Idle;
// ----------------------------------------------------------- // -----------------------------------------------------------
// Hauptspielschleife // Hauptspielschleife
// ----------------------------------------------------------- // -----------------------------------------------------------
while (!WindowShouldClose()) while (!WindowShouldClose())
{ {
// Klick-Erkennung //Klick-Erkennung
if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) if (!gameWon && state != GameState::LockInput && state != GameState::CheckingMatch && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{ {
Vector2 mouse = GetMousePosition(); Vector2 mouse = GetMousePosition();
for (auto &c : cubes) for (auto &c : cubes)
@@ -68,8 +83,12 @@ int main()
{ {
Vector2 screenPos = GetWorldToScreen({c.GetPosition().x, c.GetPosition().y, c.GetPosition().z}, camera); Vector2 screenPos = GetWorldToScreen({c.GetPosition().x, c.GetPosition().y, c.GetPosition().z}, camera);
if (fabs(mouse.x - screenPos.x) < 40 && fabs(mouse.y - screenPos.y) < 40) if (fabs(mouse.x - screenPos.x) < 40 && fabs(mouse.y - screenPos.y) < 40) {
c.FlipForward(); c.FlipForward();
state = GameState::OneFlipped;
}
} }
} }
} }
@@ -85,15 +104,20 @@ int main()
if (!first) first = &c; if (!first) first = &c;
else if (!second && &c != first) second = &c; else if (!second && &c != first) second = &c;
} }
if (first && second && first->IsFlipped() && second->IsFlipped()) {
state = GameState::LockInput;
}
if (state == GameState::LockInput) {
state = GameState::CheckingMatch;
}
} }
// Matching-Logik // Matching-Logik
if (first && second) if (state == GameState::CheckingMatch && first && second)
{ {
Color col1 = first->GetColor(); if (first->GetColor().r == second->GetColor().r &&
Color col2 = second->GetColor(); first->GetColor().g == second->GetColor().g &&
first->GetColor().b == second->GetColor().b)
if (col1.r == col2.r && col1.g == col2.g && col1.b == col2.b)
{ {
first->SetMatched(true); first->SetMatched(true);
second->SetMatched(true); second->SetMatched(true);
@@ -105,6 +129,7 @@ int main()
} }
first = second = nullptr; first = second = nullptr;
state = GameState::Idle;
} }
// Gewinnprüfung // Gewinnprüfung
@@ -128,6 +153,8 @@ int main()
else else
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
EndDrawing(); EndDrawing();
} }