// Ramsey.h

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <SFML/Graphics.hpp>

class Ramsey : public sf::Drawable {
    int n; /// dimension of the matrix
    int k; /// number of different characters
    int** M; /// The n by n matrix of 1,2,..,k values
public:
    bool is_valid{1}; //Is the matrix in a valid state?
    bool adjust_n(int offset) {
        // If n+offset < 2 return false: we've under-adjusted.
        // Set is_valid to true since we want to start in a valid state.
        // Delete M (this need to be done for all the subarrays first, and lastly for M itself.)
        // Make the adjustment in n (either up one or down one, depending on offset.) 
		// Allocate enough memory to hold your new array.
		// Initialize all elements of M to 1 (it'll be randomized somewhere else.)
		// If we've reduced n to the point where k > n, then set k down to n.
    }
    bool adjust_k(int offset) {
        // If k+offset < 2 or > n, return false (you don't want that!)
        // Otherwise, set is_valid to true.
		// Make the adjustment in k (either up one or down one, depending on offset.)
		// Initialize all elements of M to 1 (it'll be randomize later.)
    }
    Ramsey() {}; //default constructor
    bool testRamsey(int* M[]) {
        for(int i=0; i < n-1; ++i) // for each row
            for(int j = 0; j < n-1; ++j) //for each column
                for(int k = i+1; k<n; ++k ) //for each subsequent row
                    for(int l = j+1; l<n; ++l)   //each subs. column {
                        /*std::cout << "\nM[" << i << "][" << j << "]=" << M[i][j]
                                  << "\nM[" << i << "][" << l << "]=" << M[i][l]
                                  << "\nM[" << k << "][" << j << "]=" << M[k][j]
                                  << "\nM[" << k << "][" << l << "]=" << M[k][l]
                                  << std::endl;*/
                        if(M[i][j]==M[i][l] &&
                                M[i][l]==M[k][j] &&
                                M[k][j]==M[k][l])
                            return false;
                    }
        return true; // it passes the Ramsey test.
    }
    Ramsey(int en, int kay) : n(en), k(kay)  { //constructor
		// Allocate heap memory for an n by n matrix, M, of int.        
        // Initialized all elements of the M to 1.
    }
    void display() { // For debugging
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j)
                std::cout << M[i][j] << "  ";
            std::cout << '\n';
        }
    }
    void draw(sf::RenderTarget& target, sf::RenderStates states) const; // draw prototype
    void update()     {
        if (is_valid) return; // If it's good, no need to update
        // Otherwise, set all values of M to random numbers between 1 and k, inclusive.
        if(testRamsey(M))   // If we have the Ramsey state, 
        	// then set is_valid is to true
    }
};
void Ramsey::draw(sf::RenderTarget& target, sf::RenderStates states) const {
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            sf::RectangleShape rect(sf::Vector2f(600/n,600/n));
            rect.setPosition(sf::Vector2f(i*600./n,j*600./n));
            rect.setFillColor(sf::Color(255/M[i][j],255/M[i][j],255/M[i][j]));
            target.draw(rect);
        }
    }
}