Move MyBot::play(const OthelloBoard& board) {
	ourTurn = turn;
	store.clear();
	threadSuccessfull = false;
	if (!strtGame) {
		pthread_join(RGThread, NULL);
		getPrevMove(board);
		setPlyDepth();
		if(OpponentMoveDone){
			pos = getIndex();
			if(pos <= threadDone && pos != -1)
				threadSuccessfull = true;
		}
	}
	else if (ourTurn == BLACK) {
		strtGame = false;
		--gameMovesDone;
		setPlyDepth();
		PrevBoard = OthelloBoard(board);
		list<Move> moveLst = PrevBoard.getValidMoves(ourTurn);
		list<Move>::iterator it = moveLst.begin();
		int randNo = (rand() % 4);
		for (int i = 0; i < randNo - 1; ++it, ++i);

		FinalMove.x = it->x, FinalMove.y = it->y;
		PrevBoard.makeMove(ourTurn, FinalMove);
		++gameMovesDone;
		/* Initializing the thread to RG opponenet before returning the move */
		RGThreadStatus = pthread_create(&RGThread, NULL, threadFunc, (void*)NULL);

		return FinalMove;
	}
	strtGame = false;
	PrevBoard = OthelloBoard(board);
	Node* root = new Node(PrevBoard, ourTurn);
	if(!shallowDepthDone)
		shallowDepth(root);
	alphabetaMiniMax(root, 0, MIN_NUM, MAX_NUM, 0);
	PrevBoard.makeMove(ourTurn, FinalMove);
	++gameMovesDone;
	/* Initializing the thread to RG opponenet before returning the move */
	RGThreadStatus = pthread_create(&RGThread, NULL, threadFunc, (void*)NULL);

	return FinalMove;
}
Exemple #2
0
Move MyBot::play(const OthelloBoard& board )
{
    list<Move> moves = board.getValidMoves( turn );
    if(moves.size()==0)
        return Move::pass();
    OthelloBoard b;
    list<Move>::iterator it;
    int currbest = POSLARGE;
    Move *cm = 0;
    bool firstRun = true;
    int val;
    priority_queue<MovePair> pq;

    for(it=moves.begin(); it!=moves.end(); it++){
        b = board;
        b.makeMove(turn,*it);
        int score = weights[it->x][it->y];
        MovePair *tempm = new MovePair(&(*it), score);
        pq.push(*tempm);
    }
    

    while(!pq.empty()){
        Move* m = pq.top().m;
        pq.pop();
        b = board;
        b.makeMove(turn,*m);
        val = alphaBeta(other(turn), b, NEGLARGE, val, PLY);
        if(val<currbest || firstRun){
            currbest = val;
            cm = m;
            firstRun = false;
        }
    }
    if(cm==0) cout<<"cm is null!!"<<endl<<moves.size()<<endl;
	return *cm;

}
Exemple #3
-1
/*Function to calculate 2 levels of Moves*/
void* threadFunc(void* ptr){
	int i, j;
	shallowDepthDone = false;
	threadDone = threadDone2 = -1;
	memset(thread2Done,false, sizeof(thread2Done));
	Turn otherTurn = other(ourTurn);
	immediateSucc = PrevBoard.getValidMoves(otherTurn);
	list<Move>::iterator it, kj;
	OthelloBoard saveBoard = PrevBoard;

	for(i = 0, it = immediateSucc.begin(); it != immediateSucc.end(); ++it, ++i){
		PrevBoard.makeMove(otherTurn, *it);
		moveLst1[i] = PrevBoard.getValidMoves(ourTurn);
		PrevBoard = saveBoard;
		++threadDone;
	}

	for(i = 0, kj = immediateSucc.begin() ; kj != immediateSucc.end(); ++kj, ++i ){
		PrevBoard.makeMove(otherTurn, *kj);
		OthelloBoard saveBoard1 = PrevBoard;
		for( j = 0, it = moveLst1[i].begin(); it != moveLst1[i].end(); ++it, ++j){
			PrevBoard.makeMove(ourTurn, *it);
			moveLst2[i][j] = PrevBoard.getValidMoves(otherTurn);
			PrevBoard = saveBoard1;
		}
		thread2Done[i] = true;
		++threadDone2;
		PrevBoard = saveBoard;
	}
	return NULL;
}