資源簡介
matlab開發-othellom。一個簡單的單人奧賽羅棋盤游戲程序。

代碼片段和文件信息
function?othello()
%?othello.m
%?A?simple?othello?program
%?Author:?Subroto?Gunawan
%?Date:?August?8?2000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%?VARIABLE?DECLARATIONS?%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?drawing?parameters
DrawResolution?=?1/100;
N=2*pi;
Theta?=?0:DrawResolution:N;
%?define?the?board
BoardSize?=?8;
FigSize?=?400;
ButtonWidth?=?100;
Board?=?zeros(BoardSizeBoardSize);
InitXLoc?=?[?BoardSize/2?BoardSize/2+1?BoardSize/2?BoardSize/2+1];
InitYLoc?=?[?BoardSize/2?BoardSize/2?BoardSize/2+1?BoardSize/2+1];
%?default?values
DefaultFirstTurn?=?1;?%?1?is?white?2?is?black
finish=0;
whitePlayer?=?‘human‘;
blackPlayer?=?‘com‘;
XPos?=?[-1];
YPos?=?[-1];
XLegalPos?=?[];
YLegalPos?=?[];
BetweenCount?=?[];
NoMoveTurnCount?=?0;
XDir?=?[-1?-1?0?+1?+1?+1?0?-1];?%?counter?clockwise?directions?starting?from?West
YDir?=?[0?+1?+1?+1?0?-1?-1?-1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%?INITIALIZATION?%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?set?up?the?main?frame
fig1?=?figure(1);?
clf;
set(fig1?‘Position‘?[120?120?FigSize+ButtonWidth?FigSize]...
???‘Name‘‘Othello‘...
???‘Numbertitle‘‘off‘...
???‘MenuBar‘‘none‘);
%?user?control?panel
left?=?400;
bottom?=?300;
width?=?75;
height?=?30;
ymod?=?30;
statusText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[(FigSize+ButtonWidth-300)/2?FigSize-30?300?25]...
???‘BackgroundColor‘[0.8?0.8?0.8]...
???‘FontWeight‘‘bold‘...
???‘String‘‘‘);
infoText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[(FigSize+ButtonWidth-300)/2?5?300?25]...
???‘BackgroundColor‘[0.8?0.8?0.8]...
???‘String‘‘Right?Click?to?Quit‘);
whitePlayerText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[left?bottom?width?height]...
???‘BackgroundColor‘[0.8?0.8?0.8]...
???‘HorizontalAlignment‘‘left‘...
???‘String‘[‘?White?:?‘?whitePlayer]);
???
blackPlayerText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[left?bottom-ymod?width?height]...
???‘BackgroundColor‘[0.8?0.8?0.8]...
???‘HorizontalAlignment‘‘left‘...
???‘String‘[‘?Black?:?‘?blackPlayer]);
turnText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[left?bottom-4*ymod?width?height]...
???‘BackgroundColor‘[0.8?0.8?0.8]...
???‘String‘‘?White?Turn?‘);
???
whiteText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[left?bottom-7*ymod?width?height]...
??????‘BackgroundColor‘[0.8?0.8?0.8]...
??????‘String‘‘White?=?2‘);
???
blackText?=?uicontrol(‘style‘‘Text‘...
???‘Position‘[left?bottom-8*ymod?width?height]...
??????‘BackgroundColor‘[0.8?0.8?0.8]...
??????‘String‘‘Black?=?2‘);
%?creating?the?board?grids
XLine?=?linspace(0FigSizeBoardSize+1);
YLine?=?linspace(0FigSizeBoardSize+1);
for?i=1:(BoardSize+1)
???line([XLine(i)?XLine(i)]?[YLine(1)?YLine(BoardSize+1)]‘Color‘[0?0?0]);
???line([XLine(1)?XLine(BoardSize+1)]?[YLine(i)?YLine(i)]‘Color‘[0?0?0]);
end
axis([0FigSize+ButtonWidth0FigSize]);
hold?on;?
axis?off;
%?determine?the?radius?of?the?piece
gap?=?(XLine(2)-XLine(1))/2;
radius?=?gap?-?(gap*0.25);?%?leave?a?25%?side?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????12088??2018-07-11?20:16??othello.m
評論
共有 條評論