int DrawBoardGui(UINode* node, char** error)
{
	int i, j;
	for (j = (BOARD_SIZE - 1); j >= 0; j--)
	{
		for (i = 0; i < BOARD_SIZE; i++){
			char* fileName = ResolveFileNameFromLetter(board[i][j]);
			char* name = ResolveNameFromLetter(board[i][j]);

			if (fileName != NULL){
				control* chessPiece_control;
				if (-1 == Create_panel_from_bmp(
					fileName,
					name,
					MARGIN + i * SQUARE_W,
					(BOARD_H - MARGIN - (j + 1)*SQUARE_W),
					(Uint16)SQUARE_W,
					(Uint16)SQUARE_H,
					&chessPiece_control,
					error))
				{
					return -1;
				}

				UINode* chessPiece_node;
				if (-1 == CreateAndAddNodeToTree(chessPiece_control, node, &chessPiece_node, error))
				{
					FreeControl(chessPiece_control);
					return -1;
				}
			}
		}
	}
	return 0;
}
Пример #2
0
int buildBoardUITree(char** error)
{
	control* board_control;
	if (-1 == Create_panel_from_bmp(
		CHESSBOARDFILENAME,
		CHESSBOARDNAME,
		0,
		0,
		(Uint16)BOARD_W,
		(Uint16)BOARD_H,
		&board_control,
		error))
	{
		return -1;
	}
	if (-1 == CreateAndAddNodeToTree(board_control, tree, &board_node, error))
	{
		FreeControl(board_control);
		return -1;
	}

	if (-1 == DrawSquareButtons(board_node, &GameBoardSquare_ButtonClick, error))
	{
		return -1;
	}

	if (-1 == DrawBoardGui(board_node, error))
	{
		return -1;
	}
	return 0;
}
Пример #3
0
void FreeTree(UINode* node)
{
	if (node == NULL)
	{
		free(node);
		return;
	}

	if (node->children != NULL){
		for (int i = 0; i < node->childrenCount; i++)
		{
			FreeTree(node->children[i]);
		}
	}
	FreeControl(node->control);
	node->control = NULL;

	free(node->children);
	node->children = NULL;

	node->childrenCount = 0;
	node->childrenSize = 0;
	node->father = NULL;
	node->root = NULL;
	
	free(node);
}
int  DrawPiecesOnSidePanelFilterColor(UINode* panel_node, ButtonAction FuncPtr, COLOR c, char** error)
{
	char* Pieces = "mrnbq";
	if (c == BLACK)
	{
		Pieces = "MRNBQ";
	}

	for (int i = 0; i < 6; i++)
	{
		char* fileName = ResolveFileNameFromLetter(Pieces[i]);
		char* name = ResolveNameFromLetter(Pieces[i]);

		if (fileName == NULL){
			if (Pieces[i] == ' ') {
				fileName = DELETE_FILENAME;
				name = DELETE_NAME;
			}
		}

		if (fileName != NULL){
			control* chessPiece_control;
			if (-1 == Create_Button_from_bmp_transHighlight(
				fileName,
				SQUAREBUTTONHIGHLIGHTEDFILENAME,
				name,
				(Sint16)(BOARD_W + MARGIN + (i % 2) * SQUARE_W),
				(Sint16)(0.5 * MARGIN + (i / 2) * SQUARE_H),
				(Uint16)SQUARE_W,
				(Uint16)SQUARE_H,
				FuncPtr,
				&chessPiece_control,
				error))
			{
				return -1;
			}
			UINode* chessPiece_node;
			if (-1 == CreateAndAddNodeToTree(chessPiece_control, panel_node, &chessPiece_node, error))
			{
				FreeControl(chessPiece_control);
				return -1;
			}
			if (-1 == AddToListeners(chessPiece_control, error))
			{
				return -1;
			}
		}
	}
	return 0;

}
int DrawPiecesOnSidePanel(UINode* panel_node, ButtonAction FuncPtr, char** error)
{
	char* Pieces = "mMrRnNbBqQkK";
	for (int i = 0; i < 13; i++)
	{
		char* fileName = ResolveFileNameFromLetter(Pieces[i]);
		char* name = ResolveNameFromLetter(Pieces[i]);

		if (fileName == NULL){
			if (Pieces[i] == ' ') {
				fileName = DELETE_FILENAME;
				name = DELETE_NAME;
			}
		}

		if (fileName != NULL){
			control* chessPiece_control;
			if (-1 == Create_Button_from_bmp_transHighlight(
				fileName,
				SQUAREBUTTONHIGHLIGHTEDFILENAME,
				name,
				(Sint16)(GAMEBOARDBACKGROUND_W - 160 - SQUARE_W - 13 + (i % 2) * (SQUARE_W + 22)),
				(Sint16)(0.5 * MARGIN + (i / 2) * SQUARE_H),
				(Uint16)SQUARE_W,
				(Uint16)SQUARE_H,
				FuncPtr,
				&chessPiece_control,
				error))
			{
				return -1;
			}
			UINode* chessPiece_node;
			if (-1 == CreateAndAddNodeToTree(chessPiece_control, panel_node, &chessPiece_node, error))
			{
				FreeControl(chessPiece_control);
				return-1;
			}
			if (-1 == AddToListeners(chessPiece_control, error))
			{
				return-1;
			}
		}
	}
	return 0;

}
int DrawSquareButtons(UINode* node, ButtonAction FuncPtr, char** error)
{
	if (-1 == initializeButtonsBoard(error))
	{
		return -1;
	}

	for (int i = 0; i < BOARD_SIZE; i++)
	{
		for (int j = 0; j < BOARD_SIZE; j++)
		{
			control* square;
			if (-1 == Create_Button_from_bmp(
				SQUAREBUTTONFILENAME,
				SQUAREBUTTONHIGHLIGHTEDFILENAME,
				SQUAREBUTTONNAME,
				MARGIN + (i*SQUARE_W),
				MARGIN + (j*SQUARE_H),
				(Uint16)SQUARE_W,
				(Uint16)SQUARE_H,
				FuncPtr,
				&square,
				error))
			{
				FreeButtonsBoard();
				return -1;
			}
			UINode* square_node;
			if (-1 == CreateAndAddNodeToTree(square, node, &square_node, error))
			{
				FreeButtonsBoard();
				FreeControl(square);
				return -1;
			}
			if (-1 == AddToListeners(square, error))
			{
				FreeTree(square_node);
				FreeButtonsBoard();
				return -1;
			}
			buttonsBoard[i][j] = square;
		}
	}
	return 0;
}
Пример #7
0
void
DeleteConnection(Connection *conn)
{
    MemPool *mpool = conn->co_MemPool;

    if (conn->co_Desc->d_Type == THREAD_SPOOL) {
	conn->co_LastServerLog = 1;
	LogServerInfo(conn, TFd);
    } else if (conn->co_Desc->d_Type == THREAD_NNTP) {
	char statbuf[1024];
	char vsbuf[11];
	char hsbuf[31];

	snprintf(vsbuf, sizeof(vsbuf), "%s", conn->co_Auth.dr_VServerDef->vs_Name);

	snprintf(hsbuf, sizeof(hsbuf), "%s%s%s%s%s",
		*conn->co_Auth.dr_AuthUser ? conn->co_Auth.dr_AuthUser : "",
		*conn->co_Auth.dr_AuthUser ? "/" : "",
		*conn->co_Auth.dr_IdentUser ? conn->co_Auth.dr_IdentUser : "",
		*conn->co_Auth.dr_IdentUser ? "@" : "",
		conn->co_Auth.dr_Host);
	RTStatusBase(conn->co_Desc->d_Slot, "CLSD %-10s %-30s", vsbuf, hsbuf);

	GroupStats(conn);

	snprintf(statbuf, sizeof(statbuf), "exit articles %lu groups %lu posts %lu bytes %.0f", conn->co_ClientTotalArticleCount, conn->co_ClientGroupCount, conn->co_ClientPostCount, conn->co_ClientTotalByteCount);
	LogCmd(conn, '$', statbuf);

	StatusUpdate(conn, "(closed)");
	freeReaderSlot(conn->co_Desc->d_Slot);
	--NumReaders;
	/*
	 * Inform the main server that we are done with the descriptor
	 * by writing the DnsRes structure back to it, so the main server
	 * can track who from where is connecting to what and when that
	 * connection terminates.
	 */
	conn->co_Auth.dr_ByteCount = conn->co_TMBuf.mh_TotalBytes;
	SendMsg(TFd, conn->co_Desc->d_Fd, &conn->co_Auth);
    }

    FreeControl(conn);
    freePool(&conn->co_BufPool);
    freePool(&mpool);		/* includes Connection structure itself */
}
Пример #8
0
void Game()
{
	check = false;

	FreeTree(tree);
	if (NULL != buttonsBoard){
		FreeButtonsBoard();
	}
	if (-1 == EventHandler_init(&Quit, &error_global))
	{
		guiQuit = -1;
		return;
	}

	chosenMove = NULL;

	gameSelectedSquare_control = NULL;

	showDepthOptions = false;

	get_moves_for_color(board, curSettings->next_turn, &curMovesList);

	CheckGameOver();

	control* window;
	if (-1 == Create_window(GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &window, &error_global))
	{
		guiQuit = -1;
		return;
	}


	if (-1 == CreateTree(window, &tree, &error_global))
	{
		FreeControl(window);
		guiQuit = -1;
		return;
	}


	control* gameBoarBackground_control;
	if (-1 == Create_panel_from_bmp(
		GAMEBOARDBACKGROUNDFILENAME,
		GAMEBOARDBACKGROUNDNAME,
		0,
		0,
		(Uint16)GAMEBOARDBACKGROUND_W,
		(Uint16)GAMEBOARDBACKGROUND_H,
		&gameBoarBackground_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* gameBoarBackground_node;
	if (-1 == CreateAndAddNodeToTree(gameBoarBackground_control, tree, &gameBoarBackground_node, &error_global))
	{
		FreeControl(gameBoarBackground_control);
		guiQuit = -1;
		return;
	}

	if (-1 == buildBoardUITree(&error_global))
	{
		guiQuit = -1;
		return;
	}

	Sint16 quitButton_x_location = (Sint16)(GAMEBOARDBACKGROUND_W - BUTTON_W - 0.5 * MARGIN);
	Sint16 quitButton_y_location = (Sint16)(GAMEBOARDBACKGROUND_H - BUTTON_H - 1.5 * MARGIN);
	control* quitButton_control;
	if (-1 == Create_Button_from_bmp(
		BUTTONQUITFILENAME,
		BUTTONQUITFILENAME,
		BUTTONQUITNAME,
		quitButton_x_location,
		quitButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&Quit_ButtonClick,
		&quitButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* quitButton_node;
	if (-1 == CreateAndAddNodeToTree(quitButton_control, gameBoarBackground_node, &quitButton_node, &error_global))
	{
		FreeControl(quitButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(quitButton_control, &error_global))
	{
		FreeControl(quitButton_control);
		guiQuit = -1;
		return;
	}


	Sint16 bestButton_x_location = quitButton_x_location;
	Sint16 bestButton_y_location = (Sint16)(quitButton_y_location - BUTTON_H - 1.5 * MARGIN);
	control* bestButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONBESTMOVEFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONBESTMOVENAME,
		bestButton_x_location,
		bestButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&GameBoardBest_ButtonClick,
		&bestButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* bestButton_node;
	if (-1 == CreateAndAddNodeToTree(bestButton_control, gameBoarBackground_node, &bestButton_node, &error_global))
	{
		FreeControl(bestButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(bestButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	int saveButton_x_location = quitButton_x_location;
	int saveButton_y_location = 2 * MARGIN;
	control* saveButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONSAVEFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONSAVENAME,
		saveButton_x_location,
		saveButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&GameBoardSave_ButtonClick,
		&saveButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}

	UINode* saveButton_node;
	if (-1 == CreateAndAddNodeToTree(saveButton_control, gameBoarBackground_node, &saveButton_node, &error_global))
	{
		FreeControl(saveButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(saveButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}


	Sint16 mainMenuButton_x_location = (Sint16)(quitButton_x_location);
	Sint16 mainMenuButton_y_location = (Sint16)(saveButton_y_location + BUTTON_H + 1.5 *MARGIN);
	control* mainMenuButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONMAINMENUFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONMAINMENUNAME,
		mainMenuButton_x_location,
		mainMenuButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&GameBoardMainMenu_ButtonClick,
		&mainMenuButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* mainMenuButton_node;
	if (-1 == CreateAndAddNodeToTree(mainMenuButton_control, gameBoarBackground_node, &mainMenuButton_node, &error_global))
	{
		FreeControl(mainMenuButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(mainMenuButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	if (check)
	{

		char* filename = NULL;
		char* name = NULL;

		if (curSettings->next_turn == WHITE)
		{
			filename = LABELBLACKCHECKFILENAME;
			name = LABELBLACKCHECKNAME;
		}
		else
		{
			filename = LABELWHITECHECKFILENAME;
			name = LABELWHITECHECKNAME;
		}

		int checkLabel_x_location = mainMenuButton_x_location;
		int checkabel_y_location = mainMenuButton_y_location + BUTTON_H + MARGIN;

		control* checkLabel_control;
		if (-1 == Create_panel_from_bmp(
			filename,
			name,
			checkLabel_x_location,
			checkabel_y_location,
			GAMEBOARDBACKGROUND_W,
			GAMEBOARDBACKGROUND_H, &checkLabel_control, &error_global))
		{
			guiQuit = -1;
			return;
		}
		UINode* checkLabel_node;
		if (-1 == CreateAndAddNodeToTree(checkLabel_control, gameBoarBackground_node, &checkLabel_node, &error_global))
		{
			FreeControl(checkLabel_control);
			guiQuit = -1;
			return;
		}
	}

	if (gameOver)
	{
		Sint16 checkMateLabel_x_location = 0;
		Sint16 checkMateLabel_y_location = (Sint16)(0.25 * BOARD_H - 20);
		control* checkMateLabel_control;
		if (-1 == Create_panel_from_bmp(
			LABELCHECKMATEFILENAME,
			LABELCHECKMATENAME,
			checkMateLabel_x_location,
			checkMateLabel_y_location,
			GAMEBOARDBACKGROUND_W,
			GAMEBOARDBACKGROUND_H,
			&checkMateLabel_control,
			&error_global))
		{
			guiQuit = -1;
			return;
		}

		UINode* checkMateLabel_node;
		if (-1 == CreateAndAddNodeToTree(checkMateLabel_control, board_node, &checkMateLabel_node, &error_global))
		{
			FreeControl(checkMateLabel_control);
			guiQuit = -1;
			return;
		}

		char* filename = NULL;
		char* name = NULL;

		if (curSettings->next_turn == WHITE)
		{
			filename = LABELBLACKWINSFILENAME;
			name = LABELBLACKWINSNAME;
		}
		else
		{
			filename = LABELWHITEWINSFILENAME;
			name = LABELWHITEWINSNAME;
		}

		Sint16 winsLabel_x_location = 0;
		Sint16 winsLabel_y_location = (Sint16)(0.5 * BOARD_H - 20);
		control* winsLabel_control;
		if (-1 == Create_panel_from_bmp(
			filename,
			name,
			winsLabel_x_location,
			winsLabel_y_location,
			GAMEBOARDBACKGROUND_W,
			GAMEBOARDBACKGROUND_H,
			&winsLabel_control,
			&error_global))
		{
			guiQuit = -1;
			return;
		}
		UINode* winsLabel_node;
		if (-1 == CreateAndAddNodeToTree(winsLabel_control, board_node, &winsLabel_node, &error_global))
		{
			FreeControl(winsLabel_control);
			guiQuit = -1;
			return;
		}
	}
	else if (tie)
	{
		Sint16 tieLabel_x_location = 0;
		Sint16 tieLabel_y_location = (Sint16)(0.25 * BOARD_H - 20);
		control* tieLabel_control;
		if (-1 == Create_panel_from_bmp(
			LABELTIEFILENAME,
			LABELTIENAME,
			tieLabel_x_location,
			tieLabel_y_location,
			GAMEBOARDBACKGROUND_W,
			GAMEBOARDBACKGROUND_H,
			&tieLabel_control,
			&error_global))
		{
			guiQuit = -1;
			return;
		}
		UINode* tieLabel_node;
		if (-1 == CreateAndAddNodeToTree(tieLabel_control, board_node, &tieLabel_node, &error_global))
		{
			FreeControl(tieLabel_control);
			guiQuit = -1;
			return;
		}

		Sint16 gameOverLabel_x_location = 0;
		Sint16 gameOverLabel_y_location = (Sint16)(0.50 * BOARD_H - 20);
		control* gameOverLabel_control;
		if (-1 == Create_panel_from_bmp(
			LABELGAMEOVERFILENAME,
			LABELGAMEOVERNAME,
			gameOverLabel_x_location,
			gameOverLabel_y_location,
			GAMEBOARDBACKGROUND_W,
			GAMEBOARDBACKGROUND_H,
			&gameOverLabel_control,
			&error_global))
		{
			guiQuit = -1;
			return;
		}
		UINode* gameOverLabel_node;
		if (-1 == CreateAndAddNodeToTree(gameOverLabel_control, board_node, &gameOverLabel_node, &error_global))
		{
			FreeControl(gameOverLabel_control);
			guiQuit = -1;
			return;
		}
	}



	// DrawTree
	if (-1 == FlipTree(&error_global))
	{
		guiQuit = -1;
		return;
	}



	if (PLAYER_VS_AI_GAME_MODE == curSettings->game_mode && curSettings->next_turn != curSettings->user_color)
	{
		ComputerTurn(&error_global);
	}
}
Пример #9
0
void GameBoardBest_ButtonClick(control * input)
{
	if (gameOver == 0){
		if (showDepthOptions == false){
			showDepthOptions = true;
			input->ishighlighted = 1;
		}
		else
		{
			showDepthOptions = false;
			input->ishighlighted = 0;
		}
		if (showDepthOptions){
			if (curSettings->game_mode == TWO_PLAYERS_GAME_MODE){


				UINode* gameBoarBackground_node = tree->children[0];
				int oneButton_x_location = (Sint16)(BOARD_W + 0.5 * MARGIN);
				int oneButton_y_location = (Sint16)(BOARD_H *0.5 + 0.5 * NUMBUTTON_H);

				control* oneButton_control;
				if (-1 == Create_Button_from_bmp_transHighlight(
					BUTTON1FILENAME,
					NUMBUTTONHIGHLIGHTEDFILENAME,
					BUTTON1NAME,
					oneButton_x_location,
					oneButton_y_location,
					(Uint16)NUMBUTTON_W,
					(Uint16)NUMBUTTON_H,
					&GameMinimaxDepth_ButtonClick,
					&oneButton_control,
					&error_global))
				{
					guiQuit = -1;
					return;
				}
				UINode* oneButton_node;
				if (-1 == CreateAndAddNodeToTree(oneButton_control, gameBoarBackground_node, &oneButton_node, &error_global))
				{
					FreeControl(oneButton_control);
					guiQuit = -1;
					return;
				}
				if (-1 == AddToListeners(oneButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}


				Sint16 twoButton_x_location = (Sint16)(oneButton_x_location + NUMBUTTON_W + 0.5 * MARGIN);
				Sint16 twoButton_y_location = (Sint16)(oneButton_y_location);

				control* twoButton_control;
				if (-1 == Create_Button_from_bmp_transHighlight(
					BUTTON2FILENAME,
					NUMBUTTONHIGHLIGHTEDFILENAME,
					BUTTON2NAME,
					twoButton_x_location,
					twoButton_y_location,
					(Uint16)NUMBUTTON_W,
					(Uint16)NUMBUTTON_H,
					&GameMinimaxDepth_ButtonClick,
					&twoButton_control,
					&error_global))
				{
					guiQuit = -1;
					return;
				}
				UINode* twoButton_node;
				if (-1 == CreateAndAddNodeToTree(twoButton_control, gameBoarBackground_node, &twoButton_node, &error_global))
				{
					FreeControl(twoButton_control);
					guiQuit = -1;
					return;
				}
				if (-1 == AddToListeners(twoButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}


				Sint16 threeButton_x_location = (Sint16)(twoButton_x_location + NUMBUTTON_W + 0.5 * MARGIN);
				Sint16 threeButton_y_location = (Sint16)(oneButton_y_location);

				control* threeButton_control;
				if (-1 == Create_Button_from_bmp_transHighlight(
					BUTTON3FILENAME,
					NUMBUTTONHIGHLIGHTEDFILENAME,
					BUTTON3NAME,
					threeButton_x_location,
					threeButton_y_location,
					(Uint16)NUMBUTTON_W,
					(Uint16)NUMBUTTON_H,
					&GameMinimaxDepth_ButtonClick,
					&threeButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}
				UINode* threeButton_node;
				if (-1 == CreateAndAddNodeToTree(threeButton_control, gameBoarBackground_node, &threeButton_node, &error_global))
				{
					FreeControl(threeButton_control);
					guiQuit = -1;
					return;
				}
				if (-1 == AddToListeners(threeButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}

				Sint16 fourButton_x_location = (Sint16)(threeButton_x_location + NUMBUTTON_W + 0.5 * MARGIN);
				Sint16 fourButton_y_location = (Sint16)(oneButton_y_location);
				control* fourButton_control;
				if (-1 == Create_Button_from_bmp_transHighlight(
					BUTTON4FILENAME,
					NUMBUTTONHIGHLIGHTEDFILENAME,
					BUTTON4NAME,
					fourButton_x_location,
					fourButton_y_location,
					(Uint16)NUMBUTTON_W,
					(Uint16)NUMBUTTON_H,
					&GameMinimaxDepth_ButtonClick,
					&fourButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}
				UINode* fourButton_node;
				if (-1 == CreateAndAddNodeToTree(fourButton_control, gameBoarBackground_node, &fourButton_node, &error_global))
				{
					FreeControl(fourButton_control);
					guiQuit = -1;
					return;
				}
				if (-1 == AddToListeners(fourButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}

				Sint16 bestButton_x_location = (Sint16)(fourButton_x_location + NUMBUTTON_W + 0.5 *MARGIN);
				Sint16 bestButton_y_location = (Sint16)(oneButton_y_location);
				control* bestButton_control;
				if (-1 == Create_Button_from_bmp_transHighlight(
					BUTTONBESTFILENAME,
					BUTTONBESTHIGHLIGHTFILENAME,
					BUTTONBESTNAME,
					bestButton_x_location,
					bestButton_y_location,
					(Uint16)NUMBUTTON_W,
					(Uint16)NUMBUTTON_H,
					&GameMinimaxDepth_ButtonClick, &bestButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}
				UINode* bestButton_node;
				if (-1 == CreateAndAddNodeToTree(bestButton_control, gameBoarBackground_node, &bestButton_node, &error_global))
				{
					FreeControl(bestButton_control);
					guiQuit = -1;
					return;
				}
				if (-1 == AddToListeners(bestButton_control, &error_global))
				{
					guiQuit = -1;
					return;
				}

				switch (curSettings->minimax_depth){
				case 1:
					oneButton_control->ishighlighted = 1;
					break;
				case 2:
					twoButton_control->ishighlighted = 1;
					break;
				case 3:
					threeButton_control->ishighlighted = 1;
					break;
				case 4:
					fourButton_control->ishighlighted = 1;
					break;
				case MAX_MINIMAX_DEPTH_POSSIBLE:
					bestButton_control->ishighlighted = 1;
					break;
				}
			}

			if (-1 == HighlightBestMove(BLINKNUM, &error_global))
			{
				guiQuit = -1;
				return;
			}

			// DrawTree
			if (-1 == FlipTree(&error_global))
			{
				guiQuit = -1;
				return;
			}
		}
		else
		{
			Game();
		}
	}
}
Пример #10
0
int HighlightBestMove(int blinknum, char** error)
{
	struct move_list* best_move_list = NULL;
	int number_of_boards_evaluated = 0;

	// Get the best next move
	int current_move_grade = get_best_moves(curSettings->minimax_depth, board, curSettings->next_turn, curMovesList, &best_move_list, &number_of_boards_evaluated);

	// Check for errors
	if (FAILED_ERROR == current_move_grade) {
		free_move_list(best_move_list);
		return -1;
	}

	move bestMove = best_move_list->mov;
	position startPos = bestMove.start_pos;
	position endPos = bestMove.end_pos;

	control* startSquare = buttonsBoard[(int)startPos.col][7 - (int)startPos.row];
	control* endSquare = buttonsBoard[(int)endPos.col][7 - (int)endPos.row];

	bool startHiglighted = startSquare->ishighlighted;
	bool endHiglighted = endSquare->ishighlighted;

	startSquare->ishighlighted = 1;
	endSquare->ishighlighted = 1;

	for (int i = 0; i < blinknum; i++){
		SwitchButtonHighlight(startSquare);
		SwitchButtonHighlight(endSquare);

		if (isPawnUpgradePossible(&bestMove, get_piece(board, startPos)))
		{
			char* fileName = ResolveFileNameFromLetter(bestMove.new_disc);
			char* name = ResolveNameFromLetter(bestMove.new_disc);

			if (fileName != NULL){
				control* chessPiece_control;
				if (-1 == Create_panel_from_bmp(
					fileName,
					name,
					(Sint16)(GAMEBOARDBACKGROUND_W - BUTTON_W - MARGIN),
					(Sint16)(0.5*BOARD_H - SQUARE_H - 0.5),
					(Uint16)SQUARE_W,
					(Uint16)SQUARE_H,
					&chessPiece_control, error))
				{
					return -1;
				}
				UINode* chessPiece_node;
				if (-1 == CreateAndAddNodeToTree(chessPiece_control, tree->children[0], &chessPiece_node, error))
				{
					FreeControl(chessPiece_control);
					return -1;
				}
			}
		}

		// DrawTree
		if (-1 == FlipTree(error))
		{
			return -1;
		}
		SDL_Delay(250);
	}



	startSquare->ishighlighted = startHiglighted;
	endSquare->ishighlighted = endHiglighted;

	free_move_list(best_move_list);
	return 0;
}
Пример #11
0
void DeleteControl ( int iControlID )
{
	// Delete control
	FreeControl ( g_pGlob->hWnd, iControlID );
}
Пример #12
0
void SettingMenu()
{
	FreeTree(tree);
	if (-1 == EventHandler_init(&Quit, &error_global))
	{
		guiQuit = -1;
		return;
	}

	control* window;
	if (-1 == Create_window(GAMESETTING_W, GAMESETTING_H, &window, &error_global))
	{
		guiQuit = -1;
		return;
	}
	if (-1 == CreateTree(window, &tree, &error_global))
	{
		FreeControl(window);
		guiQuit = -1;
		return;
	}

	// Drawing all controls

	control* gameSettingBackground_control;
	if(-1 ==Create_panel_from_bmp(
		GAMESETTINGFILENAME,
		GAMESETTINGNAME,
		0,
		0,
		(Uint16)GAMESETTING_W,
		(Uint16)GAMESETTING_H,
		&gameSettingBackground_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* gameSettingBackground_node;
	if (-1 == CreateAndAddNodeToTree(gameSettingBackground_control, tree, &gameSettingBackground_node, &error_global))
	{
		FreeControl(gameSettingBackground_control);
		guiQuit = -1;
		return;
	}

	int pvpButtonn_x_location = 285;
	int pvpButton_y_location = 45;
	control* pvpButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONPVPFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONPVPNAME,
		pvpButtonn_x_location,
		pvpButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&ChooseMode_ButtonClick,
		&pvpButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}

	UINode* pvpButton_node;
	if (-1 == CreateAndAddNodeToTree(pvpButton_control, gameSettingBackground_node, &pvpButton_node, &error_global))
	{
		FreeControl(pvpButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(pvpButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	int pvcButtonn_x_location = pvpButtonn_x_location + BUTTON_W + MARGIN;//227
	int pvcButton_y_location = pvpButton_y_location;
	control* pvcButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONPVCFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONPVCNAME,
		pvcButtonn_x_location,
		pvcButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&ChooseMode_ButtonClick,
		&pvcButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* pvcButton_node;
	if (-1 == CreateAndAddNodeToTree(pvcButton_control, gameSettingBackground_node, &pvcButton_node, &error_global))
	{
		FreeControl(pvcButton_control);
		guiQuit = -1;
		return;
	}

	if (-1 == AddToListeners(pvcButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	int setPiecesButton_x_location = pvpButtonn_x_location;
	int setPiecesButton_y_location = 133;

	control* setPiecesButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONSETPIECESFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONSETPIECESNAME,
		setPiecesButton_x_location,
		setPiecesButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&SetPiece_ButtonClick,
		&setPiecesButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* setPiecesButton_node;
	if (-1 == CreateAndAddNodeToTree(setPiecesButton_control, gameSettingBackground_node, &setPiecesButton_node, &error_global))
	{
		FreeControl(setPiecesButton_control);
		guiQuit = -1;
		return;
	}

	if (-1 == AddToListeners(setPiecesButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	int whiteButton_x_location = pvpButtonn_x_location;
	int whiteButton_y_location = 222;
	control* whiteButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONWHITEFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONWHITENAME,
		whiteButton_x_location,
		whiteButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&NextPlayer_ButtonClick,
		&whiteButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* whiteButton_node;
	if (-1 == CreateAndAddNodeToTree(whiteButton_control, gameSettingBackground_node, &whiteButton_node, &error_global))
	{
		FreeControl(whiteButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(whiteButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	int blackButton_x_location = pvcButtonn_x_location;
	int blackButton_y_location = 222;
	control* blackButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONBLACKFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONBLACKNAME,
		blackButton_x_location,
		blackButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&NextPlayer_ButtonClick,
		&blackButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* blackButton_node;
	if (-1 == CreateAndAddNodeToTree(blackButton_control, gameSettingBackground_node, &blackButton_node, &error_global))
	{
		FreeControl(blackButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(blackButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}


	int cancelButton_x_location = 44;
	int cancelButton_y_location = 398;
	control* cancelButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONCANCELFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONCANCELNAME,
		cancelButton_x_location,
		cancelButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&GameSettingsCancel_ButtonClick,
		&cancelButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* cancelButton_node;
	if (-1 == CreateAndAddNodeToTree(cancelButton_control, gameSettingBackground_node, &cancelButton_node, &error_global))
	{
		FreeControl(cancelButton_control); 
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(cancelButton_control, &error_global))
	{
		guiQuit = -1;
		return;
	}

	int nextButton_x_location = cancelButton_x_location;
	int nextButton_y_location = 474;
	control* nextButton_control;
	if (-1 == Create_Button_from_bmp_transHighlight(
		BUTTONNEXTFILENAME,
		BUTTONTRANSPARENTHIGHLIGHTEDFILENAME,
		BUTTONNEXTNAME,
		nextButton_x_location,
		nextButton_y_location,
		(Uint16)BUTTON_W,
		(Uint16)BUTTON_H,
		&GameSettingsNext_ButtonClick,
		&nextButton_control,
		&error_global))
	{
		guiQuit = -1;
		return;
	}
	UINode* nextButton_node;
	if (-1 == CreateAndAddNodeToTree(nextButton_control, gameSettingBackground_node, &nextButton_node, &error_global))
	{
		FreeControl(nextButton_control);
		guiQuit = -1;
		return;
	}
	if (-1 == AddToListeners(nextButton_control, &error_global))
	{
		guiQuit = -1;;
		return;
	}

	if (curSettings->game_mode == TWO_PLAYERS_GAME_MODE)
	{
		pvpButton_control->ishighlighted = 1;
	}
	else
	{
		pvcButton_control->ishighlighted = 1;
	}

	if (curSettings->next_turn == WHITE)
	{
		whiteButton_control->ishighlighted = 1;
	}
	else
	{
		blackButton_control->ishighlighted = 1;
	}

	if (1 == setPieces)
	{
		setPiecesButton_control->ishighlighted = 1;
	}

	// DrawTree
	if (-1 == FlipTree(&error_global))
	{
		guiQuit = -1;
		return;
	}
}