Line 6... |
Line 6... |
*/
|
*/
|
|
|
//#include "config.h"
|
//#include "config.h"
|
//#include <string.h>
|
//#include <string.h>
|
//#include <glib.h>
|
//#include <glib.h>
|
|
//#include <iostream>
|
|
#include <stdio.h>
|
#include "./shared.h"
|
#include "./shared.h"
|
#include "pico.h"
|
#include "pico.h"
|
//#include "../connectk.h"
|
//#include "../connectk.h"
|
|
|
/* Variables required to check for cache hits */
|
/* Variables required to check for cache hits */
|
Line 34... |
Line 36... |
return moves->utility;
|
return moves->utility;
|
|
|
/* Alpha-beta sanity check */
|
/* Alpha-beta sanity check */
|
if (alpha >= beta) {
|
if (alpha >= beta) {
|
//g_warning("DFS alpha-beta failed sanity check");
|
//g_warning("DFS alpha-beta failed sanity check");
|
|
//printf("DFS alpha-beta failed sanity check\n");
|
return moves->utility;
|
return moves->utility;
|
}
|
}
|
|
|
/* Search only the top moves beyond the minimum */
|
/* Search only the top moves beyond the minimum */
|
//aimoves_sort(moves);
|
//aimoves_sort(moves);
|
Line 52... |
Line 55... |
if (moves->len < 1)
|
if (moves->len < 1)
|
return AIW_DRAW;
|
return AIW_DRAW;
|
|
|
/* Search each move available in depth first order */
|
/* Search each move available in depth first order */
|
for (i = 0; i < moves->len; i++) {
|
for (i = 0; i < moves->len; i++) {
|
static Board b_next;
|
Board b_next;
|
AIMove *aim = moves->data + i;
|
AIMove *aim = moves->data + i;
|
AIMoves moves_next;
|
AIMoves moves_next;
|
|
|
/* Did we get a bad move? */
|
/* Did we get a bad move? */
|
if (!piece_empty(piece_at(b, aim->x, aim->y))) {
|
if (!piece_empty(piece_at(b, aim->x, aim->y))) {
|
//g_warning("DFS utility function suggested a bad move "
|
//g_warning("DFS utility function suggested a bad move "
|
//"(%s)", bcoords_to_string(aim->x, aim->y));
|
//"(%s)", bcoords_to_string(aim->x, aim->y));
|
|
//printf("bad move\n");
|
continue;
|
continue;
|
}
|
}
|
|
|
/* Already searched here? */
|
/* Already searched here? */
|
if (piece_at(b, aim->x, aim->y) == searched)
|
if (piece_at(b, aim->x, aim->y) == searched)
|
Line 100... |
Line 104... |
//if (!func) {
|
//if (!func) {
|
// g_warning("DFS player has no AI function");
|
// g_warning("DFS player has no AI function");
|
// return moves->utility;
|
// return moves->utility;
|
//}
|
//}
|
//moves_next = func(b_next);
|
//moves_next = func(b_next);
|
|
printf("depth %d branch %d player %d moves_left %d alpha %d MOVE %d %d \n",depth,i,b_next.turn,b_next.moves_left,alpha,aim->y+1,aim->x+1);
|
ai_threats(&b_next,&moves_next,index);
|
ai_threats(&b_next,&moves_next,index);
|
|
|
aim->weight = df_search(&b_next, &moves_next, index,player,
|
aim->weight = df_search(&b_next, &moves_next, index,player,
|
depth - 1, next_ci, searched,
|
depth - 1, next_ci, searched,
|
next_alpha, next_beta);
|
next_alpha, next_beta);
|