黑白棋的matlab实现
黑白棋,又叫反棋(Reversi)、奥赛罗棋(Othello)、苹果棋或翻转棋。黑白棋在西方和日
本很流行。游戏通过相互翻转对方的棋子,最后以棋盘上谁的棋子多来判断胜负。它的游戏规则简
单,因此上手很容易,但是它的变化又非常复杂。有一种说法是:只需要几分钟学会它,却需要一
生的时间去精通它。
本程序由matlab开发,作者为realghost,如果要转载,请保留此信息。
如要交流,请与 slqinyi@163.com 联系。
function Heibai()
figure(1)
axis([0 12 0 12]);
hold on
axis off
for i = 1:11%»ÆåÅÌ
line([1 11],[i i]);
line([i i],[1 11]);
end
axis equal
drawthego(5.5,5.5,1);
drawthego(5.5,6.5,0);
drawthego(6.5,5.5,0);
drawthego(6.5,6.5,1);%ÆåÅ̳õʼµÄ״̬
qishou = 1; % ÅжÏÆåÊÖµÄÑÕÉ«£¬¿ªÊ¼µÄʱºòÊǺìÉ«£¬È¡2ʱÊǺÚÉ«
boardstatus = zeros(10);% ÆåÅÌ״̬¾ØÕó£¬È¡0Ϊ¿Õ£¬È¡1Ϊºì£¬È¡2ΪºÚ
boardstatus([5 6],[5 6]) = [1 2;2 1];
while 1
hold on
posflag = 1; % ÓÃÓÚÅжÏϵÄÆåÊÇ·ñÓÐЧ£¬È¡1˵Ã÷ϵÄÆåÎÞЧ£¬ÒªÖØÐÂÏÂ
while posflag
[xpos,ypos] = ginput(1);
xpos = 0.5*(floor(xpos)+ceil(xpos));
ypos = 0.5*(floor(ypos)+ceil(ypos));
if xpos<=0.5|xpos>=11|ypos<=0.5|ypos>=11% µãµ½ÆåÅÌÍâÁË
continue
end
rx = floor(xpos);
ry = floor(ypos);
if boardstatus(rx,ry)==1|boardstatus(rx,ry)==2%¸ÃλÖÃÒѾÓÐÆå×Ó
continue;
end
if ~ischange(boardstatus,rx,ry,qishou)
continue;
end
posflag = 0;
end
if qishou==1