Line 26... |
Line 26... |
#ifndef EMUL
|
#ifndef EMUL
|
#include "pico.h"
|
#include "pico.h"
|
#endif
|
#endif
|
#include "shared.h"
|
#include "shared.h"
|
|
|
#ifndef EMUL
|
|
// The AI has as much time as it wants, but moves after 1 second. Default is to wait 2 seconds
|
// 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
|
#define AI_WAIT_TIME 0.1
|
|
|
// FPGA has 1 second to make its move
|
// FPGA has 1 second to make its move
|
#define MOVE_TIME_LIMIT 0.1
|
#define MOVE_TIME_LIMIT 0.1
|
#endif
|
|
|
|
#ifdef EMUL
|
|
// 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
|
|
|
|
// FPGA has 1 second to make its move
|
|
#define MOVE_TIME_LIMIT 1
|
|
#endif
|
|
using namespace std;
|
using namespace std;
|
extern "C" int main(int argc, char **argv);
|
extern "C" int main(int argc, char **argv);
|
// commandline option: -port <serialport>
|
// commandline option: -port <serialport>
|
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
//for verification two runs and a reference board
|
//for verification two runs and a reference board
|
Line 132... |
Line 123... |
x = char_to_int(move[2])*10 + char_to_int(move[3]) - 1;
|
x = char_to_int(move[2])*10 + char_to_int(move[3]) - 1;
|
if (check_move_validity(board,y,x) < 0) return 0;
|
if (check_move_validity(board,y,x) < 0) return 0;
|
board[y][x] = FPGA_colour;
|
board[y][x] = FPGA_colour;
|
print_board(board);
|
print_board(board);
|
print_board_file(board);
|
print_board_file(board);
|
#ifdef EMUL
|
|
if(move[0]!=moveportout[0]||move[1]!=moveportout[1]||move[2]!=moveportout[2]||move[3]!=moveportout[3]) {
|
|
printf("EMULATION FAIL: BEHAVIOUR Doesn't match \"%c%c%c%c\" X \"%c%c%c%c\"\n",move[0],move[1],move[2],move[3],moveportout[0],moveportout[1],moveportout[2],moveportout[3]);
|
|
//exit(1);
|
|
}
|
|
#endif
|
|
wait(AI_WAIT_TIME);
|
wait(AI_WAIT_TIME);
|
|
|
|
|
// AI makes a move
|
// AI makes a move
|
connect6ai(board,AI_colour,move);
|
connect6ai(board,AI_colour,move);
|
Line 198... |
Line 183... |
cout<<"FPGA has not completed a move in 1 second. Exiting."<<endl;
|
cout<<"FPGA has not completed a move in 1 second. Exiting."<<endl;
|
break;
|
break;
|
}
|
}
|
y = char_to_int(move[0])*10 + char_to_int(move[1]) - 1;
|
y = char_to_int(move[0])*10 + char_to_int(move[1]) - 1;
|
x = char_to_int(move[2])*10 + char_to_int(move[3]) - 1;
|
x = char_to_int(move[2])*10 + char_to_int(move[3]) - 1;
|
#ifdef EMUL
|
|
if(move[0]!=moveportout[0]||move[1]!=moveportout[1]||move[2]!=moveportout[2]||move[3]!=moveportout[3]) {
|
|
printf("EMULATION FAIL: BEHAVIOUR Doesn't match \"%c%c%c%c\" X \"%c%c%c%c\"\n",move[0],move[1],move[2],move[3],moveportout[0],moveportout[1],moveportout[2],moveportout[3]);
|
|
//exit(1);
|
|
}
|
|
#endif
|
|
if (check_move_validity(board,y,x) < 0) break;
|
if (check_move_validity(board,y,x) < 0) break;
|
board[y][x] = FPGA_colour;
|
board[y][x] = FPGA_colour;
|
winning_colour = check_for_win(board);
|
winning_colour = check_for_win(board);
|
if (winning_colour == AI_colour){
|
if (winning_colour == AI_colour){
|
cout<<"AI has won!" << movecount << " moves " << "Exiting."<<endl;
|
cout<<"AI has won!" << movecount << " moves " << "Exiting."<<endl;
|
Line 239... |
Line 218... |
cout<<"FPGA has not completed a move in 1 second. Exiting."<<endl;
|
cout<<"FPGA has not completed a move in 1 second. Exiting."<<endl;
|
break;
|
break;
|
}
|
}
|
y = char_to_int(move[0])*10 + char_to_int(move[1]) - 1;
|
y = char_to_int(move[0])*10 + char_to_int(move[1]) - 1;
|
x = char_to_int(move[2])*10 + char_to_int(move[3]) - 1;
|
x = char_to_int(move[2])*10 + char_to_int(move[3]) - 1;
|
#ifdef EMUL
|
|
if(move[0]!=moveportout[4]||move[1]!=moveportout[5]||move[2]!=moveportout[6]||move[3]!=moveportout[7]) {
|
|
printf("EMULATION FAIL: BEHAVIOUR Doesn't match \"%c%c%c%c\" X \"%c%c%c%c\"\n",move[0],move[1],move[2],move[3],moveportout[4],moveportout[5],moveportout[6],moveportout[7]);
|
|
//exit(1);
|
|
}
|
|
#endif
|
|
if (check_move_validity(board,y,x) < 0) break;
|
if (check_move_validity(board,y,x) < 0) break;
|
board[y][x] = FPGA_colour;
|
board[y][x] = FPGA_colour;
|
winning_colour = check_for_win(board);
|
winning_colour = check_for_win(board);
|
if (winning_colour == AI_colour){
|
if (winning_colour == AI_colour){
|
cout<<"AI has won! " << movecount << " moves " << "Exiting."<<endl;
|
cout<<"AI has won! " << movecount << " moves " << "Exiting."<<endl;
|