连接四个matlab
好的,现在我正试图通过Matlab编码创建一个连接四的游戏;现在这个游戏还很幼稚,但我的问题是,我要么无法在每个方格中绘制图形,要么根本无法绘制“圆形”图形。请尽可能地帮助我。此外,如果有人知道任何连接四个matlab教程,将不胜感激连接四个matlab,matlab,Matlab,好的,现在我正试图通过Matlab编码创建一个连接四的游戏;现在这个游戏还很幼稚,但我的问题是,我要么无法在每个方格中绘制图形,要么根本无法绘制“圆形”图形。请尽可能地帮助我。此外,如果有人知道任何连接四个matlab教程,将不胜感激 function [] = Kinect4(nrRows, nrCols) board = zeros(nrRows, nrCols); nrMoves = 0; set(gca, 'xlim', [0 nrCols]);
function [] = Kinect4(nrRows, nrCols)
board = zeros(nrRows, nrCols);
nrMoves = 0;
set(gca, 'xlim', [0 nrCols]);
set(gca, 'ylim', [0 nrRows]);
for r = 1 : 1 : nrRows - 1
line([0, nrCols], [r, r], ...
'LineWidth', 4, 'Color', [0 0 1]);
end
for c = 1 : 1 : nrCols - 1
line([c, c], [0, nrRows], ...
'LineWidth', 4, 'Color', [0 0 1]);
end
DrawBoard(nrRows, nrCols)
hold on;
while nrMoves < nrRows * nrCols %Computes ability to move polygon
[x, y] = ginput(1);
r = ceil(y); % convert to row index
c = ceil(x); % convert to column index
angles = 0 : 1 : 360;
x = cx + r .* cosd(angles);
y = cy + r .* sind(angles);
plot(x, y, 'Color', [1 1 1], 'LineWidth', 3);
axis square;
end
end
function[]=Kinect4(nrRows,nrCols)
电路板=零(nrRows,NRCOL);
nr=0;
集合(gca,'xlim',[0 nrCols]);
集合(gca,'ylim',[0行];
对于r=1:1:nR行-1
行([0,nrCols],[r,r]。。。
'线宽',4'颜色',[01]);
结束
对于c=1:1:nrCols-1
行([c,c],[0,nrRows]。。。
'线宽',4'颜色',[01]);
结束
绞车(nrRows、nrCols)
等等
nrMoves
以下是对代码的一些修复
绘图板(nrRows,nrCols)
。不确定您是否将其作为注释放在那里,因为您已经绘制了图板,或者DrawBoard
是否是一个单独的函数r
和c
的计算,以给出要插入销钉的单元格的中心。这是通过从每个值中减去0.5来实现的李>
x=cx+r.*cosd(角度)代码>至x=c+0.5*cosd(角度)代码>。在前一个例子中,变量cx
未定义,我使用0.5
代替r
作为桩的半径,您可以用适当的变量替换它。但是,我们的想法是画一个半径为0.5
的圆(以便它适合一个单元格),中心偏移量为c
。y
的类似更改可使销钉沿y轴偏移李>
将绘图
命令中的颜色更改为[0]
,颜色为黑色<代码>[1]
为白色,无法在白色背景上看到:)。我建议用'k'
表示黑色,用'b'
表示蓝色等等。有关基本颜色规范,请参见matlab文档
function[]=Kinect4(nrRows,nrCols)
电路板=零(nrRows,NRCOL);
nr=0;
集合(gca,'xlim',[0 nrCols]);
集合(gca,'ylim',[0行];
对于r=1:1:nR行-1
行([0,nrCols],[r,r]。。。
'线宽',4'颜色',[01]);
结束
对于c=1:1:nrCols-1
行([c,c],[0,nrRows]。。。
'线宽',4'颜色',[01]);
结束
轴线广场;
等等
nrMoves
非常感谢您的帮助。我的下一个问题是如何实现重力并检查电池是否已经充满?我不需要确切的编码,但是如果能告诉我如何做,我将非常感激。@FunnyBro777有很多方法可以做到这一点。一种直观的方法是使用板
martix跟踪已填充的单元格。因此,如果一个单元格被占用,相应的元素将不为零。当玩家进入下一步时,ginput
只关心列(x
)的位置,并替换board
矩阵中该列的最后一个零元素。您可以将其翻转为1或2,以跟踪哪个玩家进行了移动。另一个选项是使用行向量,每次玩家进行移动时,只需将相应的列增加1。你不需要立即画出玩家的动作,因为没有办法跟踪所做的动作。好吧,你的解释比我一直在读/研究的更有意义。非常感谢你的帮助
function [] = Kinect4(nrRows, nrCols)
board = zeros(nrRows, nrCols);
nrMoves = 0;
set(gca, 'xlim', [0 nrCols]);
set(gca, 'ylim', [0 nrRows]);
for r = 1 : 1 : nrRows - 1
line([0, nrCols], [r, r], ...
'LineWidth', 4, 'Color', [0 0 1]);
end
for c = 1 : 1 : nrCols - 1
line([c, c], [0, nrRows], ...
'LineWidth', 4, 'Color', [0 0 1]);
end
axis square;
hold on;
while nrMoves < nrRows * nrCols %Computes ability to move polygon
[x, y] = ginput(1);
r = ceil(y) - 0.5;
c = ceil(x) - 0.5;
angles = 0 : 1 : 360;
x = c + 0.5*cosd(angles);
y = r + 0.5*sind(angles);
plot(x, y, 'Color', [0 0 0], 'LineWidth', 3);
end
end