aboutsummaryrefslogtreecommitdiff
path: root/main/puzzle/neo/neo.cpp
blob: 56d90f744630ab27447ba99d96af82095e1d2447 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <array>

#define MATRIX_SIZE 8

enum NeoState {
    NEO_UNINITIALIZED,
    NEO_PLAYING,
    NEO_SOLVED
};

// Simulate the 8x8 LED matrix with a 2D array
std::array<std::array<bool, MATRIX_SIZE>, MATRIX_SIZE> neoMatrix;

NeoState neoState = NEO_UNINITIALIZED;

// Helper function to toggle LEDs if within bounds
void toggleIfValid(int x, int y) {
    if (x >= 0 && x < MATRIX_SIZE && y >= 0 && y < MATRIX_SIZE) {
        neoMatrix[x][y] = !neoMatrix[x][y];
    }
}

void initializeNeoMatrix() {
    // The initial pattern from the Appendix A example (assuming red is 'true'/on and white is 'false'/off)
    std::array<std::array<bool, MATRIX_SIZE>, MATRIX_SIZE> initialPattern = {{
        {false, true, false, true, false, true, false, true},
        {true, false, true, false, true, false, true, false},
        {false, true, false, true, false, true, false, true},
        {true, false, true, false, true, false, true, false},
        {false, true, false, true, false, true, false, true},
        {true, false, true, false, true, false, true, false},
        {false, true, false, true, false, true, false, true},
        {true, false, true, false, true, false, true, false}
    }};

    for (int i = 0; i < MATRIX_SIZE; i++) {
        for (int j = 0; j < MATRIX_SIZE; j++) {
            neoMatrix[i][j] = initialPattern[i][j];
        }
    }

    neoState = NEO_PLAYING;
}


void printNeoMatrix() {
    // Print the matrix state to the console
    for (int i = 0; i < MATRIX_SIZE; i++) {
        for (int j = 0; j < MATRIX_SIZE; j++) {
            std::cout << (neoMatrix[i][j] ? 1 : 0) << " ";
        }
        std::cout << std::endl;
    }
}

void toggleAdjacentLEDs(int x, int y) {
    // Toggle the LED at (x, y) and adjacent LEDs
    toggleIfValid(x, y);     // Center
    toggleIfValid(x - 1, y); // Up
    toggleIfValid(x + 1, y); // Down
    toggleIfValid(x, y - 1); // Left
    toggleIfValid(x, y + 1); // Right
}


bool isNeoPuzzleSolved() {
    for (int i = 0; i < MATRIX_SIZE; i++) {
        for (int j = 0; j < MATRIX_SIZE; j++) {
            if (neoMatrix[i][j]) return false; // If any LED is on, puzzle is not solved
        }
    }
    return true;
}

/// Integration needed
int main() {
    initializeNeoMatrix();
    printNeoMatrix();

    while (neoState != NEO_SOLVED) {
        int x, y;
        std::cout << "Enter the coordinates of the button pressed (x y): ";
        std::cin >> x >> y;

        if (x >= 0 && x < MATRIX_SIZE && y >= 0 && y < MATRIX_SIZE) {
            toggleAdjacentLEDs(x, y);
            printNeoMatrix();

            if (isNeoPuzzleSolved()) {
                neoState = NEO_SOLVED;
                std::cout << "The NeoTrellis puzzle is solved!\n";
            }
        } else {
            std::cout << "Invalid coordinates. Please enter values between 0 and " << MATRIX_SIZE - 1 << ".\n";
        }
    }

    return 0;
}