Beispiel #1
0
float check_parity(UINT64 blank, UINT32 color)
{
	int p;

	p = CountBit(blank & 0x0f0f0f0f) % 2;
	p |= (CountBit(blank & 0xf0f0f0f0) % 2) << 1;
	p |= (CountBit(blank & 0x0f0f0f0f00000000) % 2) << 2;
	p |= (CountBit(blank & 0xf0f0f0f000000000) % 2) << 3;

	return parity[p];
}
Beispiel #2
0
int RandomMove(BitBoard moves)
{
	int move;
	int move_cnt = rand()%CountBit(moves);
	int pos;

	while(1)
	{
		pos = CountBit((moves & (-(signed long long int)moves)) - 1);
		if(move_cnt == 0)
		{
			move = pos;
			break;
		}
		else
		{
			move_cnt--;
		}
		moves &= moves - 1;
	}
	return move;
}
Beispiel #3
0
/**
* @brief Get the final score.
*
* Get the final score, when no move can be made.
*
* @param board Board.
* @param n_empties Number of empty squares remaining on the board.
* @return The final score, as a disc difference.
*/
INT32 GetExactScore(UINT64 bk, UINT64 wh, INT32 empty)
{
	const int n_discs_p = CountBit(bk);
	const int n_discs_o = 64 - empty - n_discs_p;

#ifdef LOSSGAME
	int score = n_discs_o - n_discs_p;
#else
	int score = n_discs_p - n_discs_o;
#endif
	if (score < 0) score -= empty;
	else if (score > 0) score += empty;

	return score;
}
Beispiel #4
0
		bool f(int x)
		{
			if(x==-1)	return true;
			else if(x==N)	m[x]=alp-1;
			else m[x]=m[x+1]-1;
		met:
			if(m[x]<x)	return false;
			if(masconf[m[x]]&maskconf
				|| CountBit(seet[x]=seet[x+1] | masconf[m[x]])>N+1 
				|| !f(x-1))
			{
				m[x]--;
				goto met;
			}
			return true;
		}
