#include"List.hpp"

struct Active;
struct Movement;
struct ZeroColor;

struct Vertex:List<Active>{
  Movement*selected;

  void inline operator()(ZeroColor*const z){
    selected=(Movement*)z;
  }
};

struct Potentials;

struct Active:Element<Active,Vertex,Potentials,1>{};

struct Position;

struct Index:List<Position>{};

struct Position:Element<Position,Index,Potentials,2>{
  void inline operator+=(Delta const d){
    operator!(),l+=d,operator~();
  }void inline operator*(){
    operator!(),operator~();
  }
};

struct Height;

struct Heights:List<Height>{};

struct Potential;

struct Potentials:List<Potential>{
  Index*index;
  Active active;
  Position position;

  void inline operator()(Index*const i,Vertex*const v){
    index=i,active(v);
  }void inline operator!(){
    !active,!position;
  }void inline operator~();
};

struct Height:Element<Height,Heights,Movement,0>{
  void inline operator-(){
    --this->l;
  }void inline operator+(){
    ++this->l;
  }void inline operator--(){
    operator!(),operator-(),operator~();
  }void inline operator++(){
    operator!(),operator+(),operator~();
  }
};

struct Potential:Element<Potential,Potentials,Movement,1>{
  void inline operator!(){
    remove();
    if(*l==l->z)!*l;
  }void inline operator~(){
    if(*l==l->z)~*l;
    insert();
  }void inline operator-(){
    --this->l;
  }void inline operator+(){
    ++this->l;
  }void inline operator--(){
    operator!(),operator-(),operator~();
  }void inline operator++(){
    operator!(),operator+(),operator~();
  }
};

struct Movement{
  Height height;
  Potential potential;
  Heights*remove;
  //TODO
  Vertices vertex;
  //TODO

  void inline operator()(Heights*const h,Potentials*const p){
    height(h),potential(p),remove=h,operator~();
  }void inline operator!(){
    !height,!potential;
  }void inline operator~(){
    ~height,~potential;
  }void inline operator-(){
    -height,-potential;
  }void inline operator+(){
    +height,+potential;
  }void inline operator--(){
    --height,--potential;
  }void inline operator++(){
    ++height,++potential;
  }
};

void inline Potentials::operator~(){
  auto const*const s=active.l->selected;
  ~active,position(s->remove-s->height.l+index),~position;
}
//TODO
struct ZeroColor{
  Colors colors=nColors;
  void const*empty0;
  Heights*height=0;

  Score score=0;
  void const*empty1;
  void const*empty2;

  Heights*remove=0;

  void inline operator()(Movement const*const m){
    height=m->height.l,remove=m->remove;
  }
};
//TODO END
