OpenCores
URL https://opencores.org/ocsvn/connect-6/connect-6/trunk

Subversion Repositories connect-6

[/] [connect-6/] [trunk/] [BUILD_SCC/] [synth_src/] [state.cpp] - Diff between revs 4 and 7

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 4 Rev 7
Line 25... Line 25...
//#include <glib/gprintf.h>
//#include <glib/gprintf.h>
//#include <stdlib.h>
//#include <stdlib.h>
//#include <stdio.h>
//#include <stdio.h>
//#include <string.h>
//#include <string.h>
//#include <math.h>
//#include <math.h>
#include "./shared.h"
//#include <iostream>
 
#include "shared.h"
 
//#include "q.hpp"
//#include "connectk.h"
//#include "connectk.h"
 
#ifdef PICO_SYNTH
 
//#include "pico.h"
 
#endif
 
//#include "./q.hpp"
 
using namespace std;
/*
/*
 *      Allocation chain
 *      Allocation chain
 */
 */
 
 
#define IA 1103515245u
#define IA 1103515245u
Line 44... Line 50...
//from vpr uti.c code
//from vpr uti.c code
/* Portable random number generator defined below.  Taken from ANSI C by  *
/* Portable random number generator defined below.  Taken from ANSI C by  *
 * K & R.  Not a great generator, but fast, and good enough for my needs. */
 * K & R.  Not a great generator, but fast, and good enough for my needs. */
 
 
 
 
 
//int ready=0;
void my_srandom(int seed,unsigned int *current_random)
void my_srandom(int seed,unsigned int *current_random)
{
{
    *current_random = (unsigned int)seed;
    *current_random = (unsigned int)seed;
}
}
 
 
Line 173... Line 180...
                else
                else
                        moves->data[moves->len++] = *move;
                        moves->data[moves->len++] = *move;
        } else
        } else
                moves->data[i].weight += move->weight;
                moves->data[i].weight += move->weight;
}
}
 
//FIFO(moves_fifo,AIMove);
 
//#pragma fifo_length moves_fifo 361
void aimoves_append(AIMoves *moves, const AIMove *move)
void aimoves_append(AIMoves *moves, const AIMove *move)
{
{
        int i;
        int i;
 
 
        if (move->x >= board_size || move->y >= board_size)
        if (move->x >= board_size || move->y >= board_size)
                return;
                return;
 
        #pragma num_iterations(0,150,361)
        for (i = 0; i < moves->len; i++) {
        for (i = 0; i < moves->len; i++) {
                AIMove *aim = moves->data + i;
                AIMove *aim = moves->data + i;
 
 
                if (aim->x == move->x && aim->y == move->y) {
                if (aim->x == move->x && aim->y == move->y) {
                        aim->weight = move->weight;
                        aim->weight = move->weight;
Line 194... Line 203...
                //g_warning("Attempted to append a move to a full AIMoves");
                //g_warning("Attempted to append a move to a full AIMoves");
                //printf("Attempted to append a move to a full AIMoves");
                //printf("Attempted to append a move to a full AIMoves");
                return;
                return;
        }
        }
        moves->data[moves->len++] = *move;
        moves->data[moves->len++] = *move;
 
        //if(!moves_fifo.full()) moves_fifo.push(*move);
}
}
 
 
int aimoves_compare(const void *a, const void *b)
int aimoves_compare(const void *a, const void *b)
{
{
        return ((AIMove*)b)->weight - ((AIMove*)a)->weight;
        return ((AIMove*)b)->weight - ((AIMove*)a)->weight;
}
}
 
 
int aimoves_choose(AIMoves *moves, AIMove *move)
int aimoves_choose(AIMoves *moves, AIMove *move,unsigned int *index)
{
{
        //#pragma read_write_ports moves.data combined 3
        //#pragma read_write_ports moves.data combined 3
        //#pragma internal_blockram moves
        //#pragma internal_blockram moves
        //#pragma no_memory_analysis moves
        //#pragma no_memory_analysis moves
        int i = 0, top = 0;
 
 
        int i = 0;
 
        int top;
 
        AIMoves moves1;
        #pragma bitsize i 4
        #pragma bitsize i 4
        if (!moves || !moves->len)
      //  if (!moves || !moves->len)
                return 0;
      //          return 0;
        aimoves_sort(moves);
      //  //aimoves_sort(moves);
        for (top = 0; top < moves->len &&
      //  for (top = 0; top < moves->len &&
             moves->data[top].weight == moves->data[0].weight; top++);
      //       moves->data[top].weight == moves->data[0].weight; top++);
        if (top)
      //  if (top)
                //i = my_irand(top,current_random);//g_random_int_range(0, top);
      //          //i = my_irand(top,current_random);//g_random_int_range(0, top);
                i=0;
      //        i=0;
 
      //  
 
      //  *move = moves->data[i];
 
      //  return 1;
 
        /*---------------------------------------
 
                Rewritten for Hardware
 
        ---------------------------------------*/
 
        //for (top = 0; top < moves->len; top++){
 
        //      if(top==0) {
 
        //                       if (!moves)
 
        //                      return 0;
 
        //      }
 
        //      if(moves->data[index[top]].weight != moves->data[index[0]].weight){
 
        //              *move = moves->data[index[i]];
 
        //              return 1;
 
        //      }
 
        //      if(top==moves->len-1) {
 
        //              *move = moves->data[index[i]];
 
        //              return 1;
 
        //      }
 
        //}
 
        //                return 0;
 
        if(!moves|| !moves->len) return 0;
 
        else {*move=moves->data[index[i]];return 1;}
 
 
 
 
        *move = moves->data[i];
 
        return 1;
 
}
}
//
//
//void aimoves_crop(AIMoves *moves, unsigned int n)
//void aimoves_crop(AIMoves *moves, unsigned int n)
//{
//{
//        if (moves->len < n)
//        if (moves->len < n)
Line 387... Line 422...
   int i,j;
   int i,j;
   for(i=0;i<(n-1);i++)
   for(i=0;i<(n-1);i++)
      for(j=0;j<(n-(i+1));j++)
      for(j=0;j<(n-(i+1));j++)
             if(list[j].weight < list[j+1].weight)
             if(list[j].weight < list[j+1].weight)
                    swap(&list[j],&list[j+1]);
                    swap(&list[j],&list[j+1]);
 
                                //cout<<"BUBBLESORT"<<":"<<n<<endl;
 
                                //for(i=0;i<n;i++) cout<<list[i].weight<<",";
 
                                //cout<<endl;
}
}
//taken from http://cprogramminglanguage.net/c-bubble-sort-source-code.aspx
//taken from http://cprogramminglanguage.net/c-bubble-sort-source-code.aspx
void aimoves_sort(AIMoves *moves)
void aimoves_sort(AIMoves *moves)
{
{
        //qsort(moves->data, moves->len, sizeof (AIMove), aimoves_compare);
        //qsort(moves->data, moves->len, sizeof (AIMove), aimoves_compare);
        bublesort(moves->data,moves->len);
        bublesort(moves->data,moves->len);
 
        //streamsort(moves->data,moves->len);
 
 
}
}
 
 
//void aimoves_subtract(AIMoves *m1, const AIMoves *m2)
//void aimoves_subtract(AIMoves *m1, const AIMoves *m2)
//{
//{

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.