int othello_ai::evaluation(othello16 o_t, int player) { int total_black = o_t.count(BLACK); int total_white = o_t.count(WHITE); std::string map = o_t.tostring(); int value = 0, i, j, num = 0, liberty_value = 0; if (total_black + total_white <= 48 ) { // 前期 for (i = 0; i < MAXEDGE; i ++) { for (j = 0; j < MAXEDGE; j ++) { num = i * MAXEDGE + j; if (map[num] == BLANK + '0') { continue; } value += ( ( o_t.mycolor == map[num] - '0' ) ? 1 : -1 ) * valuemap[i][j]; } } return value; } else if (total_black + total_white <= 192 ) { // 中期 for (i = 0; i < MAXEDGE; i ++) { for (j = 0; j < MAXEDGE; j ++) { num = i * MAXEDGE + j; if (map[num] == BLANK + '0') { continue; } value += ( ( o_t.mycolor == map[num] - '0' ) ? 1 : -1 ) * valuemap[i][j]; } } liberty_value += 4 * o_t.canmove(player) * ((player == o_t.mycolor) ? 1 : -1); return value + liberty_value; } }
int othello_ai::result(othello16 a) { int n1, n2, n3, n4; int num = 0;//棋子个数差 int canput;//可下子差(行动力) int bothputnum; int pos = 0;//布局差 int evaluation = 0; int potential_canput = 0; vector<pair<int, int> > t1 = o.allmove(o.mycolor); vector<pair<int, int> > t2 = o.allmove(3 - o.mycolor); canput = t1.size() - t2.size(); bothputnum = t1.size() + t2.size(); int total; string borad = a.tostring(); num = a.count(a.mycolor) - a.count(3 - a.mycolor);//棋子个数差 total = a.count(a.mycolor) + a.count(3 - a.mycolor); if(bothputnum == 0) { if(num > 0) return 99999; else if(num < 0) return -99999; else return 0; } int i,j,z; for(i = 0 ; i < 16 ; i ++) { for(j = 0 ; j < 16 ; j ++) { char t = borad.at(i * 16 + j); if(t == '0' + a.mycolor) { pos = pos + cost[i][j]; } else if(t == '0' + 3 - a.mycolor) { pos = pos - cost[i][j]; } } } int x[9]; for(i = 0 ; i < 16 ; i ++) { for(j = 0 ; j < 16 ; j ++) { for(z = 0 ; z < 9 ; z ++) { x[z] = i * 16 + j + (z/3 - 1) * 16 + (z%3 - 1); if(x[z] >= 0 && x[z] <= 255) { char t = borad.at(i * 16 + j); char t1 = borad.at(x[z]); if(t1 == '0') { if(t == '0' + a.mycolor) { potential_canput = potential_canput - 1; } else if(t == '0' + 3 - a.mycolor) { potential_canput = potential_canput + 1; } } } } } } if(total < 210) { n1 = 1; n2 = 4; n3 = 3; n4 = 4; } else { n1 = 4; n2 = 2; n3 = 1; n4 = 2; } evaluation =n1 * num + n2 * canput + n3 * pos + n4 * potential_canput; return evaluation; }