Beispiel #5
0
/**
* @brief Get the final score.
*
* Get the final score, when no move can be made.
*
* @param board Board.
* @param n_empties Number of empty squares remaining on the board.
* @return The final score, as a disc difference.
*/
INT32 GetWinLossScore(UINT64 bk, UINT64 wh, INT32 empty)
{
	int score;
	const int n_discs_p = CountBit(bk);
	const int n_discs_o = 64 - empty - n_discs_p;

#ifdef LOSSGAME
	if (n_discs_p < n_discs_o)
	{
		score = WIN;
	}
	else if (n_discs_p > n_discs_o)
	{
		score = LOSS;
	}
	else
	{
		score = DRAW;
	}

	return score;
#else

	if (n_discs_p > n_discs_o)
	{
		score = WIN;
	}
	else if (n_discs_p < n_discs_o)
	{
		score = LOSS;
	}
	else
	{
		score = DRAW;
	}

	return score;
#endif

}
Beispiel #6
0
//
//  関数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的:  メイン ウィンドウのメッセージを処理します。
//
//  WM_COMMAND	- アプリケーション メニューの処理
//  WM_PAINT	- メイン ウィンドウの描画
//  WM_DESTROY	- 中止メッセージを表示して戻る
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	static HWND boardWnd, hBut[2];       // レバーコントロールのハンドル
    INITCOMMONCONTROLSEX ic;  // INITCOMMONCONTROLSEX構造体
    REBARBANDINFO rbBand;     // REBARBANDINFO構造体
	switch (message)
	{
	case WM_CREATE:
		/* ボード表示ウィンドウの作成 */
		//boardWnd = MakeBoardWindow(hWnd);
		/* レバーコントロールの作成 */
		ic.dwSize = sizeof(INITCOMMONCONTROLSEX); 
		ic.dwICC = ICC_COOL_CLASSES; 
		InitCommonControlsEx(&ic); 
		hRebar = MakeMyRebar(hWnd);
		hListBox = CreateListBox(hWnd);

		ZeroMemory(&rbBand, sizeof(REBARBANDINFO)); 
		rbBand.cbSize = sizeof(REBARBANDINFO); 
		rbBand.fMask = RBBIM_TEXT | RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE; 
		rbBand.fStyle = RBBS_CHILDEDGE | RBBS_NOGRIPPER; 
		rbBand.cxMinChild = 90;
		rbBand.cyMinChild = 25; 

		rbBand.hwndChild = CreateWindow("BUTTON", "新規対局", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)NEWGAME_BT, hInst ,NULL);
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
		
		rbBand.hwndChild = CreateWindow("BUTTON", "継続対局", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)CONTINUE_BT, hInst ,NULL);
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

		rbBand.hwndChild = CreateWindow("BUTTON", "中断", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)INTERRUPT_BT, hInst ,NULL);
		rbBand.cxMinChild = 60;
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

		rbBand.hwndChild = CreateWindow("BUTTON", "手番変更", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)CHANGE_BT, hInst ,NULL);
		rbBand.cxMinChild = 90; 
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

		rbBand.cxMinChild = 30;
		rbBand.hwndChild = CreateWindow("BUTTON", "<<", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)FIRST_BT, hInst ,NULL); 
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
		rbBand.hwndChild = CreateWindow("BUTTON", "←", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)UNDO_BT, hInst ,NULL);
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); 

		rbBand.hwndChild = CreateWindow("BUTTON", "→", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)REDO_BT, hInst ,NULL); 
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

		rbBand.hwndChild = CreateWindow("BUTTON", ">>", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
										 0, 0, 0, 0, hRebar, (HMENU)FINAL_BT, hInst ,NULL);
		SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

		//hToolBar = CreateToolbarEx( 
		//	hWnd,					//親ウィンドウ
		//	WS_CHILD | WS_VISIBLE,	//ウィンドウスタイル 
		//	ID_TOOLBAR,				//コントロールID 
		//	8,						//イメージの数 
		//	hInst, 
		//	ID_MYBMP, 
		//	tbb, 
		//	8,						// ボタンの数 
		//	0,						//ボタンの幅 
		//	0,						//ボタンの高さ 
		//	18,						//イメージの幅 
		//	18,						//イメージの高さ 
		//	sizeof(TBBUTTON));
		//SendMessage(hToolBar, TB_INSERTBUTTON, 2, (LPARAM)&tb); 

		hComBox1 = CreateComBox1(hWnd, BOARD_SIZE + 10, 90, 0);
		SendMessage(hComBox1, CB_SETCURSEL, 0, 0);
		hComBox2 = CreateComBox1(hWnd, BOARD_SIZE + 10, 120, 1);
		SendMessage(hComBox2, CB_SETCURSEL, 1, 0);
		hComBox3 = CreateComBox2(hWnd, BOARD_SIZE + 100, 90, 2);
		ShowWindow(hComBox3, SW_HIDE);
		hComBox4 = CreateComBox2(hWnd, BOARD_SIZE + 100, 120, 3);
		player[0] = HUMAN;
		player[1] = CPU;
		/* 初期難易度 */
		Onnormal(hWnd, BLACK);
		Onnormal(hWnd, WHITE);

		ShowWindow(hListBox, SW_SHOW);	//リストボックスを表示
		UpdateWindow(hWnd);
		UpdateWindow(hRebar);

		//srand((unsigned int)time(NULL));
		/* ステータスバー作成 */
		hStatus = CreateStatusBar(hWnd);

		/* 定石データオープン */
		open_book_thread(hInst);

		break;
	case WM_LBUTTONDOWN:
		/* 左クリックイベント 打てるマスをクリックすればスレッドが起動 */
		if(!AI_THINKING && chk_range_board(lParam))
		{
			Flag_Abort = TRUE;
			WaitForSingleObject(SIG_HINT_FINISHED, INFINITE);
			Flag_Abort = FALSE;
			GameThread(lParam, LBUTTON);
		}
		SendMessage(hStatus, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)turn_str[NowTurn]);
		return 0;
	case WM_RBUTTONDOWN:
		RButtonClick(hWnd, hStatus, lParam);
		return 0;
	case WM_SET_TEXT_BAR:
		SendMessage(hStatus, SB_SETTEXT, (WPARAM)0 | 3, (LPARAM)lParam);
		return 0;
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 選択されたメニューの解析:
		switch (wmId)
		{
		/* コンボボックス */
		case IDC_COM1:
			/* 変更された */
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				int index = SendMessage(hComBox1, CB_GETCURSEL, 0, 0);
				/* 人間を選択 */
				if(index == 0)
				{
					player[0] = HUMAN;
					CpuColor = WHITE;
					ShowWindow(hComBox3, SW_HIDE);
				}
				/* CPUを選択 */
				else
				{
					player[0] = CPU;
					CpuColor = BLACK;
					ShowWindow(hComBox3, SW_SHOW);
				}
			}
			break;
		case IDC_COM2:
			/* 変更された */
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				int index = SendMessage(hComBox2, CB_GETCURSEL, 0, 0);
				/* 人間を選択 */
				if(index == 0)
				{
					player[1] = HUMAN;
					CpuColor = BLACK;
					ShowWindow(hComBox4, SW_HIDE);
				}
				/* CPUを選択 */
				else
				{
					player[1] = CPU;
					CpuColor = WHITE;
					ShowWindow(hComBox4, SW_SHOW);
				}
			}
			break;
		case IDC_COM3:
			/* 変更された */
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				int index = SendMessage(hComBox3, CB_GETCURSEL, 0, 0);
				/* 難易度 */
				switch(index)
				{
				case 0:
					OnVeasy(hWnd, BLACK);
					break;
				case 1:
					Oneasy(hWnd, BLACK);
					break;
				case 2:
					Onnormal(hWnd, BLACK);
					break;
				case 3:
					Onhard(hWnd, BLACK);
					break;
				case 4:
					OnVhard(hWnd, BLACK);
					break;
				case 5:
					OnUhard(hWnd, BLACK);
					break;
				case 6:
					OnSUhard(hWnd, BLACK);
					break;
				case 7:
					OnSSUhard(hWnd, BLACK);
					break;
				case 8:
					OnHUhard(hWnd, BLACK);
					break;
				case 9:
					OnUltra(hWnd, BLACK);
					break;
				case 10:
					OnSUltra(hWnd, BLACK);
					break;
				case 11:
					OnSSUltra(hWnd, BLACK);
					break;
				case 12:
					OnAllSearchWin(hWnd, BLACK);
					break;
				case 13:
					OnAllSearchSD(hWnd, BLACK);
					break;
				}
			}
			break;
		case IDC_COM4:
			/* 変更された */
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				int index = SendMessage(hComBox4, CB_GETCURSEL, 0, 0);
				/* 難易度 */
				switch(index)
				{
				case 0:
					OnVeasy(hWnd, WHITE);
					break;
				case 1:
					Oneasy(hWnd, WHITE);
					break;
				case 2:
					Onnormal(hWnd, WHITE);
					break;
				case 3:
					Onhard(hWnd, WHITE);
					break;
				case 4:
					OnVhard(hWnd, WHITE);
					break;
				case 5:
					OnUhard(hWnd, WHITE);
					break;
				case 6:
					OnSUhard(hWnd, WHITE);
					break;
				case 7:
					OnSSUhard(hWnd, WHITE);
					break;
				case 8:
					OnHUhard(hWnd, WHITE);
					break;
				case 9:
					OnUltra(hWnd, WHITE);
					break;
				case 10:
					OnSUltra(hWnd, WHITE);
					break;
				case 11:
					OnSSUltra(hWnd, WHITE);
					break;
				case 12:
					OnAllSearchWin(hWnd, WHITE);
					break;
				case 13:
					OnAllSearchSD(hWnd, WHITE);
					break;
				}
			}
			break;
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case NEWGAME_BT:
		case StartNew:
			InitBoard();
			/* 置換表の取得 */
			HashDelete(ghash);
			ghash = HashNew(21);
			HashClear(ghash);
			/* 再描写 */
			hdc = GetDC(hWnd);
			DrawBoard( hdc, hStatus, -1, -1);
			ReleaseDC(hWnd, hdc);
			GameThread(lParam, STARTGAME);
			return DefWindowProc(hWnd, message, wParam, lParam);
		case CONTINUE_BT:
			/* 置換表の取得 */
			if(ghash == NULL){
				HashDelete(ghash);
				ghash = HashNew(21);
				HashClear(ghash);
			}
			if(NowTurn == BLACK)
			{
				/* 再描写 */
				hdc = GetDC(hWnd);
				DrawBoard( hdc, hStatus, -1, -1);
				ReleaseDC(hWnd, hdc);
				NowTurn = BLACK;
				GameThread(lParam, STARTGAME);
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			else
			{
				hdc = GetDC(hWnd);
				DrawBoard( hdc, hStatus, -1, -1);
				ReleaseDC(hWnd, hdc);
				NowTurn = WHITE;
				GameThread(lParam, STARTGAME);
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
		case StartContinue_B:
			/* 再描写 */
			hdc = GetDC(hWnd);
			DrawBoard( hdc, hStatus, -1, -1);
			ReleaseDC(hWnd, hdc);
			NowTurn = BLACK;
			GameThread(lParam, STARTGAME);
			return DefWindowProc(hWnd, message, wParam, lParam);
		case StartContinue_W:
			hdc = GetDC(hWnd);
			DrawBoard( hdc, hStatus, -1, -1);
			ReleaseDC(hWnd, hdc);
			NowTurn = WHITE;
			GameThread(lParam, STARTGAME);
			return DefWindowProc(hWnd, message, wParam, lParam);
		/*case Veasy:
			Force_SearchWin = FALSE;
			Force_SearchSD = FALSE;
			OnVeasy(hWnd);
			break;
		case easy:
			Force_SearchWin = FALSE;
			Force_SearchSD = FALSE;
			Oneasy(hWnd);
			break;
		case normal:
			Force_SearchWin = FALSE;
			Force_SearchSD = FALSE;
			Onnormal(hWnd);
			break;
		case hard:
			Force_SearchWin = FALSE;
			Force_SearchSD = FALSE;
			Onhard(hWnd);
			break;
		case Vhard:
			Force_SearchWin = FALSE;
			Force_SearchSD = FALSE;
			OnVhard(hWnd);
			break;
		case Uhard:
			Force_SearchWin = FALSE;
			Force_SearchSD = FALSE;
			OnUhard(hWnd);
			break;
		case AllWinLoss:
			Force_SearchWin = TRUE;
			OnAllSearchWin(hWnd);
			break;
		case AllStoneDiff:
			Force_SearchSD = TRUE;
			Force_SearchWin = FALSE;
			OnAllSearchSD(hWnd);
			break;*/
		case book_switch:
			if(!UseBook)
			{
				UseBook = TRUE;
				m_FlagBook = TRUE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, book_switch, MFS_CHECKED);
			}
			else
			{
				UseBook = FALSE;
				m_FlagBook = FALSE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, book_switch, MFS_UNCHECKED);
			}
			break;
		case book_best:
			if(!b_Flag_not_change)
			{
				HMENU hMenu = GetMenu(hWnd);
				UncheckedAll_BookMenu(hMenu);
				b_Flag_not_change = TRUE;
				CheckMenuItem(hMenu, book_best, MFS_CHECKED);
			}
			break;
		case book_little_change:
			if(!b_Flag_little_change)
			{
				HMENU hMenu = GetMenu(hWnd);
				UncheckedAll_BookMenu(hMenu);
				b_Flag_little_change = TRUE;
				CheckMenuItem(hMenu, book_little_change, MFS_CHECKED);
			}
			break;
		case book_change:
			if(!b_Flag_change)
			{
				HMENU hMenu = GetMenu(hWnd);
				UncheckedAll_BookMenu(hMenu);
				b_Flag_change = TRUE;
				CheckMenuItem(hMenu, book_change, MFS_CHECKED);
			}
			break;
		case book_random:
			{
				HMENU hMenu = GetMenu(hWnd);
				UncheckedAll_BookMenu(hMenu);
				CheckMenuItem(hMenu, book_random, MFS_CHECKED);
			}
			break;
		/*case CorrectSt:
			PrintCorrectSt(hWnd);
			return DefWindowProc(hWnd, message, wParam, lParam);*/
		case rotate90:
			m_FlagInGame = FALSE;
			black = rotate_90(black);
			white = rotate_90(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = rotate_90(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case rotate180:
			m_FlagInGame = FALSE;
			black = rotate_180(black);
			white = rotate_180(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = rotate_180(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case rotate270:
			m_FlagInGame = FALSE;
			black = rotate_270(black);
			white = rotate_270(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = rotate_270(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case symX:
			m_FlagInGame = FALSE;
			black = symmetry_x(black);
			white = symmetry_x(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = symmetry_x(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case symY:
			m_FlagInGame = FALSE;
			black = symmetry_y(black);
			white = symmetry_y(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = symmetry_y(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case symBL:
			m_FlagInGame = FALSE;
			black = symmetry_b(black);
			white = symmetry_b(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = symmetry_b(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case symWL:
			m_FlagInGame = FALSE;
			black = symmetry_w(black);
			white = symmetry_w(white);
			{
				BitBoard move = one << (move_x * 8 + move_y);
				move = symmetry_w(move);
				int pos = CountBit((move & (-(signed long long int)move)) - 1);
				move_x = pos / 8;
				move_y = pos % 8;
			}
			break;
		case BoardInit:
			InitBoard();
			{
				/* メニューバーの各項目の有効無効化 */
				HMENU hMenu = GetMenu(hWnd);
				EnableMenuItem(hMenu, interrupt, MFS_GRAYED);
				EnableMenuItem(hMenu, EditBoard, MFS_ENABLED);
				EnableMenuItem(hMenu, ChangeColor, MFS_ENABLED);
			}
			break;
		case EditBoard:
			Flag_Edit = TRUE;
			break;
		case INTERRUPT_BT:
		case interrupt:
			if(AI_THINKING /*|| m_FlagHint */)
			{
				Flag_Abort = TRUE;
			}
			else
			{
				Interrupt_flag = TRUE;
				m_FlagInterrupt = TRUE;
				m_FlagInGame = FALSE;
			}
			{
				HMENU hMenu = GetMenu(hWnd);
				EnableMenuItem(hMenu, interrupt, MFS_GRAYED);
				hMenu = GetMenu(hWnd);
				EnableMenuItem(hMenu, EditBoard, MFS_ENABLED);
				EnableMenuItem(hMenu, ChangeColor, MFS_ENABLED);
			}
			break;
		case CHANGE_BT:
		case ChangeColor:
			CpuColor ^= 1;
			break;
		case print_result:
			if(!AI_result)
			{
				AI_result = TRUE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, print_result, MFS_CHECKED);
			}
			else
			{
				AI_result = FALSE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, print_result, MFS_UNCHECKED);
			}
			break;
		case print_AI_moves:
			/*if(!AI_thinking)
			{
				AI_thinking = TRUE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, print_AI_moves, MFS_CHECKED);
			}
			else
			{
				AI_thinking = FALSE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, print_AI_moves, MFS_UNCHECKED);
			}*/
			
			break;
		case print_thinking:
		/*	if(!OnTheWay)
			{
				OnTheWay = TRUE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, print_thinking, MFS_CHECKED);
			}
			else
			{
				OnTheWay = FALSE;
				HMENU hMenu = GetMenu(hWnd);
				CheckMenuItem(hMenu, print_thinking, MFS_UNCHECKED);
			}*/
			break;
		case Auto_Learn:
			//InitBoard();
			//{
			//	int i = 0;
			//	while(i < 1)
			//	{
			//		Learn_Thread();
			//		//Start_Auto_Learn(4, 13, 100000, -1);
			//		i++;
			//	}
			//}
			break;
		case 32849:
			/*{
				Learn_Thread();
			}*/
			break;
		case auto_g:
			m_FlagInterrupt = FALSE;
			Interrupt_flag = FALSE;
			auto_game_thread();
			break;
		case UNDO_BT:
		case Undo:
			if(turn == 0 || (UndoBoard_B[turn - 1] == 0 && UndoBoard_W[turn - 1] == 0))
			{
				break;
			}
			m_FlagInGame = FALSE;
			if(AI_THINKING /* || m_FlagHint */)
			{
				Flag_Abort = TRUE;
			}
			/* ヒント用の評価データ破棄 */
			/*{
				for(int i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;}
			}*/
			black = UndoBoard_B[turn - 1];
			white = UndoBoard_W[turn - 1];
			move_x = Undo_x[turn - 1];
			move_y = Undo_y[turn - 1];
			NowTurn = Undo_color[turn - 1];

			turn--;
			SendMessage(hListBox, LB_SETCURSEL, turn - 1, 0);
			if(turn - 1 < 0 || (UndoBoard_B[turn - 1] == 0 && UndoBoard_W[turn - 1] == 0))
			{
				EnableMenuItem(GetMenu(hWnd), Undo, MFS_GRAYED);
				EnableWindow(GetDlgItem(hRebar, UNDO_BT), FALSE);
			}
			if(!(UndoBoard_B[turn + 1] == 0 && UndoBoard_W[turn + 1] == 0) || turn + 1 <= 60)
			{
				EnableMenuItem(GetMenu(hWnd), Redo, MFS_ENABLED);
				EnableWindow(GetDlgItem(hRebar, REDO_BT), TRUE);
			}
			break;
		case REDO_BT:
		case Redo:
			if(turn == 60 || UndoBoard_B[turn + 1] == 0 && UndoBoard_W[turn + 1] == 0)
			{
				break;
			}
			m_FlagInGame = FALSE;
			/* ヒント用の評価データ破棄 */
			/*{
				for(int i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;}
			}*/
			SendMessage(hListBox, LB_SETCURSEL, turn, 0);
			black = UndoBoard_B[turn + 1];
			white = UndoBoard_W[turn + 1];
			move_x = Undo_x[turn + 1];
			move_y = Undo_y[turn + 1];
			NowTurn = Undo_color[turn + 1];
			turn++;
			if((UndoBoard_B[turn + 1] == 0 && UndoBoard_W[turn + 1] == 0) || turn + 1 > 60)
			{
				EnableMenuItem(GetMenu(hWnd), Redo, MFS_GRAYED);
				EnableWindow(GetDlgItem(hRebar, REDO_BT), FALSE);
			}
			if(turn - 1 >= 0 || !(UndoBoard_B[turn - 1] == 0 && UndoBoard_W[turn - 1] == 0))
			{
				EnableMenuItem(GetMenu(hWnd), Undo, MFS_ENABLED);
				EnableWindow(GetDlgItem(hRebar, UNDO_BT), TRUE);
			}
			break;
		case FIRST_BT:
			{
				int i;
				for(i = 0; i < 60; i++)
				{
					if(UndoBoard_B[i] != 0 || UndoBoard_W[i] != 0)
					{	
						black = UndoBoard_B[i];
						white = UndoBoard_W[i];
						move_x = Undo_x[i];
						move_y = Undo_y[i];
						NowTurn = Undo_color[i];
						turn = i;
						/* ヒント用の評価データ破棄 */
						//for(i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;}
						m_FlagInGame = FALSE;
						break;
					}
				}
			}
			break;
		case FINAL_BT:
			{
				int i;
				for(i = 60; i >= 0; i--)
				{
					if(UndoBoard_B[i] != 0 || UndoBoard_W[i] != 0)
					{	
						black = UndoBoard_B[i];
						white = UndoBoard_W[i];
						move_x = Undo_x[i];
						move_y = Undo_y[i];
						NowTurn = Undo_color[i];
						turn = i;
						/* ヒント用の評価データ破棄 */
						//for(i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;}
						m_FlagInGame = FALSE;
						break;
					}
				}
			}
			break;
		case Hint_0:
			OnHint_0(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case Hint_1:
			OnHint_1(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case Hint_2:
			OnHint_2(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case Hint_3:
			OnHint_3(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case Hint_4:
			OnHint_4(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case Hint_5:
			OnHint_5(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case Hint_6:
			OnHint_6(hWnd);
			HINT_DISPED = FALSE;
			GameThread(0, HINTONLY);
			break;
		case print_eval:
			//read_eval_table(CountBit(black | white) - 4);
			if(turn == 0){
				break;
			}
			//read_eval_table(turn - 1);
			if(NowTurn == BLACK){
				init_index_board(black, white);
				GetEvalFromPattern(black, white, NowTurn, turn - 1);
			}
			else{
				init_index_board(white, black);
				GetEvalFromPattern(white, black, NowTurn, turn - 1);
			}
			
			{
				char eval_msg[PATTERN_NUM + 1][64];
				sprintf_s(eval_msg[0], "hori_ver1_1 = %f, ", key_hori_ver1[0]);
				sprintf_s(eval_msg[1], "hori_ver1_2 = %f\n", key_hori_ver1[1]);
				sprintf_s(eval_msg[2], "hori_ver1_3 = %f,", key_hori_ver1[2]);
				sprintf_s(eval_msg[3], "hori_ver1_4 = %f\n", key_hori_ver1[3]);
				sprintf_s(eval_msg[4], "hori_ver2_1 = %f,", key_hori_ver2[0]);
				sprintf_s(eval_msg[5], "hori_ver2_2 = %f\n", key_hori_ver2[1]);
				sprintf_s(eval_msg[6], "hori_ver2_3 = %f,", key_hori_ver2[2]);
				sprintf_s(eval_msg[7], "hori_ver2_4 = %f\n", key_hori_ver2[3]);
				sprintf_s(eval_msg[8], "hori_ver3_1 = %f,", key_hori_ver3[0]);
				sprintf_s(eval_msg[9], "hori_ver3_2 = %f\n", key_hori_ver3[1]);
				sprintf_s(eval_msg[10], "hori_ver3_3 = %f,", key_hori_ver3[2]);
				sprintf_s(eval_msg[11], "hori_ver3_4 = %f\n", key_hori_ver3[3]);
				sprintf_s(eval_msg[12], "dia_ver1_1 = %f,",  key_dia_ver1[0]);
				sprintf_s(eval_msg[13], "dia_ver1_2 = %f\n",  key_dia_ver1[1]);
				sprintf_s(eval_msg[14], "dia_ver2_1 = %f,", key_dia_ver2[0]);
				sprintf_s(eval_msg[15], "dia_ver2_2 = %f\n", key_dia_ver2[1]);
				sprintf_s(eval_msg[16], "dia_ver2_3 = %f,", key_dia_ver2[2]);
				sprintf_s(eval_msg[17], "dia_ver2_4 = %f\n", key_dia_ver2[3]);
				sprintf_s(eval_msg[18], "dia_ver3_1 = %f,", key_dia_ver3[0]);
				sprintf_s(eval_msg[19], "dia_ver3_2 = %f\n", key_dia_ver3[1]);
				sprintf_s(eval_msg[20], "dia_ver3_3 = %f,", key_dia_ver3[2]);
				sprintf_s(eval_msg[21], "dia_ver3_4 = %f\n", key_dia_ver3[3]);
				sprintf_s(eval_msg[22], "dia_ver4_1 = %f,", key_dia_ver4[0]);
				sprintf_s(eval_msg[23], "dia_ver4_2 = %f\n", key_dia_ver4[1]);
				sprintf_s(eval_msg[24], "dia_ver4_3 = %f,", key_dia_ver4[2]);
				sprintf_s(eval_msg[25], "dia_ver4_4 = %f\n", key_dia_ver4[3]);
				sprintf_s(eval_msg[26], "edge_1 = %f,", key_edge[0]);
				sprintf_s(eval_msg[27], "edge_2 = %f\n", key_edge[1]);
				sprintf_s(eval_msg[28], "edge_3 = %f,", key_edge[2]);
				sprintf_s(eval_msg[29], "edge_4 = %f\n", key_edge[3]);
				sprintf_s(eval_msg[26], "edge_cor_1 = %f,", key_edge_cor[0]);
				sprintf_s(eval_msg[27], "edge_cor_2 = %f\n", key_edge_cor[1]);
				sprintf_s(eval_msg[28], "edge_cor_3 = %f,", key_edge_cor[2]);
				sprintf_s(eval_msg[29], "edge_cor_4 = %f\n", key_edge_cor[3]);
				sprintf_s(eval_msg[34], "corner4_2_1 = %f,", key_corner4_2[0]);
				sprintf_s(eval_msg[35], "corner4_2_2 = %f\n", key_corner4_2[1]);
				sprintf_s(eval_msg[36], "corner4_2_3 = %f,", key_corner4_2[2]);
				sprintf_s(eval_msg[37], "corner4_2_4 = %f\n", key_corner4_2[3]);
				sprintf_s(eval_msg[38], "corner3_3_1 = %f,", key_corner3_3[0]);
				sprintf_s(eval_msg[39], "corner3_3_2 = %f\n", key_corner3_3[1]);
				sprintf_s(eval_msg[40], "corner3_3_3 = %f,", key_corner3_3[2]);
				sprintf_s(eval_msg[41], "corner3_3_4 = %f\n", key_corner3_3[3]);
				/*sprintf_s(eval_msg[38], "triangle_1 = %f,", key_triangle[0]);
				sprintf_s(eval_msg[39], "triangle_2 = %f\n", key_triangle[1]);
				sprintf_s(eval_msg[40], "triangle_3 = %f,", key_triangle[2]);
				sprintf_s(eval_msg[41], "triangle_4 = %f\n", key_triangle[3]);
				sprintf_s(eval_msg[42], "mobility = %f\n", key_mobility);
				sprintf_s(eval_msg[43], "potential_mobility = %f\n", key_pot_mobility);
				sprintf_s(eval_msg[44], "paility = %f\n", key_pality);*/
				sprintf_s(eval_msg[42], "mobility = %f\n", key_mobility);
				sprintf_s(eval_msg[43], "constant = %f\n", key_constant);
				sprintf_s(eval_msg[44], "\n評価値 = %f,", eval_sum);
				sprintf_s(eval_msg[45], "\nblack = 0x%llx\nwhite = 0x%llx\n", black, white);
				int i;
				char print_msg[8192];
				strcpy_s(print_msg, eval_msg[0]);
				for(i = 1; i < 46; i++)
				{
					strcat_s(print_msg, eval_msg[i]);
				}
				
				MessageBox(hWnd, print_msg, "評価値詳細一覧", MB_OK);
				//memset(msg, 0, sizeof(print_msg));
			}
			break;
			/* FFOメニュ− */

		case FFO40:
			black = 9158069842325798912;
			white = 11047339776155165;
			configCPU(BLACK);
			break;

		case FFO41:
			black = 616174399789064;
			white = 39493460025648416;
			configCPU(BLACK);
			break;

		case FFO42:
			white = 9091853944868375556;
			black = 22586176447709200;
			configCPU(BLACK);
			break;

		case FFO43:
			black = 38808086923902976;
			white = 13546258740034592;
			configCPU(WHITE);
			break;

		case FFO44:
			black = 2494790880993312;
			white = 1010251075753548824;
			configCPU(WHITE);
			break;

		case FFO45:
			black = 282828816915486;
			white = 9287318235258944;
			configCPU(BLACK);
			break;

		case FFO46:
			black = 4052165999611379712;
			white = 36117299622447104;
			configCPU(BLACK);

			break;

		case FFO47:
			black = 277938752194568;
			white = 3536224466208;
			configCPU(WHITE);
			break;

		case FFO48:
			black = 38519958422848574;
			white = 4725679339520;
			configCPU(WHITE);
			break;

		case FFO49:
			black = 5765976742297600;
			white = 4253833575484;
			configCPU(BLACK);

			break;

		case FFO50:
			black = 4504145659822080;
			white = 4336117619740130304;
			configCPU(BLACK);
			break;

		case FFO51:
			black = 349834415978528;
			white = 8664011788383158280;
			configCPU(WHITE);
			break;

		case FFO52:
			black = 9096176176681728056;
			white = 35409824317440;
			configCPU(WHITE);
			break;

		case FFO53:
			black = 2515768979493888;
			white = 8949795312300457984;
			configCPU(BLACK);
			break;

		case FFO54:
			black = 277938752194568;
			white = 3536224466208;
			configCPU(BLACK);
			break;

		case FFO55:
			black = 4635799596172290;
			white = 289361502099486840;
			configCPU(BLACK);
			break;

		case FFO56:
			black = 4925086697193472;
			white = 9007372734053408;
			configCPU(WHITE);
			break;

		case FFO57:
			black = 9060166336512000;
			white = 8943248156475301888;
			configCPU(BLACK);

			break;

		case FFO58:
			black = 4636039783186432;
			white = 3383245044333600;
			configCPU(BLACK);
			break;

		case FFO59:
			black = 17320879491911778304;
			white = 295223649004691488;
			configCPU(BLACK);
			break;

		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		InvalidateRect(hWnd, NULL, FALSE);
		/* 再描写 */
		hdc = GetDC(hWnd);
		DrawBoard( hdc, hStatus, -1, -1);
		ReleaseDC(hWnd, hdc);
		UpdateWindow(hRebar);
		SendMessage(hStatus, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)turn_str[NowTurn]);
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: 描画コードをここに追加してください...
		hdc = GetDC(hWnd);
		DrawBoard( hdc, hStatus, move_x, move_y);
		ReleaseDC(hWnd, hdc);
		SendMessage(hStatus, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)turn_str[NowTurn]);
		//char str[64];
		//sprintf_s(str, "black = %llu", black);
		//SendMessage(hStatus, SB_SETTEXT, (WPARAM)3 | 0, (LPARAM)str);
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		
		/* 置換表の解放 */
		//HashDelete(hashTable);
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Beispiel #7
0
/* 局面情報を元に定石を検索 */
int search_books(BooksNode *book_root, BitBoard bk, BitBoard wh, int turn)
{
	int move = -1;
	srand((unsigned int )time(NULL));

	/* 局面から該当の定石を探す */
	BooksNode *book_header = search_book_info(book_root, NULL, bk, wh, turn);
	if(book_header != NULL)
	{
		//if(!m_FlagHint)
		//{
			/* 評価値により次の手を定石から選ぶ */
			MAXEVAL = book_alphabeta(book_header, 0, NEGAMIN, NEGAMAX, NowTurn);
			book_header = BestNode;
		//}
		/*if(book_header->book_name != "" && !m_FlagHint)
		{
			SendMessage(hStatus, SB_SETTEXT, (WPARAM)0 | 0, (LPARAM)book_header->book_name);
		}*/

		/* 指し手の対称回転変換の場合分け */
		switch(TRANCE_MOVE)
		{
		case 0:
			move = book_header->move;
			break;
		case 1:
			{
				BitBoard t_move = rotate_90(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		case 2:
			{
				BitBoard t_move = rotate_180(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		case 3:
			{
				BitBoard t_move = rotate_270(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		case 4:
			{
				BitBoard t_move = symmetry_x(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		case 5:
			{
				BitBoard t_move = symmetry_y(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		case 6:
			{
				BitBoard t_move = symmetry_b(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		case 7:
			{
				BitBoard t_move = symmetry_w(one << book_header->move);
				move =  CountBit((t_move & (-(INT64)t_move)) - 1);
			}
			break;
		default:
			move = book_header->move;
			break;
		}
	}
	/* save global node. */
	Undo_Node[turn] = book_header;
	return move;
}
Beispiel #8
0
/***************************************************************************
* Name  : SearchBooks
* Brief : 定石やからCPUの着手を決定する
* Return: 着手可能位置のビット列
****************************************************************************/
INT32 SearchBooks(BooksNode *book_root, UINT64 bk, UINT64 wh,
	UINT32 color, UINT32 change, INT32 turn)
{
	INT32 move = MOVE_NONE;
	ULONG eval = 0;
	BookData *book_data;
	BooksNode *book_header;

	g_booklist_cnt = 0;
	// 変化度設定
	set_book_error(change);

	/* 局面から該当の定石を探す */
	book_header = SearchBookInfo(book_root, book_root, bk, wh, turn);

	if (book_header != NULL)
	{
		/* 評価値により次の手を定石から選ぶ */
		eval = book_alphabeta(book_header, 0, NEGAMIN, NEGAMAX, color);
		book_data = select_node(change);
		g_evaluation = book_data->eval;

		/* 指し手の対称回転変換の場合分け */
		switch (TRANCE_MOVE)
		{
		case 0:
			move = book_data->node->move;
			break;
		case 1:
		{
			UINT64 t_move = rotate_90(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		case 2:
		{
			UINT64 t_move = rotate_180(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		case 3:
		{
			UINT64 t_move = rotate_270(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		case 4:
		{
			UINT64 t_move = symmetry_x(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		case 5:
		{
			UINT64 t_move = symmetry_y(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		case 6:
		{
			UINT64 t_move = symmetry_b(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		case 7:
		{
			UINT64 t_move = symmetry_w(1ULL << book_data->node->move);
			move = CountBit((t_move & (-(INT64)t_move)) - 1);
		}
		break;
		default:
			move = book_data->node->move;
			break;
		}
	}

	return move;
}