matlab游戏编程实例(黑白棋).docVIP

  • 41
  • 0
  • 约1.03万字
  • 约 9页
  • 2019-09-06 发布于江西
  • 举报
黑白棋的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);%???ì3?ê?μ?×′ì? qishou = 1; % ?D????ê?μ???é?£??aê?μ?ê±oòê?oìé?£?è?2ê±ê?oúé? boardstatus = zeros(10);% ???ì×′ì????ó£?è?0?a??£?è?1?aoì£?è?2?aoú boardstatus([5 6],[5 6]) = [1 2;2 1]; while 1 hold on posflag = 1; % ó?óú?D????μ???ê?·?óDD§£?è?1?μ?÷??μ????TD§£?òa??D??? 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% μ?μ????ìíaá? continue end rx = floor(xpos); ry = floor(ypos); if boardstatus(rx,ry)==1|boardstatus(rx,ry)==2%??????ò??-óD??×ó continue; end if ~ischange(boardstatus,rx,ry,qishou) continue; end posflag = 0; end if qishou==1 drawthego(xpos,ypos,qishou); boardstatus(floor(xpos),floor(ypos))=1; qishou = 2; else drawthego(xpos,ypos,qishou); boardstatus(floor(xpos),floor(ypos))=2; qishou = 1; end boardstatus = change(boardstatus,rx,ry,converse(qishou));%?üD????ìD??¢ % ???-???ì for i = 1:10 for j = 1:10 if boardstatus(i,j)~=0 drawthego(i+0.5,j+0.5,boardstatus(i,j)) end end end if isempty(find(boardstatus~=0))% ???ì???úá?£??D??ê¤?o [n1,m1] = find(boardstatus==1); [n2,m2] = find(boardstatus==2); count1 = length(n1); count2 = length(n2); if count1count2 msg = [°×

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档