此類簡(jiǎn)單游戲的設(shè)計(jì)最花時(shí)間的就是要保證功能完整,讓玩家玩得盡可能舒服。 主體架構(gòu)方面都沒有大問題,而在加入人機(jī)對(duì)戰(zhàn)、機(jī)器對(duì)戰(zhàn)及悔棋功能時(shí),一些細(xì)微問題需要好好研究,不停測(cè)試。 AI等智力問題也要適中。太弱智了玩得沒激情,太聰明了玩得沒信心。 經(jīng)過測(cè)試,發(fā)現(xiàn)再高級(jí)的AI也有輸?shù)臅r(shí)候,測(cè)試的博弈樹的深度為2,再深反應(yīng)會(huì)很慢,也就是說能預(yù)測(cè)兩步的AI也會(huì)輸。 剛開始找到博弈樹算法時(shí),以為不管深度為多少都很聰明,后來(lái)發(fā)現(xiàn)只要找到竅門,那么深度為2的也很容易被打敗。 而深度為3的反應(yīng)需要10秒,后面的深度呈指數(shù)型增長(zhǎng),不符合實(shí)際需求。 游戲經(jīng)過多次測(cè)試,反應(yīng)良好。
PS】因馬上就要交課程設(shè)計(jì)報(bào)告,公司也很忙,以下功能等后續(xù)版本實(shí)現(xiàn): 1、 據(jù)資料顯示,博弈樹算法還有很大的優(yōu)化空間 2、 機(jī)器對(duì)戰(zhàn),需要用到多線程 3、 聯(lián)網(wǎng)對(duì)戰(zhàn),因?yàn)閭鬏數(shù)臄?shù)據(jù)量小,且要求實(shí)時(shí)、有序、可靠,因此采用TCP協(xié)議 4、 嵌入式,所在公司用的是Wince系統(tǒng),改天有時(shí)間移植上去 5、 多語(yǔ)言界面,如果老外也喜歡五子棋的話
參考文獻(xiàn)【見同文件夾目錄】 1、 五子棋開局指南 2、 維基百科:Alpha-Beta剪枝算法
0.png (51.19 KB, 下載次數(shù): 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;//;
- //設(shè)置窗口大。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
復(fù)制代碼
所有資料51hei提供下載:
3_1.zip
(108.13 KB, 下載次數(shù): 63)
2017-6-6 18:24 上傳
點(diǎn)擊文件名下載附件
解壓就好 下載積分: 黑幣 -5
|