此類簡單游戲的設計最花時間的就是要保證功能完整,讓玩家玩得盡可能舒服。 主體架構方面都沒有大問題,而在加入人機對戰、機器對戰及悔棋功能時,一些細微問題需要好好研究,不停測試。 AI等智力問題也要適中。太弱智了玩得沒激情,太聰明了玩得沒信心。 經過測試,發現再高級的AI也有輸的時候,測試的博弈樹的深度為2,再深反應會很慢,也就是說能預測兩步的AI也會輸。 剛開始找到博弈樹算法時,以為不管深度為多少都很聰明,后來發現只要找到竅門,那么深度為2的也很容易被打敗。 而深度為3的反應需要10秒,后面的深度呈指數型增長,不符合實際需求。 游戲經過多次測試,反應良好。
PS】因馬上就要交課程設計報告,公司也很忙,以下功能等后續版本實現: 1、 據資料顯示,博弈樹算法還有很大的優化空間 2、 機器對戰,需要用到多線程 3、 聯網對戰,因為傳輸的數據量小,且要求實時、有序、可靠,因此采用TCP協議 4、 嵌入式,所在公司用的是Wince系統,改天有時間移植上去 5、 多語言界面,如果老外也喜歡五子棋的話
參考文獻【見同文件夾目錄】 1、 五子棋開局指南 2、 維基百科:Alpha-Beta剪枝算法
0.png (51.19 KB, 下載次數: 85)
下載附件
2017-6-6 18:29 上傳
c++源程序如下:
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "3_1.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
-
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status bar\n");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- //添加白棋圖像
- // m_wndStatusBar.GetStatusBarCtrl().SetIcon(0,AfxGetApp()->LoadIcon(IDI_WHITE));
- //顯示文字
- // m_wndStatusBar.SetPaneText(0,"白棋下");
-
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.dwExStyle=cs.dwExStyle|WS_EX_TOPMOST; //
- cs.style=WS_SYSMENU|WS_OVERLAPPED|WS_MINIMIZEBOX;//;
- //設置窗口大小:400*340
- cs.cx=450;
- cs.cy=500;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
復制代碼
所有資料51hei提供下載:
3_1.zip
(108.13 KB, 下載次數: 63)
2017-6-6 18:24 上傳
點擊文件名下載附件
解壓就好 下載積分: 黑幣 -5
|