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
- from Rev 14 to Rev 15
- ↔ Reverse comparison
Rev 14 → Rev 15
/trunk/BUILD_SCC/synth_src/search_bfs.cpp
30,9 → 30,17
int maxi(int x,int y){ |
return (x>=y)?x:y; |
} |
static AIWEIGHT df_search(Board *b, AIMoves *moves,index_array *index, Player *player, |
int depth, int cache_index, |
PIECE searched, AIWEIGHT alpha, AIWEIGHT beta) |
int mod2(int x){ |
#pragma bitsize x 5 |
int ans[16]={0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}; |
return ans[x]; |
} |
int mod5(int x){ |
#pragma bitsize x 5 |
int ans[16]={0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0}; |
return ans[x]; |
} |
/*static*/ AIWEIGHT df_search(Board *b, AIMoves *moves,/*index_array *index,*/ Player *player,int depth, int cache_index, PIECE searched, AIWEIGHT alpha, AIWEIGHT beta) |
/* Depth is in _moves_ */ |
{ |
#pragma internal_fast index |
44,11 → 52,12
AIMoves moves_next[2][16]; |
#pragma internal_fast moves_next |
AIWEIGHT utility[5][16]; |
#pragma internal_blockram utility |
PIECE turn[5]={b->turn}; |
int branch=player->branch; |
|
board_copy(b, &b_next[0][0]); |
ai_threats(b_next,0,0,moves_next,index); |
ai_threats(b_next,0,0,moves_next/*,index*/); |
utility[0][0]=moves_next[0][0].utility; |
turn[0]=b->turn; |
for(i=0;i<branch;i++){ |
80,8 → 89,10
for(k=0;k<j+1;k++) branches*=branch; |
//int branches=(player->branch)^j; |
//printf("branches %d\n",branches); |
int current_j=j % 2; |
int next_j=(j+1) % 2; |
//int current_j=j % 2; |
//int next_j=(j+1) % 2; |
int current_j=mod2(j); |
int next_j=mod2(j+1); |
if (b_next[current_j][0].moves_left <= 0) turn[j]=other_player(b_next[current_j][0].turn); |
else turn[j]=b_next[current_j][0].turn; |
|
88,7 → 99,8
for (i = 0; i < branches; i++) { |
//if(!(moves_next[j][i>>1].utility==AIW_WIN || moves_next[j][i>>1].utility==-AIW_WIN)){ |
if(!(utility[j][i>>1]==AIW_WIN || utility[j][i>>1]==-AIW_WIN)){ |
AIMove aim = *(moves_next[current_j][i>>1].data + (i % branch)); |
//AIMove aim = *(moves_next[current_j][i>>1].data + (i % branch)); |
AIMove aim = *(moves_next[current_j][i>>1].data + mod2(i)); |
//printf ("aim->utility %d \n",utility[j][i>>1]); |
|
board_copy(&b_next[current_j][i>>1], &b_next[next_j][i]); |
148,7 → 160,7
// return moves->utility; |
//} |
//moves_next = func(b_next); |
ai_threats(b_next,next_j,i,moves_next,index); |
ai_threats(b_next,next_j,i,moves_next/*,index*/); |
utility[j+1][i]=moves_next[next_j][i].utility; |
|
//aim->weight = df_search(&b_next, &moves_next, index,player, |
233,7 → 245,7
moves.len=0; |
Board copy; |
#pragma internal_blockram copy |
index_array index={0}; |
/*index_array index={0};*/ |
#pragma internal_fast index |
//AIFunc move_func = ai(player->ai)->func; |
|
290,11 → 302,11
//ai_threats(©,&moves,&index); |
|
//if (player->search == SEARCH_DFS) { |
df_search(©, &moves, &index,player, player->depth, 0, |
df_search(©, &moves, /*&index,*/player, player->depth, 0, |
PIECE_SEARCHED, AIW_LOSE, AIW_WIN); |
//printf("FINAL WEIGHTS %d %d \n\n",moves.data[0].weight,moves.data[1].weight); |
int ret_val; |
ret_val=aimoves_choose(&moves, move,&index); |
ret_val=aimoves_choose(&moves, move/*,&index*/); |
if (!ret_val) |
return 0; |
else return 1; |
/trunk/BUILD_SCC/synth_src/connect6_synth.cpp
173,7 → 173,7
//#pragma num_iterations(1,2,2) |
//#pragma unroll |
Player player; |
player.depth=4; |
player.depth=2; |
player.branch=2; |
for(i=myboard.moves_left;i>0;i--){ |
//aimoves_free(&moves); |
/trunk/BUILD_SCC/synth_src/threats.cpp
348,7 → 348,7
#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[2][16],int depth,int branch,AIMoves moves[2][16],index_array *index) |
/*AIMoves*/int ai_threats(Board board[2][16],int depth,int branch,AIMoves moves[2][16]/*,index_array *index*/) |
{ |
//#pragma read_write_ports board.data combined 2 |
//#pragma internal_blockram board |
356,6 → 356,7
|
//#pragma internal_blockram move |
//#pragma no_memory_analysis move |
index_array index={0}; |
#pragma internal_fast index |
|
/////////* All threat functions work on this board */ |
532,7 → 533,7
#pragma internal_blockram moves1 |
/*moves = */ ai_marks(&bwrite, PIECE_THREAT(1),&moves1); |
//test(ready); |
streamsort(&moves[depth][branch],index); |
streamsort(&moves[depth][branch],&index); |
moves1.utility = u_sum; |
moves[depth][branch].utility = u_sum; |
/*---------------------------- |
808,7 → 809,7
/* Get all open tiles adjacent to any piece */ |
/*moves =*/ enum_adjacent(b, 1,&moves,current_random); |
if (moves.len){ |
aimoves_choose(&moves, move,&index); |
aimoves_choose(&moves, move/*,&index*/); |
|
return ;//moves; |
} |
/trunk/BUILD_SCC/synth_src/shared.h
348,7 → 348,7
///////////* Add an AIMove to an AIMoves array; existing moves weights will be |
////////// overwritten */ |
////////// |
int aimoves_choose(AIMoves *moves, AIMove *move, index_array *index); |
int aimoves_choose(AIMoves *moves, AIMove *move/*, index_array *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. */ |
463,7 → 463,7
///////////AIMoves *ai_dfs_utility(const Board *b); |
////////////* Utility function */ |
/////////// |
/*AIMoves **/int ai_threats(Board board[2][16],int depth,int branch,AIMoves moves[2][16],index_array *index); |
/*AIMoves **/int ai_threats(Board board[2][16],int depth,int branch,AIMoves moves[2][16]/*,index_array *index*/); |
AIMoves *ai_priority(const Board *b); |
/* Multi-level threats */ |
|
488,4 → 488,5
int depth, branch, cache, tss; |
} Player; |
/*AIMoves **/int search(Board *board,AIMove *move, Player *player); |
AIWEIGHT df_search(Board *b, AIMoves *moves,/*index_array *index,*/ Player *player,int depth, int cache_index,PIECE searched, AIWEIGHT alpha, AIWEIGHT beta); |
#endif |
/trunk/BUILD_SCC/synth_src/util.cpp
31,11 → 31,11
int i; |
// 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]; |
} |
} |
//////////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; |
/trunk/BUILD_SCC/synth_src/state.cpp
213,7 → 213,7
return ((AIMove*)b)->weight - ((AIMove*)a)->weight; |
} |
|
int aimoves_choose(AIMoves *moves, AIMove *move,index_array *index) |
int aimoves_choose(AIMoves *moves, AIMove *move/*,index_array *index*/) |
{ |
//#pragma read_write_ports moves.data combined 3 |
//#pragma internal_blockram moves |
/trunk/BUILD_SCC/synth_src/main.cpp
219,7 → 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 |
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; |
/trunk/BUILD_SCC/synth_src/main.cpp.base
219,7 → 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 |
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; |