void TScroller::scrollTo( int x, int y )
{
    drawLock++;
    if( hScrollBar != 0 )
        hScrollBar->setValue(x);
    if( vScrollBar != 0 )
        vScrollBar->setValue(y);
    drawLock--;
    checkDraw();
}
Exemple #2
0
	/*checkWinner
	 *Description: Works through each scanning function to find a winner
	 */
	int checkWinner(int grid[column_size][row_size])
	{
		//prorotypes for checkWinner
        int checkHorizontal(int grid[column_size][row_size]), checkVertical(int grid[column_size][row_size]), forwardDiagonal(int grid[column_size][row_size]), backwardDiagonal(int grid[column_size][row_size]), checkDraw(int grid[column_size][row_size]);
      
		int winner; //intialised as default value.
	  
		//works through each test until winner is not 0
		//this saves doing the deeper tests if one of the higher tests is successful at finding a winner.
		winner = checkHorizontal(grid);
			if(winner == 0)
				winner = checkVertical(grid);
				if(winner == 0)
					winner = forwardDiagonal(grid);
					if(winner == 0)
						winner = backwardDiagonal(grid);
						if(winner == 0)
							winner = checkDraw(grid); //will return a 3 if a draw is found.

		return(winner);
    }
void TScroller::setLimit( int x, int y )
{
    limit.x = x;
    limit.y = y;
    drawLock++;
    if( hScrollBar != 0 )
        hScrollBar->setParams( hScrollBar->value,
                               0,
                               x - size.x,
                               size.x-1,
                               hScrollBar->arStep
                             );
    if( vScrollBar != 0 )
        vScrollBar->setParams( vScrollBar->value,
                               0,
                               y - size.y,
                               size.y-1,
                               vScrollBar->arStep
                             );
    drawLock--;
    checkDraw();
}
Exemple #4
0
void TicTacToe::checkGameCondition() {
    if (checkDraw()) {
        ++mDrawCount;
        ui->drawCount->setText(QString("%1").arg(mDrawCount));
        clearGrid();
    }

    else if (checkUserWin()) {
        ++mUserScore;
        ui->userScore->setText(QString("%1").arg(mUserScore));
        clearGrid();
    }

    else {
        computerPlay();
        if(checkComputerWin()) {
            ++mComputerScore;
            ui->computerScore->setText(QString("%1").arg(mComputerScore));
            clearGrid();
        }
    }
}
Exemple #5
0
void
GNEPOI::drawGL(const GUIVisualizationSettings& s) const {
    // check if boundary has to be drawn
    if(s.drawBoundaries) {
        GLHelper::drawBoundary(getCenteringBoundary());
    }
    // first clear vertices
    myPOIVertices.clear();
    // check if POI can be drawn
    if (checkDraw(s)) {
        // push name (needed for getGUIGlObjectsUnderCursor(...)
        glPushName(getGlID());
        // draw inner polygon
        drawInnerPOI(s, drawUsingSelectColor());
        // draw an orange square mode if there is an image(see #4036)
        if (!getShapeImgFile().empty() && OptionsCont::getOptions().getBool("gui-testing")) {
            // Add a draw matrix for drawing logo
            glPushMatrix();
            glTranslated(x(), y(), getType() + 0.01);
            GLHelper::setColor(RGBColor::ORANGE);
            GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
            glPopMatrix();
        }
        // check if dotted contour has to be drawn
        if (myNet->getViewNet()->getDottedAC() == this) {
            if (getShapeImgFile() != DEFAULT_IMG_FILE) {
                const double exaggeration = s.poiSize.getExaggeration(s, this);
                GLHelper::drawShapeDottedContour(getType(), *this, 2 * myHalfImgWidth * exaggeration, 2 * myHalfImgHeight * exaggeration);
            } else if (myPOIVertices.size() > 0) {
                glPushMatrix();
                glTranslated(x(), y(), getType() + 0.01);
                GLHelper::drawShapeDottedContour(getType(), myPOIVertices);
                glPopMatrix();
            }
        }
        // pop name
        glPopName();
    }
}
Exemple #6
0
void game::update() {
    m_isWon = checkWin();
    m_isDraw = checkDraw();
    m_isComplete = (m_isDraw || m_isWon);
    if (!m_isComplete) {
        cout << "Computer: Your move?...\t";
        m_invalidInput = m_b.update(m_currPlayer->getMove(),m_currPlayer->GetIcon());
        while (!m_invalidInput) {
            cout << "Invalid move, please try again: ";
            m_invalidInput = m_b.update(m_currPlayer->getMove(),m_currPlayer->GetIcon());
        }
        switchPlayer();
    }
    else if (m_isWon){
        switchPlayer();
        cout << "You win!!! " <<m_currPlayer->GetName() << " ("<<m_currPlayer->GetIcon() << ")\n"<<endl;
        switchPlayer();
        cout <<m_currPlayer->GetName() << " ("<<m_currPlayer->GetIcon() << ")" << " is defeated."<<endl;
    }
    else if (m_isDraw)
        cout << "\n\n\nIt's a draw" <<endl;
}
Exemple #7
0
//main game loop that get the parameter from multiplayer() above.
void gameLoop(std::pair < unsigned int, std::string> &result,
			  const std::string &playerOne, 
			  const std::string &playerTwo,
			  unsigned int &playerOneScore,
			  unsigned int &playerTwoScore) {
	bool play = true;
	auto gameBoard = initBoard();
	char turn = '1';
	while ( play ) {
		ClearScreen();
		displayBoard(gameBoard,playerOneScore,playerTwoScore,turn);
		if ( turn == '1' ) {
			pickSquare(gameBoard, '1', playerOne);	//user enter move and modify the current gameBoard.
			if ( checkVictory(gameBoard) == true ) {
				playerOneScore++;	
				ClearScreen();
				displayBoard(gameBoard, playerOneScore, playerTwoScore, turn); //display current gameBoard
				std::cout << playerOne << " wins!" << std::endl;
				auto playAgainTemp = playAgain(); //use as temporary value to hold a boolean whether player wants to play again
				if ( playAgainTemp == true ) {
					std::cout << "Swapping turns..." << std::endl;
					delay(1);
					gameBoard = initBoard(); //create a new blank board
					ClearScreen();
					swapTurn(turn); //the other player will start the new game
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				} else if ( playAgainTemp == false ) {	//if the player decides not to continue game after winning,
					result.first = playerOneScore;			//the game will end by returning the current score at the end
					result.second = playerOne;		//of current game to result (pair) for further processing (see
					play = false;						//multiplayer() function above).
				}
			
			} else if ( checkVictory(gameBoard) == false ) {
				if ( checkDraw(gameBoard) == true ) {
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					std::cout << "The game is drawn." << std::endl;
					auto playAgainTemp = playAgain();
					if ( playAgainTemp == true ) {
						std::cout << "Swapping turns..." << std::endl;
						delay(1);
						gameBoard = initBoard();
						ClearScreen();
						swapTurn(turn);
						displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					} else if ( playAgainTemp == false ) {
						play = false;	//when draw, no high score will be recorded
					}
				} else if ( checkDraw(gameBoard) == false ) {
					swapTurn(turn);
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn); // continue to player 2
				}
			}
		}
		if ( turn == '2' ) {							//player 2 loop are exactly the same as player 1(except 
			pickSquare(gameBoard, '2', playerTwo);		//for the parameters that are being passed, which are
			if ( checkVictory(gameBoard) == true ) {	//unique for player 2 for identification purposes
				playerTwoScore++;
				ClearScreen();
				displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				std::cout << playerTwo << " wins!" << std::endl;
				auto playAgainTemp = playAgain();
				if (playAgainTemp == true ) {
					std::cout << "Swapping turns..." << std::endl;
					delay(1);
					gameBoard = initBoard();
					ClearScreen();
					swapTurn(turn);
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				} else if (playAgainTemp == false ) {
					result.first = playerTwoScore;
					result.second = playerTwo;
					play = false;
				}

			} else if ( checkVictory(gameBoard) == false ) {
				if ( checkDraw(gameBoard) == true ) {
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					std::cout << "The game is drawn." << std::endl;
					auto playAgainTemp = playAgain();
					if (playAgainTemp == true ) {
						std::cout << "Swapping turns..." << std::endl;
						delay(1);
						gameBoard = initBoard();
						ClearScreen();
						swapTurn(turn);
						displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
					} else if (playAgainTemp == false ) {
						play = false;
					}
				} else if ( checkDraw(gameBoard) == false ) {
					swapTurn(turn);
					ClearScreen();
					displayBoard(gameBoard, playerOneScore, playerTwoScore, turn);
				}
			}
		}
	}
}
void display() {
/*
	This function is used to display the content on to the screen...
	This is not important for the participant... He can skip it
*/
	int gridDup[6][7],moveDup=move,endGameFlagDup,rowNum;
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	drawGrid(grid);
	if(animate) {
		drawPiece(result,displacement,move);
		if(stopAnimate(grid,result,displacement)) {
			animate=0;
			if(!errorFlag) {
				rowNum=updateGrid(move,grid,result);			//	update the grid implying the move has been made
				drawGrid(grid);
				if(checkWinOrLose(grid,result,rowNum)) {		//	check for win condition
					win=move;					//	win will contain which bot has won
					endGameFlag=1;
				}
				else if(checkDraw(grid)) {				//	check for draw condition
					win=0;						//	win=0 implies draw
					endGameFlag=1;
				}
				move*=-1;						//	toggle between plaper 1 and player 2
			}
		}
	}
	if(errorFlag)									//	If error occurs
		text(displayStr,-1.5,-1.8,font3);
	if(endGameFlag) {								//	If game ends
		if(win>0)				//	player 1 wins
			strcpy(displayStr,"Bot 1 wins!!!");
		else if(win<0)				//	player 2 wins
			strcpy(displayStr,"Bot 2 wins!!!");
		else					//	draw
			strcpy(displayStr,"Game drawn!!!");
		text(displayStr,-1.5,-1.8,font3);
		printf("\n\n\t%s\n\n\t\tgrid content : \n\n",displayStr);
		displayStatus(grid);
	}
	glFlush();
	glutSwapBuffers();
	if(animate)
		displacement+=0.005;
	if(!endGameFlag && !errorFlag && !animate) {
		copyGrid(grid,gridDup);
		moveDup=move;
		endGameFlagDup=endGameFlag;
		if(move>0)
			result=bot1(grid,move);
		else
			result=bot2(grid,move);
		if(!(equalGrid(grid,gridDup) && move==moveDup && endGameFlagDup==endGameFlag)) {	//	grid() and move variables should not be changed
			sprintf(displayStr,"Bot %d error : Grid or move is modified!!!",move);
			errorFlag=1;
		}
		checkForErrors(result,move,grid);			//	errors like result should be within the 0 to 6 range, etc...
		animate=1;
		displacement=0;
	}
}
Exemple #9
0
int Search::search(int depth, int alpha, int beta, _TpvLine *pline, int N_PIECE, int *mateIn) {
    ASSERT_RANGE(depth, 0, MAX_PLY);
    INC(cumulativeMovesCount);
    *mateIn = INT_MAX;
    ASSERT_RANGE(side, 0, 1);
    if (!getRunning()) {
        return 0;
    }
    int score = -_INFINITE;
    /* gtb */
    if (gtb && pline->cmove && maxTimeMillsec > 1000 && gtb->isInstalledPieces(N_PIECE) && depth >= gtb->getProbeDepth()) {
        int v = gtb->getDtm<side, false>(chessboard, (uchar) chessboard[RIGHT_CASTLE_IDX], depth);
        if (abs(v) != INT_MAX) {
            *mateIn = v;
            int res = 0;
            if (v == 0) {
                res = 0;
            } else {
                res = _INFINITE - (abs(v));
                if (v < 0) {
                    res = -res;
                }
            }
            ASSERT_RANGE(res, -_INFINITE, _INFINITE);
            ASSERT(mainDepth >= depth);
            return res;
        }
    }
    u64 oldKey = chessboard[ZOBRISTKEY_IDX];
#ifdef DEBUG_MODE
    double betaEfficiencyCount = 0.0;
#endif
    ASSERT(chessboard[KING_BLACK]);
    ASSERT(chessboard[KING_WHITE]);
    ASSERT(chessboard[KING_BLACK + side]);
    int extension = 0;
    int is_incheck_side = inCheck<side>();
    if (!is_incheck_side && depth != mainDepth) {
        if (checkInsufficientMaterial(N_PIECE)) {
            if (inCheck<side ^ 1>()) {
                return _INFINITE - (mainDepth - depth + 1);
            }
            return -lazyEval<side>() * 2;
        }
        if (checkDraw(chessboard[ZOBRISTKEY_IDX])) {
            return -lazyEval<side>() * 2;
        }
    }
    if (is_incheck_side) {
        extension++;
    }
    depth += extension;
    if (depth == 0) {
        return quiescence<side, smp>(alpha, beta, -1, N_PIECE, 0);
    }

    //************* hash ****************
    u64 zobristKeyR = chessboard[ZOBRISTKEY_IDX] ^_random::RANDSIDE[side];

    _TcheckHash checkHashStruct;

    if (checkHash<Hash::HASH_GREATER, smp>(false, alpha, beta, depth, zobristKeyR, checkHashStruct)) {
        return checkHashStruct.res;
    };
    if (checkHash<Hash::HASH_ALWAYS, smp>(false, alpha, beta, depth, zobristKeyR, checkHashStruct)) {
        return checkHashStruct.res;
    };
    ///********** end hash ***************

    if (!(numMoves & 1023)) {
        setRunning(checkTime());
    }
    ++numMoves;
    ///********* null move ***********
    int n_pieces_side;
    _TpvLine line;
    line.cmove = 0;

    if (!is_incheck_side && !nullSearch && depth >= NULLMOVE_DEPTH && (n_pieces_side = getNpiecesNoPawnNoKing<side>()) >= NULLMOVES_MIN_PIECE) {
        nullSearch = true;
        int nullScore = -search<side ^ 1, smp>(depth - (NULLMOVES_R1 + (depth > (NULLMOVES_R2 + (n_pieces_side < NULLMOVES_R3 ? NULLMOVES_R4 : 0)))) - 1, -beta, -beta + 1, &line, N_PIECE, mateIn);
        nullSearch = false;
        if (nullScore >= beta) {
            INC(nNullMoveCut);
            return nullScore;
        }
    }
    ///******* null move end ********
    /**************Futility Pruning****************/
    /**************Futility Pruning razor at pre-pre-frontier*****/
    bool futilPrune = false;
    int futilScore = 0;
    if (depth <= 3 && !is_incheck_side) {
        int matBalance = lazyEval<side>();
        if ((futilScore = matBalance + FUTIL_MARGIN) <= alpha) {
            if (depth == 3 && (matBalance + RAZOR_MARGIN) <= alpha && getNpiecesNoPawnNoKing<side ^ 1>() > 3) {
                INC(nCutRazor);
                depth--;
            } else
                ///**************Futility Pruning at pre-frontier*****
            if (depth == 2 && (futilScore = matBalance + EXT_FUTILY_MARGIN) <= alpha) {
                futilPrune = true;
                score = futilScore;
            } else
                ///**************Futility Pruning at frontier*****
            if (depth == 1) {
                futilPrune = true;
                score = futilScore;
            }
        }
    }
    /************ end Futility Pruning*************/
    incListId();
    ASSERT_RANGE(KING_BLACK + side, 0, 11);
    ASSERT_RANGE(KING_BLACK + (side ^ 1), 0, 11);
    u64 friends = getBitmap<side>();
    u64 enemies = getBitmap<side ^ 1>();
    if (generateCaptures<side>(enemies, friends)) {
        decListId();
        score = _INFINITE - (mainDepth - depth + 1);
        return score;
    }
    generateMoves<side>(friends | enemies);
    int listcount = getListSize();
    if (!listcount) {
        --listId;
        if (is_incheck_side) {
            return -_INFINITE + (mainDepth - depth + 1);
        } else {
            return -lazyEval<side>() * 2;
        }
    }
    _Tmove *best = nullptr;
    if (checkHashStruct.hashFlag[Hash::HASH_GREATER]) {
        sortHashMoves(listId, checkHashStruct.phasheType[Hash::HASH_GREATER]);
    } else if (checkHashStruct.hashFlag[Hash::HASH_ALWAYS]) {
        sortHashMoves(listId, checkHashStruct.phasheType[Hash::HASH_ALWAYS]);
    }
    INC(totGen);
    _Tmove *move;
    bool checkInCheck = false;
    int countMove = 0;
    char hashf = Hash::hashfALPHA;
    while ((move = getNextMove(&gen_list[listId]))) {
        countMove++;
        INC(betaEfficiencyCount);
        if (!makemove(move, true, checkInCheck)) {
            takeback(move, oldKey, true);
            continue;
        }
        checkInCheck = true;
        if (futilPrune && ((move->type & 0x3) != PROMOTION_MOVE_MASK) && futilScore + PIECES_VALUE[move->capturedPiece] <= alpha && !inCheck<side>()) {
            INC(nCutFp);
            takeback(move, oldKey, true);
            continue;
        }
        //Late Move Reduction
        int val = INT_MAX;
        if (countMove > 4 && !is_incheck_side && depth >= 3 && move->capturedPiece == SQUARE_FREE && move->promotionPiece == NO_PROMOTION) {
            currentPly++;
            val = -search<side ^ 1, smp>(depth - 2, -(alpha + 1), -alpha, &line, N_PIECE, mateIn);
            ASSERT(val != INT_MAX);
            currentPly--;
        }
        if (val > alpha) {
            int doMws = (score > -_INFINITE + MAX_PLY);
            int lwb = max(alpha, score);
            int upb = (doMws ? (lwb + 1) : beta);
            currentPly++;
            val = -search<side ^ 1, smp>(depth - 1, -upb, -lwb, &line, move->capturedPiece == SQUARE_FREE ? N_PIECE : N_PIECE - 1, mateIn);
            ASSERT(val != INT_MAX);
            currentPly--;
            if (doMws && (lwb < val) && (val < beta)) {
                currentPly++;
                val = -search<side ^ 1, smp>(depth - 1, -beta, -val + 1, &line, move->capturedPiece == SQUARE_FREE ? N_PIECE : N_PIECE - 1, mateIn);
                currentPly--;
            }
        }
        score = max(score, val);
        takeback(move, oldKey, true);
        move->score = score;
        if (score > alpha) {
            if (score >= beta) {
                decListId();
                ASSERT(move->score == score);
                INC(nCutAB);
                ADD(betaEfficiency, betaEfficiencyCount / (double) listcount * 100.0);
                ASSERT(checkHashStruct.rootHash[Hash::HASH_GREATER]);
                ASSERT(checkHashStruct.rootHash[Hash::HASH_ALWAYS]);
                recordHash<smp>(getRunning(), checkHashStruct.rootHash, depth - extension, Hash::hashfBETA, zobristKeyR, score, move);
                setKillerHeuristic(move->from, move->to, 0x400);
                return score;
            }
            alpha = score;
            hashf = Hash::hashfEXACT;
            best = move;
            move->score = score;    //used in it
            updatePv(pline, &line, move);
        }
    }
    ASSERT(checkHashStruct.rootHash[Hash::HASH_GREATER]);
    ASSERT(checkHashStruct.rootHash[Hash::HASH_ALWAYS]);
    recordHash<smp>(getRunning(), checkHashStruct.rootHash, depth - extension, hashf, zobristKeyR, score, best);
    decListId();
    return score;
}