Is there it possible to create a function that checks for the best next move in this Connect N game?
Mostra commenti meno recenti
Input:
M = [0,0,0,0,0,0,0;0,0,0,1,0,0,0;0,2,1,2,0,0,0;0,1,1,1,0,0,0;2,2,1,1,2,0,0;1,2,1,2,1,1,2]
Visualized:
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 2 0 2 0 0 0
0 1 1 1 0 0 0
2 2 1 1 2 0 0
1 2 1 2 1 1 2
Is there it possible to create a function that checks for the best next move in this Connect N game (in this case N = 4)
A connect N occurs when N pieces line up horizontally, vertically or diagonally.
This is the function that I'm using to check for victories, this might help, but I wouldn't know how to use this for that purpose myself:
function victory = checkVictory(M, N);
victory = 0;
checkWin = @(x)conv2(x,eye(N),'same')>=N | conv2(x,flipud(eye(N)),'same')>=N | conv2(x,ones(N,1),'same')>=N | conv2(x,ones(1,N),'same')>=N;
teamOne = checkWin(M == 1);
teamTwo = checkWin(M == 2);
if any(teamOne(:)) == 1
victory = 1;
elseif any(teamTwo(:)) == 1
victory = 2;
end
end
Risposta accettata
Più risposte (0)
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!