#include "RandomAnalysis.h" RandomAnalysis::RandomAnalysis() { RandomAnalysis(hex_board(), VERT); } RandomAnalysis::RandomAnalysis(hex_board theBoard) { RandomAnalysis(theBoard, VERT); } RandomAnalysis::RandomAnalysis(hex_board theBoard, occupantType side) { this->theBoard = theBoard; this->side = side; SIZE = theBoard.SIZE; total = theBoard.numberOfEmpties(); moves = (int) (total + 1)/2; available = MoveList(total); choices = MoveList(moves); } void RandomAnalysis::setuplists() { int i,j; int counter = 0; Move here; for(i=0; i0) { randomPercent = rand()/(RAND_MAX+1.0); ; index = (int) (tempTotal*randomPercent); here = tempAvailable.move(index); theBoard.doIt(here, VERT); tempAvailable.remove(index); choices.add(here); tempTotal--; tempMoves--; } } void RandomAnalysis::refresh() { int i,j; Move here; int tempMoves = choices.getLength(); //Here we unplay all of the random moves from fillup. for(i=0;i best) { best = eval; result = here; } //Refresh the move tested. theBoard.doIt(here, EMPTY); available.add(here); } cout << "Best Move: " << result.hex.y << "-" << result.hex.x <<"\n"; cout << "Best: " << best << "\n"; return result; } double RandomAnalysis::value() { double eval=0; int i; int move_test; move_test = MAX_TEST; // if (move_test > (2^(total - 2))) move_test = (int) (2^(total - 2) + 1) for(i=0; i < move_test; i++) { fillup(); //Play random moves. //Test for a vertical win. //The evaluation is the probability of a win. if (theBoard.isWon(side)) { eval++; } refresh(); } eval = eval/move_test; return eval; }