/*

g++ -o ga-example-003 -Wall -ansi -pedantic -std=c++11 -O3 ga-example-003.cc

./ga-example-003

*/

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>

#include "ga.hpp"

int main(int argc, char* argv[]) { 
  ga::Blocks blocks;  
  ga::Setup  setup;
  
  ga::make(20,blocks);
  
  // Let us take the blocks one by one, in some random order, and
  // "push" them one by one in the container.

  // This sets a random permutation of indexes.
  std::vector<unsigned int> order;
  order.resize(blocks.size());
  for(unsigned int i=0;i<order.size();++i)
    order[i]=i;
  std::random_shuffle(order.begin(),order.end());
  
  // Let us now push the blocks in a tetris-like manner. The blocks
  // are taken according to the order we have just computed.
  for(auto& block_number : order) {
    double column = ga::random(0,gaWIDTH);
    std::cout << "Pushing block #" << block_number 
	      << " at column " << column << std::endl;
    ga::push(setup,blocks,block_number,column);
  }


  std::ofstream file;
  xfig::open("setup-02.fig",file);
  xfig::draw(file,ga::Position(0,0),
  	     blocks,setup);
  xfig::close(file);
  

  return 0;
}