CONNECT 4 GAME FILE
%% Program Setup clc clear close all %% Introduction %Informative message giving rules and mechanics. fprintf('Welcome to Connect Four in MATLAB by Team J!\n\n This is a two player game, meaning you need a friend to play it!\n\nJust match four of your color horozontally, vertically, or diagonaly to win!\n\n If you misclick or try to place a coin on a spot without\nanother coin below it, you will be punished by losing your turn!\n\n Place carefully! \n\n Good luck, and thank you for playing!\n\n The Black player starts first!\n\n') %% Scene Setup Jscene=simpleGameEngine('ConnectFour.png',86,101); %Initialize Scene. %Set up sprite variable names. %Sprite names given based on placement in "ConnectFour.png". empty=1; red=2; black=3; %Display Empty Board. global disboard %disboard is shorthand for displayed board. disboard = empty * ones(6,7); %Fill the displayed board with empty sprites. drawScene(Jscene,disboard) %draw the empty sprites onto the gamescene. win=0; %Create win condition. playc = black; %Set the current player color to black, black will go first. %% Game while win==0 % While the win condition is unmet, continue the loop tic %% Getting player placement input %Getting player input. [r,c]=getMouseInput(Jscene); %upon a click on the displayed board, index the row(r) and column(c) that the click was located in %% Clearing command window %Clearing the command window every .1 seconds, upon click. %This only happens while win is 0. elapsedTime = toc; if elapsedTime >= .1 clc end %% Checking Effect of "Gravity" if disboard(r,c) == 1 % If the coin is placed in the bottom row, place the player's coin. if r==6 disboard(r,c)= playc; drawScene(Jscene,disboard) %Alternate the player turn. if playc == black playc = red; fprintf('Red Players Turn\n\n') %Display who's turn it is. elseif playc == red playc = black; fprintf('Black Players Turn\n\n') %Display who's turn it is. end else %If there is a coin below the choice of the player, place the player's coin. if disboard(r+1,c) == 2 || disboard(r+1,c) == 3 disboard(r,c)= playc; drawScene(Jscene,disboard) %Alternate the player turn. if playc == black playc = red; fprintf('Red Players Turn\n\n') %Display who's turn it is. elseif playc == red playc = black; fprintf('Black Players Turn\n\n') %Display who's turn it is. end else %Else, punish the player by removing their chance to play that move. fprintf('You cannot place your coin ontop of an empty space. Next Players turn. \n\n') %Alternating player turn. if playc == black playc = red; fprintf('Red Players Turn\n\n') %Display who's turn it is. elseif playc == red playc = black; fprintf('Black Players Turn\n\n') %Display who's turn it is. end end end else %Punishing player for not thinking about the move. fprintf('You cannot play a coin in an already filled spot. Next Players Turn. \n\n') %Checking if the board is full. %Filling the board sums to 105 everytime, so if the sum is 105, the board is full. summdis = sum(sum(disboard)); if summdis == 105 fprintf('The board is full. It is a tie! Well played!\n\n') win = 1; %Exit the while loop if the condition is met. end %Alternating player turn. if playc == black playc = red; fprintf('Red Players Turn\n\n') %Display who's turn it is. elseif playc == red playc = black; fprintf('Black Players Turn\n\n') %Display who's turn it is. end end %% Checking win conditions %Each function checks a specific direction upon placement of the coin. %A horizontal victory is checked using the Checkright, Checkleft, Checkmid1, and Checkmid2 functions. %A vertical victory is checked using the Checkup, Checkdown, Checkmid3, and Checkmid4 functions. %A diagonal victory is checked using the Checkleftup, Checkrightup, Checkleftdown, Checkrightdown, Checkmid5, Checkmid6, Checkmid7, and Checkmid8 functions. %Once a function detects a victory, the win condition is set to one, and the while loop is ended. %Each function works for both the black player and the red player. if r == 6 && c == 1 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c); end if r == 6 && c == 2 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid1(r,c); end if r == 6 && c == 3 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid1(r,c) || Checkmid2(r,c); end if r == 6 && c == 4 win = Checkright(r,c) || Checkleft(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkleftup(r,c) || Checkmid1(r,c) || Checkmid2(r,c); end if r == 6 && c == 5 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid1(r,c) || Checkmid2(r,c); end if r == 6 && c == 6 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid2(r,c); end if r == 6 && c == 7 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c); end if r == 5 && c == 1 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid3(r,c); end if r == 5 && c == 2 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid1(r,c) || Checkmid3(r,c) || Checkmid5(r,c); end if r == 5 && c == 3 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid5(r,c) || Checkmid8(r,c); end if r == 5 && c == 4 win = Checkright(r,c) || Checkleft(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkleftup(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid5(r,c) || Checkmid8(r,c); end if r == 5 && c == 5 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid8(r,c) || Checkmid5(r,c); end if r == 5 && c == 6 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid8(r,c); end if r == 5 && c == 7 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid3(r,c); end if r == 4 && c == 1 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid3(r,c) || Checkmid4(r,c); end if r == 4 && c == 2 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid1(r,c) || Checkmid3(r,c) || Checkmid5(r,c) || Checkmid4(r,c) || Checkmid7(r,c); end if r == 4 && c == 3 win = Checkright(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid5(r,c) || Checkmid6(r,c) || Checkmid7(r,c) || Checkmid8(r,c); end if r == 4 && c == 4 win = Checkright(r,c) || Checkleft(r,c) || Checkup(r,c) || Checkrightup(r,c) || Checkleftup(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid5(r,c) || Checkmid6(r,c) || Checkmid7(r,c) || Checkmid8(r,c); end if r == 4 && c == 5 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid5(r,c) || Checkmid6(r,c) || Checkmid7(r,c) || Checkmid8(r,c); end if r == 4 && c == 6 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid6(r,c) || Checkmid8(r,c); end if r == 4 && c == 7 win = Checkleft(r,c) || Checkup(r,c) || Checkleftup(r,c) || Checkmid3(r,c) || Checkmid4(r,c); end if r == 3 && c == 1 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid3(r,c) || Checkmid4(r,c); end if r == 3 && c == 2 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid1(r,c) || Checkmid3(r,c) || Checkmid5(r,c) || Checkmid4(r,c) || Checkmid7(r,c); end if r == 3 && c == 3 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid5(r,c) || Checkmid6(r,c) || Checkmid7(r,c) || Checkmid8(r,c); end if r == 3 && c == 4 win = Checkright(r,c) || Checkleft(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkleftdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid5(r,c) || Checkmid6(r,c) || Checkmid7(r,c) || Checkmid8(r,c); end if r == 3 && c == 5 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid5(r,c) || Checkmid6(r,c) || Checkmid7(r,c) || Checkmid8(r,c); end if r == 3 && c == 6 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid2(r,c) || Checkmid3(r,c) || Checkmid4(r,c) || Checkmid6(r,c) || Checkmid8(r,c); end if r == 3 && c == 7 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid3(r,c) || Checkmid4(r,c); end if r == 2 && c == 1 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid4(r,c); end if r == 2 && c == 2 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid1(r,c) || Checkmid4(r,c) || Checkmid7(r,c); end if r == 2 && c == 3 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid4(r,c) || Checkmid7(r,c) || Checkmid6(r,c); end if r == 2 && c == 4 win = Checkright(r,c) || Checkleft(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkleftdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid4(r,c) || Checkmid6(r,c) || Checkmid7(r,c); end if r == 2 && c == 5 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c) || Checkmid4(r,c) || Checkmid6(r,c) || Checkmid7(r,c); end if r == 2 && c == 6 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid2(r,c) || Checkmid4(r,c) || Checkmid6(r,c); end if r == 2 && c == 7 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid4(r,c); end if r == 1 && c == 1 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c); end if r == 1 && c == 2 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid1(r,c); end if r == 1 && c == 3 win = Checkright(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c); end if r == 1 && c == 4 win = Checkright(r,c) || Checkleft(r,c) || Checkdown(r,c) || Checkrightdown(r,c) || Checkleftdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c); end if r == 1 && c == 5 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid1(r,c) || Checkmid2(r,c); end if r == 1 && c == 6 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c) || Checkmid2(r,c); end if r == 1 && c == 7 win = Checkleft(r,c) || Checkdown(r,c) || Checkleftdown(r,c); end end %% Displaying Winner % The color of the last coin placed dictates what string is placed into the win message. clc if playc == 2 %If the black player placed last, the winner's color is black. winc = 'Black'; elseif playc == 3 %If the red player placed last, the winner's color is red. winc = 'Red'; end fprintf('Congratulations %s Player! You won!',winc) %Display win message.
FUNCTION CHECKUP
function [win] = Checkup(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c) == 2 if disboard(r-2,c) == 2 if disboard(r-3,c) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c) == 3 if disboard(r-2,c) == 3 if disboard(r-3,c) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKDOWN
function [win] = Checkdown(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r+1,c) == 2 if disboard(r+2,c) == 2 if disboard(r+3,c) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r+1,c) == 3 if disboard(r+2,c) == 3 if disboard(r+3,c) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKLEFT
function [win] = Checkleft(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r,c-1) == 2 if disboard(r,c-2) == 2 if disboard(r,c-3) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r,c-1) == 3 if disboard(r,c-2) == 3 if disboard(r,c-3) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKRIGHT
function [win] = Checkrightup(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c+1) == 2 if disboard(r-2,c+2) == 2 if disboard(r-3,c+3) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c+1) == 3 if disboard(r-2,c+2) == 3 if disboard(r-3,c+3) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKRIGHTUP
function [win] = Checkrightup(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c+1) == 2 if disboard(r-2,c+2) == 2 if disboard(r-3,c+3) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c+1) == 3 if disboard(r-2,c+2) == 3 if disboard(r-3,c+3) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKLEFTUP
function [win] = Checkleftup (r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c-1) == 2 if disboard(r-2,c-2) == 2 if disboard(r-3,c-3) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c-1) == 3 if disboard(r-2,c-2) == 3 if disboard(r-3,c-3) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKRIGHTDOWN
function [win] = Checkrightdown (r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r+1,c+1) == 2 if disboard(r+2,c+2) == 2 if disboard(r+3,c+3) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r+1,c+1) == 3 if disboard(r+2,c+2) == 3 if disboard(r+3,c+3) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKLEFTDOWN
function [win] = Checkleftdown (r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r+1,c-1) == 2 if disboard(r+2,c-2) == 2 if disboard(r+3,c-3) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r+1,c-1) == 3 if disboard(r+2,c-2) == 3 if disboard(r+3,c-3) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID1
function [win] = Checkmid1(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r,c-1) == 2 if disboard(r,c+1) == 2 if disboard(r,c+2) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r,c-1) == 3 if disboard(r,c+1) == 3 if disboard(r,c+2) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID2
function [win] = Checkmid2(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r,c+1) == 2 if disboard(r,c-1) == 2 if disboard(r,c-2) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r,c+1) == 3 if disboard(r,c-1) == 3 if disboard(r,c-2) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID3
function [win] = Checkmid3(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r+1,c) == 2 if disboard(r-1,c) == 2 if disboard(r-2,c) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r+1,c) == 3 if disboard(r-1,c) == 3 if disboard(r-2,c) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID4
function [win] = Checkmid4(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c) == 2 if disboard(r+1,c) == 2 if disboard(r+2,c) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c) == 3 if disboard(r+1,c) == 3 if disboard(r+2,c) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID5
function [win] = Checkmid5(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r+1,c-1) == 2 if disboard(r-1,c+1) == 2 if disboard(r-2,c+2) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r+1,c-1) == 3 if disboard(r-1,c+1) == 3 if disboard(r-2,c+2) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID6
function [win] = Checkmid6(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c+1) == 2 if disboard(r+1,c-1) == 2 if disboard(r+2,c-2) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c+1) == 3 if disboard(r+1,c-1) == 3 if disboard(r+2,c-2) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID7
function [win] = Checkmid7(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r-1,c-1) == 2 if disboard(r+1,c+1) == 2 if disboard(r+2,c+2) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r-1,c-1) == 3 if disboard(r+1,c+1) == 3 if disboard(r+2,c+2) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end
FUNCTION CHECKMID8
function [win] = Checkmid8(r,c) %Uses relative position based on where the player clicked to decide if the player won. global disboard %Gets display board data from the game file. if disboard(r,c) == 1 %If the tile is still empty, the check does not commence. win=0; end %Checks the respective direction for both the black and the red. if disboard(r,c) == 2 if disboard(r+1,c+1) == 2 if disboard(r-1,c-1) == 2 if disboard(r-2,c-2) == 2 win = 1; else win = 0; end else win = 0; end else win = 0; end end if disboard(r,c) == 3 if disboard(r+1,c+1) == 3 if disboard(r-1,c-1) == 3 if disboard(r-2,c-2) == 3 win = 1; else win = 0; end else win = 0; end else win = 0; end end end