URL
https://opencores.org/ocsvn/connect-6/connect-6/trunk
Subversion Repositories connect-6
Compare Revisions
- This comparison shows the changes necessary to convert path
/connect-6/trunk/BUILD_SCC/synth_src
- from Rev 4 to Rev 7
- ↔ Reverse comparison
Rev 4 → Rev 7
/state.cpp
27,9 → 27,15
//#include <stdio.h> |
//#include <string.h> |
//#include <math.h> |
#include "./shared.h" |
//#include <iostream> |
#include "shared.h" |
//#include "q.hpp" |
//#include "connectk.h" |
|
#ifdef PICO_SYNTH |
//#include "pico.h" |
#endif |
//#include "./q.hpp" |
using namespace std; |
/* |
* Allocation chain |
*/ |
46,6 → 52,7
* 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) |
{ |
*current_random = (unsigned int)seed; |
175,7 → 182,8
} else |
moves->data[i].weight += move->weight; |
} |
|
//FIFO(moves_fifo,AIMove); |
//#pragma fifo_length moves_fifo 361 |
void aimoves_append(AIMoves *moves, const AIMove *move) |
{ |
int i; |
182,6 → 190,7
|
if (move->x >= board_size || move->y >= board_size) |
return; |
#pragma num_iterations(0,150,361) |
for (i = 0; i < moves->len; i++) { |
AIMove *aim = moves->data + i; |
|
196,6 → 205,7
return; |
} |
moves->data[moves->len++] = *move; |
//if(!moves_fifo.full()) moves_fifo.push(*move); |
} |
|
int aimoves_compare(const void *a, const void *b) |
203,24 → 213,49
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 internal_blockram moves |
//#pragma no_memory_analysis moves |
int i = 0, top = 0; |
|
int i = 0; |
int top; |
AIMoves moves1; |
#pragma bitsize i 4 |
if (!moves || !moves->len) |
return 0; |
aimoves_sort(moves); |
for (top = 0; top < moves->len && |
moves->data[top].weight == moves->data[0].weight; top++); |
if (top) |
//i = my_irand(top,current_random);//g_random_int_range(0, top); |
i=0; |
|
*move = moves->data[i]; |
return 1; |
// if (!moves || !moves->len) |
// return 0; |
// //aimoves_sort(moves); |
// for (top = 0; top < moves->len && |
// moves->data[top].weight == moves->data[0].weight; top++); |
// if (top) |
// //i = my_irand(top,current_random);//g_random_int_range(0, top); |
// 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;} |
|
|
} |
// |
//void aimoves_crop(AIMoves *moves, unsigned int n) |
389,6 → 424,9
for(j=0;j<(n-(i+1));j++) |
if(list[j].weight < list[j+1].weight) |
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 |
void aimoves_sort(AIMoves *moves) |
395,6 → 433,7
{ |
//qsort(moves->data, moves->len, sizeof (AIMove), aimoves_compare); |
bublesort(moves->data,moves->len); |
//streamsort(moves->data,moves->len); |
|
} |
|
/connect6_synth.cpp
13,7 → 13,9
//#include "connect6.h" |
//#include<stdio.h> |
#include "./shared.h" |
//#include "pico.h" |
//#ifdef PICO_SYSC_SIM |
#include "pico.h" |
//#endif |
|
// Subtract this many points for moves at the edges. |
#define EDGEPENALTY 5 |
108,8 → 110,12
// aimoves_choose(moves, move); |
// } |
//} |
int id; |
int connect6ai_synth(int firstmove,char movein[8], char colour, char moveout[8]){ |
//int id= PICO_initialize_PPA(ai_threats); |
//#ifdef PICO_SYSC_SIM |
//id= PICO_initialize_PPA(ai_threats); |
//PICO_set_task_overlap(id, 2); |
//#endif |
#pragma bitsize firstmove 17 |
char moveoutm[8]; |
#pragma internal_blockram moveoutm |
119,6 → 125,7
//#pragma read_write_ports board.data combined 2 |
//#pragma preserve_array myboard.data |
#pragma internal_blockram myboard |
//#pragma multi_buffer myboard 2 |
//#pragma no_memory_analysis myboard |
static unsigned int current_random = 10; |
AIMove move,move_threat,move_adj; |
163,6 → 170,8
int i; |
#pragma bitsize i 6 |
|
//#pragma num_iterations(1,2,2) |
//#pragma unroll |
for(i=myboard.moves_left;i>0;i--){ |
//aimoves_free(&moves); |
move.x=-1; |
244,7 → 253,10
// /// Convert the int coordinates to corresponding ASCII chars |
//move_to_ascii(move.x+1,move.y+1,&moveout[4]); |
//} |
//#ifdef PICO_SYSC_SIM |
//PICO_sync_task(id, 1); |
//PICO_finalize_PPA(id); |
//#endif |
return 0; |
} |
|
/main.cpp
23,8 → 23,8
#include "util.h" |
#include "connect6.h" |
#include "connect6_synth.h" |
//#include "pico.h" |
//#include "shared.h" |
#include "pico.h" |
#include "shared.h" |
|
// The AI has as much time as it wants, but moves after 1 second. Default is to wait 2 seconds |
#define AI_WAIT_TIME 0.1 |
33,7 → 33,7
#define MOVE_TIME_LIMIT 0.1 |
|
using namespace std; |
|
extern "C" int main(int argc, char **argv); |
// commandline option: -port <serialport> |
int main(int argc, char **argv){ |
//for verification two runs and a reference board |
53,7 → 53,7
// Get software AI's colour |
char AI_colour = select_AI_colour(argc,argv); |
char FPGA_colour; |
//int id = PICO_initialize_PPA(connect6ai_synth); |
int id = PICO_initialize_PPA(connect6ai_synth); |
// Take care of the first few moves (including sending the colour) |
if (AI_colour == 'D'){ |
FPGA_colour = 'L'; |
219,6 → 219,7
connect6ai(board,AI_colour,move); |
movecount++; |
cout<<"AI MOVE: "<<move[0]<<move[1]<<move[2]<<move[3]<<endl; |
//if(movecount >=20) return 0 ; //reducing length of simulation |
winning_colour = check_for_win(board); |
if (winning_colour == AI_colour){ |
cout<<"AI has won! " << movecount << " moves " << "Exiting."<<endl; |
269,7 → 270,7
print_board_file(board); |
} |
|
//PICO_finalize_PPA(id); |
PICO_finalize_PPA(id); |
|
return 0; |
|
/threats.cpp
23,21 → 23,116
//#include "config.h" |
//#include <math.h> |
//#include <glib->h> |
//#include <iostream> |
#include "./shared.h" |
//#include "./q.hpp" |
#include "pico.h" |
//#include <stdio.h> |
|
/* Bits per threat level */ |
#define BITS_PER_THREAT 6 |
|
//FIFO(x,int); |
//#pragma fifo_length x 24 |
//#pragma no_inter_loop_stream_analysis pico_stream_input_x |
//#pragma no_inter_loop_stream_analysis pico_stream_output_x |
//#pragma no_inter_task_stream_analysis pico_stream_input_x |
//#pragma no_inter_task_stream_analysis pico_stream_output_x |
/*--------------------------------------------------------------------*/ |
#ifdef PICO_SYNTH |
#define Q_ASSERT(_cond, _msg) |
//#include <iostream> |
//#include "pico.h" |
//#include "q.hpp" |
//#include "./shared.h" |
using namespace std; |
#else |
/* not synthesizable */ |
#include <iostream> |
#include <sstream> |
#include <string> |
#include <assert.h> |
|
typedef struct { |
int threat[2]; |
PIECE turn[2]; |
} Line; |
typedef struct{ |
int data[MAX_CONNECT_K + 1][2]; |
}threat_count_array; |
static void debug_assert (bool cond, char * msg) { |
if (!cond) { |
printf("assert failed: %s\n", msg); |
assert(0); |
} |
} |
|
#define Q_ASSERT(_cond, _msg) debug_assert(_cond, _msg) |
#endif |
#define max_size 361 |
#define ptr_bw 32 |
//FIFO(queue,AIMove); |
//#pragma no_inter_loop_stream_analysis pico_stream_input_queue |
//#pragma no_inter_loop_stream_analysis pico_stream_output_queue |
//#pragma no_inter_task_stream_analysis pico_stream_input_queue |
//#pragma no_inter_task_stream_analysis pico_stream_output_queue |
|
//FIFO(queue,AIMove); |
//FIFO_INTERFACE(queue,AIMove); |
//#pragma fifo_length pico_stream_input_queue 800 |
//#pragma fifo_length pico_stream_output_queue 800 |
//#pragma read_write_port queue separate |
//#pragma bandwidth pico_stream_input_queue 1 |
//#pragma bandwidth pico_stream_output_queue 1 |
//////template <class tp=AIMove, int max_size=128, int ptr_bw=32> |
//// |
//// /* pop front of queue, returning the front data */ |
//// /* q is corrupted if pop when empty */ |
//// AIMove q::pop (){ |
//// /* assert that before pop, queue is not empty (underflow check) */ |
//// Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)), |
//// "queue underflowed"); |
//// AIMove d = pico_stream_input_queue(); |
//// //cout <<"pop: "<<head<<":"<<tail<<":"<<wrapped<<endl; |
//// if (head == max_size-1) { |
//// head = 0; |
//// wrapped = false; |
//// } else { |
//// head = head + 1; |
//// } |
//// return d; |
//// } |
//// |
//// /* push data into back of queue */ |
//// /* q is corrupted if push when full */ |
//// void q::push (AIMove d){ |
//// pico_stream_output_queue(d); |
//// if (tail == max_size-1) { |
//// tail = 0; |
//// wrapped = true; |
//// } else { |
//// tail = tail + 1; |
//// } |
//// /* assert that after push, queue is not empty (overflow check) */ |
//// Q_ASSERT((!wrapped && (head < tail)) || (wrapped && (head >= tail)), |
//// "Queue overflowed") ; |
//// //cout <<"push: "<<head<<":"<<tail<<":"<<wrapped<<endl; |
//// } |
//// |
//// /* return current size of the queue */ |
//// int q::size (){ |
//// if (wrapped) { |
//// return (max_size - head) + (tail - 0); |
//// } else { |
//// return tail - head; |
//// } |
//// } |
/////*--------------------------------------------------------------------*/ |
////void test(int ready){ |
//// int i; |
//// //for (i=0;i<10;i++) if(ready>1) pico_stream_input_x(); |
//// //for (i=0;i<10;i++) {if(!moves_fifo1.empty()) moves_fifo1.pop(); } |
//// AIMove m; |
//// while(1) { |
//// if(ready>1) m=pico_stream_input_queue(); |
//// if(m.weight==-1) break; |
//// } |
////} |
////q moves_fifo1; |
|
static AIWEIGHT threat_bits(int threat, PIECE type, Board *b) |
/* Bit pack the threat value */ |
{ |
97,7 → 192,8
return 0; |
|
/* Push forward the maximum and find the window type */ |
#pragma unroll |
//#pragma unroll |
//#pragma num_iterations(1,3,6) |
for (maximum = 1; maximum < connect_k; maximum++) { |
p = piece_at(b, x + dx * maximum, y + dy * maximum); |
if (p == PIECE_ERROR) |
113,7 → 209,8
maximum--; |
|
/* Try to push the entire window back */ |
#pragma unroll |
//#pragma unroll |
//#pragma num_iterations(1,3,6) |
for (minimum = -1; minimum > -connect_k; minimum--) { |
p = piece_at(b, x + dx * minimum, y + dy * minimum); |
if (p == PIECE_ERROR || piece_empty(p)) |
135,6 → 232,8
/* Push back minimum if we haven't formed a complete window, this window |
can't be a double */ |
if (maximum - minimum < connect_k - 1) { |
//#pragma unroll |
//#pragma num_iterations(1,3,6) |
for (minimum--; minimum > maximum - connect_k; minimum--) { |
p = piece_at(b, x + dx * minimum, y + dy * minimum); |
if (p == PIECE_ERROR) |
157,7 → 256,7
return 0; |
} |
|
/*static*/ AIWEIGHT threat_line(int x, int y, int dx, int dy,Board *b,Board *bwrite,AIMoves *moves,int k) |
/*static*/ AIWEIGHT threat_line(int x, int y, int dx, int dy,Board *b,Board *bwrite,int k,int loop_bound) |
{ |
|
//#pragma read_write_ports threat_counts.data combined 2 |
165,8 → 264,6
//#pragma no_memory_analysis threat_counts |
|
//#pragma read_write_ports b.data combined 2 |
#pragma internal_blockram b |
#pragma internal_blockram bwrite |
//#pragma read_write_ports b.data separate 1 readonly 2 writeonly |
//#pragma no_memory_analysis b |
/* This is the line of threats currently being processed */ |
245,10 → 342,16
return weight; |
} |
|
FIFO(queue,AIMove); |
//FIFO_INTERFACE(queue,AIMove); |
#pragma fifo_length pico_stream_input_queue 800 |
#pragma fifo_length pico_stream_output_queue 800 |
#pragma bandwidth pico_stream_input_queue 1 |
#pragma bandwidth pico_stream_output_queue 1 |
/*AIMoves*/int ai_threats(Board *board,AIMove *move) |
{ |
//#pragma read_write_ports board.data combined 2 |
#pragma internal_blockram board |
//#pragma internal_blockram board |
//#pragma no_memory_analysis board |
|
//#pragma internal_blockram move |
258,13 → 361,15
/*static*/ Board b;//={0,0,0,0,0,0,0,0,0,0,0,{{0}}} ;//= NULL; |
//#pragma read_write_ports b.data combined 2 |
#pragma internal_blockram b |
//#pragma multi_buffer b 2 |
//#pragma read_write_ports b.data separate 1 readonly 2 writeonly |
//#pragma no_memory_analysis b |
/*static*/ Board bwrite;//={0,0,0,0,0,0,0,0,0,0,0,{{0}}} ;//= NULL; |
//#pragma read_write_ports b.data combined 2 |
#pragma internal_blockram bwrite |
//#pragma multi_buffer bwrite 2 |
//#pragma no_memory_analysis b |
/*static*/ AIMoves moves;//={{0,0,0,{{0,0,0}}}}; |
/*static*/ AIMoves moves;//={0,0,0,{{0,0,0}}}; |
//#pragma read_write_ports moves.data combined 3 |
#pragma internal_blockram moves |
//#pragma no_memory_analysis moves |
306,6 → 411,8
/*---------------------------------------------------------------------------*/ |
//rewritten for hardware |
/*---------------------------------------------------------------------------*/ |
//int id= PICO_initialize_PPA(threat_line); |
//PICO_set_task_overlap(id, 2); |
int j; |
int arg1,arg2,arg3,arg4,loop_bound,loop_begin; |
int k=0; |
408,16 → 515,37
} |
|
|
u_sum += threat_line(arg1, arg2, arg3, arg4,&b,&bwrite,&moves,k); |
u_sum += threat_line(arg1, arg2, arg3, arg4,&b,&bwrite,k,loop_bound); |
} |
} |
//PICO_sync_task(id, 1); |
//PICO_finalize_PPA(id); |
/*---------------------------------------------------------------------------*/ |
//board_copy(&b,&b_marks); |
unsigned int index[max_size]={0}; |
#pragma bitsize index 9 |
#pragma internal_fast index |
AIMoves moves1; |
#pragma internal_blockram moves1 |
/*moves = */ ai_marks(&bwrite, PIECE_THREAT(1),&moves); |
moves.utility = u_sum; |
if (!aimoves_choose(&moves, move)) |
//test(ready); |
streamsort(&moves1,&index[0]); |
//moves1.utility = u_sum; |
//moves.utility = u_sum; |
/*---------------------------- |
rewritten for hardware |
----------------------------*/ |
//if (!aimoves_choose(&moves1, move)) |
// return 0; |
//else return 1; |
int ret_val; |
ret_val=aimoves_choose(&moves1, move,&index[0]); |
if (!ret_val) |
return 0; |
else return 1; |
/*---------------------------- |
end rewritten for hardware |
----------------------------*/ |
//board_free(b); |
//return moves; |
//return 0; |
516,15 → 644,110
//AIMoves moves[361]; |
AIMove move; |
PIECE p; |
//moves_fifo.resoet(); |
AIMove m; |
#pragma num_iterations(19,19,19) |
for (move.y = 0; move.y < board_size; move.y++) |
for (move.x = 0; move.x < board_size; move.x++) |
#pragma num_iterations(19,19,19) |
for (move.x = 0; move.x < board_size; move.x++){ |
if ((p = piece_at(b, move.x, move.y)) >= minimum) { |
move.weight = p - PIECE_THREAT0; |
aimoves_set(moves, &move); |
} |
pico_stream_output_queue(move); |
//cout<<"push"<<move.weight<<endl; |
//ready=ready+1; |
//cout<<"READY"<<*ready<<endl; |
}else { |
m.weight =-100; |
pico_stream_output_queue(m); |
//cout<<"push"<<m.weight<<endl; |
} |
//if((move.y == board_size-1) && (move.x == board_size-1)){ |
// m.weight=-1;m.x=-1;m.y=-1; |
// /*if((ready))*/ {pico_stream_output_queue(m);/*cout<<"push_finish"<<m.weight<<endl;*/} |
// |
//} |
} |
//moves_fifo.active=0; |
//return moves; |
int i; |
//for (i=0;i<10;i++) {*ready=i;pico_stream_output_x(i); } |
//for (i=0;i<10;i++) {if(!moves_fifo1.full()) moves_fifo1.push(m); } |
//for (i=0;i<10;i++) { |
// *ready=i;pico_stream_output_queue(m); |
// if(i==9){ |
// m.weight=-1; |
// pico_stream_output_queue(m); |
// } |
// |
// } |
|
} |
|
void streamsort(AIMoves *moves,unsigned int *index){ |
/* Insertion sort for streaming*/ |
AIMove val; |
AIMove data[361]={{-1},{-1},{-1}}; |
//unsigned int index[361]; |
#pragma bitsize index 9 |
#pragma internal_fast index |
int i,j,k; |
unsigned int len=0; |
moves->data[0].weight=-100; |
// while(1) { |
// if(!moves_fifo.empty()){ |
// val=moves_fifo.pop(); |
// for(i=0;i<len;i++){ |
// if (list[i].weight < val.weight){ |
// for(j=len-1;j>i-1;j--){ |
// list[j+1]=list[j]; |
// } |
// break; |
// } |
// } |
// list[i]=val; |
// len++; |
// } |
// else break; |
// //if(!moves_fifo.active && moves_fifo.empty()) break; |
// } |
//while(1) { |
//int count=0; |
#pragma num_iterations(1,150,1362) |
for(k=0;k<1362;k++){ |
//count++; |
//cout<<count<<endl; |
if (k>1000){ |
|
//if(ready>5){ |
val=pico_stream_input_queue(); |
//cout<<"popped"<<","<<val.weight<<" "<<val.x<<" "<<val.y<<endl; |
if(val.weight==-1) {moves->len=len;break;} |
else if(val.weight==-100) continue; |
#pragma num_iterations(0,150,361) |
for(i=0;i<len;i++){ |
if (moves->data[index[i]].weight < val.weight){ |
for(j=len-1;j>i-1;j--){ |
//moves->data[j+1]=moves->data[j]; |
index[j+1]=index[j]; |
} |
break; |
} |
} |
index[i]=len; |
moves->data[len]=val; |
len++; |
//cout<<"STREAMSORT"<<":"; |
//} |
/*else*/ //{moves->len=len;break;} |
} |
} |
moves->len=len; |
//cout<<"STREAMSORT"<<":"<<moves->len<<endl; |
//for(i=0;i<len;i++) cout<<moves->data[i].weight<<","; |
//cout<<endl; |
//for(i=0;i<len;i++) cout<<moves->data[index[i]].weight<<","; |
//cout<<endl; |
} |
static gboolean is_adjacent( Board *b, BCOORD x, BCOORD y, int dist) |
{ |
int dx, dy, count; |
551,10 → 774,14
|
move.weight = AIW_NONE; |
//moves = aimoves_new(); |
for (move.y = 0; move.y < board_size; move.y++) |
for (move.x = 0; move.x < board_size; move.x++) |
#pragma num_iterations(1,9,19) |
for (move.y = 0; move.y < board_size; move.y++){ |
#pragma num_iterations(1,9,19) |
for (move.x = 0; move.x < board_size; move.x++){ |
if (is_adjacent(b, move.x, move.y, dist)) |
aimoves_append(moves, &move); |
} |
} |
//aimoves_shuffle(moves,current_random); |
//return moves; |
} |
572,12 → 799,13
//#pragma internal_blockram moves |
//#pragma no_memory_analysis moves |
//AIMove move; |
unsigned int index[1]={0}; |
//AIMoves *moves; |
moves.len=0; |
/* Get all open tiles adjacent to any piece */ |
/*moves =*/ enum_adjacent(b, 1,&moves,current_random); |
if (moves.len){ |
aimoves_choose(&moves, move); |
aimoves_choose(&moves, move,&index[0]); |
|
return ;//moves; |
} |
/shared.h
1,4 → 1,5
|
#ifndef SHARED_H |
#define SHARED_H |
/* |
|
connectk -- a program to play the connect-k family of games |
23,7 → 24,7
//#ifndef TRUE |
#define TRUE 1 |
#define FALSE 0 |
#define NULL ((void*)0) |
//#define NULL ((void*)0) |
//#endif |
//#ifndef __G_TYPES_H__ |
typedef unsigned int gboolean; |
30,6 → 31,7
#pragma bitsize gboolean 1 |
typedef int gsize; |
//#endif |
#include "pico.h" |
|
|
/* |
304,6 → 306,22
} AIMoves; |
/* An array type for holding move lists */ |
|
|
typedef struct { |
int threat[2]; |
PIECE turn[2]; |
} Line; |
typedef struct{ |
int data[MAX_CONNECT_K + 1][2]; |
}threat_count_array; |
|
|
|
|
|
|
|
|
AllocChain *aimoves_alloc(AllocChain *data); |
#define aimoves_new() ((AIMoves*)achain_new(&aimoves_root, aimoves_alloc)) |
//#define aimoves_free(m) achain_free((AllocChain*)(m)) |
325,7 → 343,7
///////////* Add an AIMove to an AIMoves array; existing moves weights will be |
////////// overwritten */ |
////////// |
int aimoves_choose(AIMoves *moves, AIMove *move); |
int aimoves_choose(AIMoves *moves, AIMove *move, unsigned int *index); |
/* Will choose one of the best moves from a GArray of AIMove structures at |
random. Returns non-zero if a move was chosen or zero if a move could not |
be chosen for some reason. */ |
400,6 → 418,7
/*AIMoves **/ void enum_adjacent(Board *b, int dist,AIMoves *moves,unsigned int current_random); |
/* Enumerate empty tiles at most dist away from some other piece on the board */ |
|
void streamsort(AIMoves *moves,unsigned int *index); |
/*AIMoves **/void ai_marks(Board *b, PIECE min,AIMoves *moves); |
/* Fills a moves list with tiles marked at least PIECE_THREAT(min) */ |
|
448,7 → 467,14
void my_srandom(int seed,unsigned int *current_random); |
int my_irand(int imax,unsigned int current_random); |
//void backup_move(Board *board, AIMoves *moves,AIMove *move); |
AIWEIGHT threat_line(int x, int y, int dx, int dy,Board *b,Board *bwrite,AIMoves *moves,int k); |
int threat_window(int x, int y, int dx, int dy, |
PIECE *ptype, int *pdouble,Board *b); |
//AIWEIGHT threat_line(int x, int y, int dx, int dy,Board *b,Board *bwrite,int k,int loop_bound); |
//int threat_window(int x, int y, int dx, int dy, |
// PIECE *ptype, int *pdouble,Board *b); |
int connect6ai_synth(int firstmove,char movein[8], char colour, char moveout[8]); |
//extern "C" AIMove pico_stream_input_queue(); |
//extern "C" void pico_stream_output_queue(AIMove); |
//extern "C" AIMove pico_ips_fifo_read_queue(); |
//extern "C" void pico_ips_fifo_write_queue(AIMove); |
//extern int id; |
//extern int ready; |
#endif |
/main.cpp.base
23,8 → 23,8
#include "util.h" |
#include "connect6.h" |
#include "connect6_synth.h" |
//#include "pico.h" |
//#include "shared.h" |
#include "pico.h" |
#include "shared.h" |
|
// The AI has as much time as it wants, but moves after 1 second. Default is to wait 2 seconds |
#define AI_WAIT_TIME 0.1 |
33,7 → 33,7
#define MOVE_TIME_LIMIT 0.1 |
|
using namespace std; |
|
extern "C" int main(int argc, char **argv); |
// commandline option: -port <serialport> |
int main(int argc, char **argv){ |
//for verification two runs and a reference board |
53,7 → 53,7
// Get software AI's colour |
char AI_colour = select_AI_colour(argc,argv); |
char FPGA_colour; |
//int id = PICO_initialize_PPA(\TCAB_NAME); |
int id = PICO_initialize_PPA(connect6ai_synth); |
// Take care of the first few moves (including sending the colour) |
if (AI_colour == 'D'){ |
FPGA_colour = 'L'; |
219,6 → 219,7
connect6ai(board,AI_colour,move); |
movecount++; |
cout<<"AI MOVE: "<<move[0]<<move[1]<<move[2]<<move[3]<<endl; |
if(movecount >=20) return 0 ; //reducing length of simulation |
winning_colour = check_for_win(board); |
if (winning_colour == AI_colour){ |
cout<<"AI has won! " << movecount << " moves " << "Exiting."<<endl; |
269,7 → 270,7
print_board_file(board); |
} |
|
//PICO_finalize_PPA(id); |
PICO_finalize_PPA(id); |
|
return 0; |
|
/util.cpp
27,22 → 27,22
|
|
char select_AI_colour (int argc, char **argv){ |
char ai_colour; |
char ai_colour='L'; |
int i; |
//cout<<"Please enter referee AI's colour. L or D"<<endl; |
//cin >> ai_colour; |
for(i=0;i<argc; i++){ |
if((strcmp(argv[i],"-player")==0) && (i< (argc+1)) ){ |
ai_colour= *argv[i+1]; |
} |
} |
// cout<<"Please enter referee AI's colour. L or D"<<endl; |
// cin >> ai_colour; |
// for(i=0;i<argc; i++){ |
// if((strncmp(argv[i],"-player",7)==0) && (i< (argc+1)) ){ |
// ai_colour= *argv[i+1]; |
// } |
// } |
|
while (ai_colour != 'L' && ai_colour != 'D'){ |
cout<<"Invalid colour. Single character L or D"<<endl; |
cin >> ai_colour; |
} |
// while (ai_colour != 'L' && ai_colour != 'D'){ |
// cout<<"Invalid colour. Single character L or D"<<endl; |
// cin >> ai_colour; |
// } |
|
cout<<"AI is playing as "<<ai_colour<<endl; |
// cout<<"AI is playing as "<<ai_colour<<endl; |
return ai_colour; |
} |
|
54,7 → 54,7
bool cmd_line_port_set = false; |
|
for(i=0;i<argc; i++){ |
if((strcmp(argv[i],"-port")==0) && (i< (argc+1)) ){ |
if((strncmp(argv[i],"-port",5)==0) && (i< (argc+1)) ){ |
com_port = argv[i+1]; |
cmd_line_port_set = true; |
} |