Пример #1
0
int stepRB(Board * b) {
    int hitCount = 0;
    Board * c = createBoard(b->size);
    cpyBoard(c,b);
    for(int i = 0; i<c->size; i++) {
        for(int j = 0; j<c->size; j++) {
            if(getBoardVal(c,i,j)=='R'&&getBoardVal(c,i+1,j)==' ') {
                hitCount++;
                setBoardVal(b, i, j, ' ');
                setBoardVal(b, i+1, j, 'R');
            }
        }
    }
    cpyBoard(c,b);
    for(int i = 0; i<c->size; i++) {
        for(int j = 0; j<c->size; j++) {
            if(getBoardVal(c,i,j)=='B'&&getBoardVal(c,i,j+1)==' ') {
                hitCount++;
                setBoardVal(b, i, j, ' ');
                setBoardVal(b, i, j+1, 'B');
            }
        }
    }
    destroyBoard(c);
    return hitCount;
}
Пример #2
0
minimaxRes minimaxPru(gameState* state, int depth, minimaxRes alpha, minimaxRes beta, int isMax){
	char colorOfPlayer = state->turn;
	char colorOfEnemy = BLACK;
	gameState* currState = (gameState*)malloc(sizeof(gameState));
	minimaxRes toRet;
	int index = 0, turn = 1;
	piece** currBoard;
	if (colorOfPlayer == BLACK){
		colorOfEnemy = WHITE;
		turn = -1;
	}
	if (depth == 0){ // End of rec
		toRet.index = 0;
		toRet.value = isMax * turn * scoreOfBoard(state);
		if (toRet.value == 4000)
			toRet.value *= -1;
		free(currState);
		return toRet;
	}
	itemMove* moves = getMoves(state);
	itemMove* head = moves;
	if (&(head->move) == NULL){//Is a leaf
		toRet.index = 0;
		toRet.value = isMax *  turn * scoreOfBoardWith(state, moves);
		if (toRet.value == 4000)
			toRet.value *= -1;
		destroyMoveList(moves);
		free(currState);
		return toRet;
	}
	while (head != NULL){
		if (!isMateWith(state,moves)){
			currBoard = makeMove(state->board, (head));
			copyDtoS(currState->board, currBoard);
			destroyBoard(currBoard);
			currState->turn = colorOfEnemy;
			if (beta.value <= alpha.value){

				break;
			}
			toRet = minimaxPru(currState, depth - 1, alpha, beta, -1 * isMax);
			if (isMax==1)
				replaceMMRs(&alpha, &toRet, isMax, index);
			else
				replaceMMRs(&beta, &toRet, isMax, index);
			head = head->next;
			index++;
		}
	}
	destroyMoveList(moves);
	free(currState);
	if (isMax==1)
		return alpha;
	else
		return beta;
}
Пример #3
0
void GUIBoggleBoard::setBoard(unsigned int rows, unsigned int cols, std::string **list) {
    destroyBoard();
    createBoard(rows, cols);
    //    std::cout<<ROWS<<" "<<COLS<<std::endl;
    for(unsigned int r=0;r<ROWS;r++){
        for(unsigned int c=0;c<COLS;c++){
            this->board[r][c] = list[r][c];
        }
    }
}
Пример #4
0
void BoggleBoard::initRandomBoard() {
  //Random boards are 4x4
  destroyBoard();
  createBoard(4, 4);
  for(unsigned int r=0;r<ROWS;r++)  {
    for(unsigned int c=0;c<COLS;c++)   {
      int index = this->returnIndex(r, c) % this->diceBag.size();
      std::string face = this->diceBag[index]->getRandomFace();
      this->board[r][c] = face;
    }
  }
}
Пример #5
0
void GUIBoggleBoard::initRandomBoard() {
  //Random boards are 4x4
  destroyBoard();
  createBoard(4, 4);
  for(unsigned int r=0;r<ROWS;r++)  {
    for(unsigned int c=0;c<COLS;c++)   {
	  // using modular of index to get one diceBag from 16 diceBag
      int index = this->returnIndex(r, c) % this->diceBag.size();
	  // choose randomly from one of six faces
      std::string face = this->diceBag[index]->getRandomFace();
      this->board[r][c] = face;
    }
  }
}
Пример #6
0
int main()
{
    //setting values
    int numProcessors=3,boardSize=50,tileSize=10,maxDensity=50,maxSteps=10,seed=0,interactive=0;
    //error checking
    if(boardSize%tileSize!=0) {
        printf("Invalid args, b mod t must equal 0\n");
        return 0;
    } else if(numProcessors<1) {
        printf("Invalid args, p must be > 0\n");
        return 0;
    } else if(boardSize<2) {
        printf("Invalid args, b must be > 1\n");
        return 0;
    }

    //Setting up board
    Board * b = createBoard(boardSize);
    randBoard(b, &seed);

    int tileGridSize=sqrt((boardSize*boardSize)/(tileSize*tileSize));

    Tile* (tiles[tileGridSize][tileGridSize]);
    for(int i=0; i<tileGridSize; i++) {
        for(int j=0; j<tileGridSize; j++) {
            tiles[i][j] = (Tile*) calloc(sizeof(Tile), 1);
            tiles[i][j]->x=i*tileSize;
            tiles[i][j]->y=j*tileSize;
        }
    }

    //work loop
    do {
        printBoard(b);
        fgetc(stdin);
    } while(stepRB(b)!=0);

    //cleanup
    for(int i=0; i<tileGridSize; i++) {
        for(int j=0; j<tileGridSize; j++) {
            free(tiles[i][j]);
        }
    }
    destroyBoard(b);
    return 0;
}