Software development encompasses coding whereby the variable of the game are identified as well error removal to ensure the code works. The code is modified based on the tests carried out. From the initial code, there are three elements that seem to be unincorporated and their inclusion in the code would greatly improve the game. These three elements include: list of variables, commands, as well as usage manual.
Software Documentation
The program is about a game that is played by two players. Where one player checks whether it is his turn to insert a chip into a valid column. The code for the games is
clc,clear
load(‘Connect’);
figure(‘WindowStyle’,’docked’)
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
Board2=Board;
%Creates a vector for the game board
A=zeros(6,7);
%Sets the condition that “game” is true for the while loop
Game=true;
%Runs the game until someone gets four in a row
while Game==true;
%Establishes who’s turn it is
turn=0;
%Checks if it is Player 1’s turn and prompts Player 1 to insert a chip into a valid column
if turn==0
k=0;
Guess=input(‘Player 1, please select a column:’);
if Guess>7 | Guess<1
Guess=input(‘Please select a column 1 through 7:’);
elseif Guess~=1&Guess~=2&Guess~=3&Guess~=4&Guess~=5&Guess~=6&Guess~=7
Guess=input(‘Please type an integer:’)
else
Guess=Guess;
end
%Places Player 1’s chip into a non-filled column
for k=1:6
if A(1,Guess)~=0
Guess=input(‘Please select a column that is not full:’);
end
if A(7-k,Guess)==0
A(7-k,Guess)=1;
Board(7-k,Guess)={redchip};
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
break
elseif A(7-k,Guess)==1|A(7-k,Guess)==2
k=k+1;
end
end
%Checks for verticle win for Player 1
x=1;
y=1;
for x=1:7
for y=1:3
if A(y,x)==1 & A(y+1,x)==1 & A(y+2,x)==1 & A(y+3,x)==1
fprintf(‘Player 1 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
%Checks for horizontal win for Player 1
if Game==true
x=1;
y=1;
for x=1:4
for y=1:6
if A(y,x)==1 & A(y,x+1)==1 & A(y,x+2)==1 & A(y,x+3)==1
fprintf(‘Player 1 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
end
%Checks for diagonal (up and to the right) win for Player 1
if Game==true
x=1;
y=1;
for x=1:4
for y=1:3
if A(y,x)==1 & A(y+1,x+1)==1 & A(y+2,x+2)==1 & A(y+3,x+3)==1
fprintf(‘Player 1 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
end
%Checks for diagonal (up and to the left) win for Player 1
if Game==true
x=1;
y=1;
for x=4:7
for y=1:3
if A(y,x)==1 & A(y+1,x-1)==1 & A(y+2,x-2)==1 & A(y+3,x-3)==1
fprintf(‘Player 1 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
end
%Checks for stalemate
if Game==true
if prod(A,’all’)~=0
fprintf(‘Stalemate! Game Over!’)
Game=false;
end
end
end
%Checks if it is Player 2’s turn and prompts Player 2 to insert a chip into a valid column
if turn==1
k=0;
Guess=input(‘Player 2, please select a column:’);
if Guess>7 | Guess<1
Guess=input(‘Please select a column 1 through 7:’);
elseif Guess~=1&Guess~=2&Guess~=3&Guess~=4&Guess~=5&Guess~=6&Guess~=7
Guess=input(‘Please type an integer:’)
else
Guess=Guess;
end
%Places Player 2’s chip into a non-filled column
for k=1:6
if A(7-k,Guess)==0
A(7-k,Guess)=2;
Board(7-k,Guess)={blackchip};
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
break
elseif A(7-k,Guess)==1|A(7-k,Guess)==2
k=k+1;
else
Guess=input(‘Enter a valid number:’);
end
end
%Checks for verticle win for Player 2
x=1;
y=1;
for x=1:7
for y=1:3
if A(y,x)==2 & A(y+1,x)==2 & A(y+2,x)==2 & A(y+3,x)==2
fprintf(‘Player 2 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
%Checks for horizontal win for Player 2
if Game==true
x=1;
y=1;
for x=1:4
for y=1:6
if A(y,x)==2 & A(y,x+1)==2 & A(y,x+2)==2 & A(y,x+3)==2
fprintf(‘Player 2 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
end
%Checks for diagonal (up and to the right) win for Player 2
if Game==true
x=1;
y=1;
for x=1:4
for y=1:3
if A(y,x)==2 & A(y+1,x+1)==2 & A(y+2,x+2)==2 & A(y+3,x+3)==2
fprintf(‘Player 2 Wins!’)
Game=false;
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
end
%Checks for diagonal (up and to the left) win for Player 2
if Game==true
x=1;
y=1;
for x=4:7
for y=1:3
if A(y,x)==2 & A(y+1,x-1)==2 & A(y+2,x-2)==2 & A(y+3,x-3)==2
fprintf(‘Player 2 Wins!’)
Game=false;
% P=input(‘\nPlay again? If yes, enter 1 If no, enter 2:’);
% if P==1
% Game=true;
% Board=Board2;
% imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
%
% elseif P==2
% Game=false;
% else
% P=input(‘Please enter either 1 or 2:’);
% end
else
turn = turn+1;
turn = mod(turn,2);
end
end
end
end
%Checks for stalemate
if Game==true
if prod(A,’all’)~=0
fprintf(‘Stalemate! Game Over!’)
Game=false;
end
end
end
end
% P=input(‘\nPlay again? If yes, enter 1 If no, enter 2:’);
% if P==1
% Game=true;
%
% elseif P==2
% Game=false;
% else
% P=input(‘Please enter either 1 or 2:’);
% end
list of variables
the variables are players and board
The variables of the game
In regards to being applicable to game, proper commands can be given to the game in order to ensure that it played well and remain free of any errors. If player one sends commands into an board, the games is turned on. Game commands used are shown in the code above
results of testing
Software Documentation
The program is about a game that is played use of strings and Hangman,. The code for the game is as follows
clc,clear
%% Hangman
%Display welcome message
fprintf(‘Welcome to Hangman, Have Fun’)
%Set P = 1, so that the game begins, When P does not equal 1, the game will
%register as over ( this allows for the user to play multiple games)
P = 1;
while P == 1
%List of strings, of different categories
T = input(‘\nplease pick your topic number (1)cities (2)food (3)animals: \n’);
a = [“INDIANAPOLIS”,”DENVER”,”PHILADELPHIA”,”JACKSONVILLE”,”COLUMBUS”,”NASHVILLE”,”
PORTLAND”,”LOUISVILLE”,”ALBUQUERQUE”,”PITTSBURGH”,”CINCINNATI”,”HOUSTON”,”ATLANTA”,”
AUSTIN”,”DALLAS”,”MILWAUKEE”,”TORONTO”,”SACRAMENTO”,”SEATTLE”,”CHICAGO”,”CLEVELAND”,”
BOSTON”];
b = [“PIZZA”,”MEATLOAF”,”SANDWICH”,”STEAK”,”SPAGHETTI”,”PANCAKES”,”PEPPERONI”,”POPCORN”,”
EGGPLANT”,”CANTALOUPE”,”MACARONI”,”BURRITO”,”SAUSAGE”,”CHEESESTEAK”,”CHEESEBURGER”,”
CHURRO”,”LASAGNA”,”CALAMARI”,”CAULIFLOWER”];
c = [“CHICKEN”,”TURTLE”,”JAGUAR”,”RHINOCEROS”,”CHIMPANZEE”,”HEDGEHOG”,”PANTHER”,”
OCTOPUS”,”POLARBEAR”,”KANGAROO”,”GIRAFFE”,”FLAMINGO”,”HIPPOPOTAMUS”,”PENGUIN”];
%Once a category is picked, Randomly select a number within the length of
% the string vector
while (T~=1)|(T~=2)|(T~=3)
if T == 1;
disp(‘Good choice, loading cities’)
C = randi(length(a));
break
elseif T == 2;
disp(‘Good choice, loading food’)
C = randi(length(b));
break
elseif T == 3;
disp(‘Good choice, loading animals’)
C = randi(length(c));
break
else
%This will display, if the person enters something that doesn’t align with
%a catevgory
T= input(‘Please enter a valid number:’)
end
end
%Once a random number is selected, a Word is picked from the specific string vector
if T==1;
Word=a(C);
elseif T==2;
Word=b(C);
elseif T==3;
Word=c(C);
end
%word is formulated from the components of the string
NewWord = char(Word);
word = NewWord;
list of variables
the variables are hangman and strings
In regards to being applicable to game, proper commands can be given to the game in order to ensure that it strings are used by hangman. Game commands used are shown in the code above. The results is shown below;