资源简介

基于C++的五子棋游戏设计 绝对可用 详细毕业设计代码,编译即可运行

资源截图

代码片段和文件信息

// Algorithm.cpp : implementation file
//

#include “stdafx.h“
#include “GoBang.h“
#include “Algorithm.h“
#include “Afxtempl.h“

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAlgorithm

CAlgorithm::CAlgorithm()
{
}

CAlgorithm::~CAlgorithm()
{
}


int CAlgorithm::SearchMaxValue(Step &st int array[16][16])
{
int max_score = 0;
int score = 0;

GameStatus temp;
temp.is_machine = true;
temp.deep = 0;
for (int i = 0 ; i < 16 ; i++)
for (int jj = 0 ; jj< 16 ;jj++)
temp.fivearray[i][jj] = array[i][jj];


for ( i = 1 ; i < 16 ; i++)
for(int j =1; j < 16 ; j++)
{
if ( array[i][j] == 0)
{
temp.st.x = i ;
temp.st.y = j;
score = 0;
int score1 = 0score2 = 0;



temp.fivearray[i][j] = 3;
temp.st.side = 3;
temp.is_machine = true; 
temp.score = 0;
GetCurrentScore(temp);
score1  = temp.score ;

temp.fivearray[i][j] = 1;
temp.st.side = 1 ;
temp.is_machine = false ;
temp.score = 0;
 GetCurrentScore(temp);
score2 = -temp.score ;



//机器
if ( score1 >= 10000 )
{
 
temp.fivearray[i][j] = 3;
temp.st.side = 3;
temp.is_machine = true; 
temp.score = 0;
Step tempst1; 
int tempscore = SearchValue(temp.fivearraytempst1false);
if ( score1 < tempscore)//如果当前盘面还有比现在分数大的,则防守
{
st.x = tempst1.x;
st.y = tempst1.y ;
return tempscore;
}
else
{
st.x = i;
st.y = j;
return score1;
}
}
if ( score2 >= 10000 )
{
temp.fivearray[i][j] = 1;
temp.st.side = 1 ;
temp.is_machine = false ;
temp.score = 0;
Step tempst1; 
int tempscore = SearchValue(temp.fivearraytempst1true);
if ( score2 <= tempscore)//
{
st.x = tempst1.x;
st.y = tempst1.y ;
return tempscore;
}
else
{
st.x = i;
st.y = j;
return score1;
}

}



score = score1 + score2 ;

 if  ( score > max_score )
 {
 max_score = score ;
 st.x = i;
 st.y = j;
 }


temp.fivearray[i][j] = 0;

}


}

return max_score ;
}

void CAlgorithm::GetCurrentScore( GameStatus &board_situation)
{
int i = board_situation.st.x ;
int j = board_situation.st.y;
board_situation.score = 0;
//状态
//返回8 成5:five
//返回7 活4:alivefour
//返回6 活3:alivethree
//返回5 活2:alivetwo
//返回4 死4:deadfour
//返回3 死3:deadthree
//返回2 死2:deadtwo
//返回0

//搜索出左到右的状态
int lr =LeftToRight_Status(i  j board_situation.fivearray);
if  ( lr == 8 ) 
{
if ( board_situation.is_machine )
board_situation.score = 100000;
else
board_situation.score = -100000;
return ;
}
//从上到下
int ud = UpToDown_Status(ij

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-05-25 08:45  基于C++的五子棋游戏设计\
     文件       25374  2012-05-26 22:04  基于C++的五子棋游戏设计\Algorithm.cpp
     文件        2081  2013-05-16 13:04  基于C++的五子棋游戏设计\Algorithm.h
     文件        3919  2012-05-26 22:46  基于C++的五子棋游戏设计\Chess.cpp
     文件        1524  2012-05-26 16:11  基于C++的五子棋游戏设计\Chess.h
     文件      906416  2013-05-16 12:59  基于C++的五子棋游戏设计\GoBang.aps
     文件        2076  2013-05-23 10:09  基于C++的五子棋游戏设计\GoBang.clw
     文件        2063  2008-11-06 18:00  基于C++的五子棋游戏设计\GoBang.cpp
     文件        5086  2012-05-22 19:56  基于C++的五子棋游戏设计\GoBang.dsp
     文件         537  2008-11-06 18:00  基于C++的五子棋游戏设计\GoBang.dsw
     文件        1324  2008-11-06 18:00  基于C++的五子棋游戏设计\GoBang.h
     文件       82944  2013-05-25 08:45  基于C++的五子棋游戏设计\GoBang.ncb
     文件      130048  2013-05-25 08:45  基于C++的五子棋游戏设计\GoBang.opt
     文件        1023  2013-05-25 08:45  基于C++的五子棋游戏设计\GoBang.plg
     文件        6652  2013-05-16 12:59  基于C++的五子棋游戏设计\GoBang.rc
     文件         882  2013-05-16 12:43  基于C++的五子棋游戏设计\GoBang.sln
     文件       10240  2013-05-25 08:44  基于C++的五子棋游戏设计\GoBang.suo
     文件        9232  2013-05-16 12:40  基于C++的五子棋游戏设计\GoBang.vcproj
     文件        1427  2013-05-16 12:46  基于C++的五子棋游戏设计\GoBang.vcproj.CX1DWFG65MRWCLE.Administrator.user
     文件       12185  2012-05-26 23:00  基于C++的五子棋游戏设计\GoBangDlg.cpp
     文件        2045  2012-05-26 22:12  基于C++的五子棋游戏设计\GoBangDlg.h
     文件        3579  2008-11-06 18:00  基于C++的五子棋游戏设计\ReadMe.txt
     目录           0  2013-05-23 12:50  基于C++的五子棋游戏设计\Release\
     文件       19124  2013-05-23 12:50  基于C++的五子棋游戏设计\Release\Algorithm.obj
     文件           0  2013-05-23 12:50  基于C++的五子棋游戏设计\Release\Algorithm.sbr
     文件       15656  2013-05-25 08:45  基于C++的五子棋游戏设计\Release\Chess.obj
     文件           0  2013-05-25 08:45  基于C++的五子棋游戏设计\Release\Chess.sbr
     文件        7464  2012-05-15 09:49  基于C++的五子棋游戏设计\Release\Computer.obj
     文件           0  2012-05-15 09:49  基于C++的五子棋游戏设计\Release\Computer.sbr
     文件     3695616  2013-05-25 08:45  基于C++的五子棋游戏设计\Release\GoBang.bsc
     文件      905216  2013-05-25 08:45  基于C++的五子棋游戏设计\Release\GoBang.exe
............此处省略36个文件信息

评论

共有 条评论