Connect 4 Initializing the board
Mostra commenti meno recenti
Worked on / edited the code (this is what I came up with so far, don't know how to put it into code though):
clear;
close all;
clc;
N = 3
K = 4
boardInit = initializeBoard(N, K);
function [M, turn] = initializeBoard(N, K)
M = zeros(N+2,N+3) % Creates the board
% 1 Generate random column value
% 2 Check if the column doesn't already have K / N+3 (since uniform destr. in width) pieces
% 3 Check if the bottom most row already has a piece (so a value of 1 or 2)
% 4 If no piece, add value of 1 or 2 randomly (there should be an equal amount of pieces be added in the end (K red pieces and K yellow pieces)
% 5 If there is a piece, move one row up and check from step 3 again
% Repeat from 1 - 5
turn = randi(2,1,1)
end
How would I go about adding random yellow or red pieces (ones and twos) to the board. They have to start at the bottom (to simulate gravity, irl they would fall down too) and have to be randomly distributed.
I don't need a whole piece of code, just an idea of what I could use. All help is greatly appreciated!
Risposta accettata
Più risposte (1)
Categorie
Scopri di più su Board games in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!