#include "structs.h"
#include "invdist.h"
#include "circ_order.h"

int compute_co_score(int **distmatrix,struct tNode *treeNode,int first,
		     int *prev,struct genome_struct *genome_list,int num_genes)
{
  int id, score = 0;
  if (treeNode == NULL) return 0;                         
  if (treeNode->leaf == TRUE) {
    id = treeNode->tag;
#ifdef DEBUG
    fprintf(outfile,"ADDING %d and %d\n",*prev,id);
#endif
    score = distmatrix[(*prev)-1][id-1];
    *prev = id;
  }                     
  score += compute_co_score(distmatrix,treeNode->lChild,first,prev,genome_list,num_genes);
  score += compute_co_score(distmatrix,treeNode->rChild,first,prev,genome_list,num_genes);

#ifdef DEBUG
  fprintf(outfile,"SCORE is %d\n",score);
  fprintf(outfile,"FINIS!\n");
#endif
  
  return score;                  
}                                

