%%initialize the board
board = -ones(8, 8);
board(4, 4) = 1;
board(5, 5) = 1;
board(4, 5) = 0;
board(5, 4) = 0;

%%initialize the figure for drawing
close all
figure
axis equal off
ylim([0.5 8.5]);
xlim([0.5 8.5]);
set(gca,'Color',[0.5 0.5 0.5]);

drawBoard(board);
gameEnd = false;
color = 0;
nFailure = 0;
pauseTime = 0.2;
%%game loop
while ~gameEnd 
    drawnow;    
    pause(pauseTime);
    [r, c] = pickNewPosition(board, color);
    if r>0 && c>0
        board = placeNewDisk(board, r, c, color);        
        nFailure = 0;
    else
        nFailure = nFailure + 1; 
    end  
    drawBoard(board);
    color = 1 - color;
    if nFailure == 2
        gameEnd = true;
    end
end


