Posts

Welcome!

Table of Contents

  • Business Plan
    • Interview 1
    • Interview 2
    • Advertisement Link
    • SDP Video Link
  • Project Management
    • Teammate Agreement/Individual Work Agreement
    • Project Schedule
    • Meeting Notes
  • Software Documentation
    • Introduction
    • User Manuel
    • Program Description
    • Algorithms
    • Final Program with Comments
    • Discussion
    • Conclusion/recommendation
    • References

 

Executive Summary

EXECUTIVE SUMMARY

The team was tasked with creating one or more digital games using the coding skills they had recently developed. Coding and programing is one of the most important areas of engineering especially since things are almost entirely digitalized today, it is critical to know how programs work and depending on the profession, how to make them. The team chose two games, the easier, more simplistic game, hangman, and the more complex game Othello, which the remainder of the website will be focusing on as the primary game.

First, the team set out to figure out what games would be the best to make, and the decision was to go with Hangman and Othello. From there, the process of creating the games began, with each member partaking in the coding to some extent. Naturally, the better coders with more experience were better suited for the task and wound up doing more than their share of the work. Things evened out however through the documentation where the other members stepped up. Throughout the process of the creation of the game, the team was meeting up, discussing the project, and working on some of the aspects of the documentation like the user interviews and the algorithms. Towards the end, the group worked more on the website and the polishing up of the documentation rather than working on the game itself, which was completed earlier. Finally, the group made an online advertisement and sales pitch video introducing the team and why people should buy it.

Othello and Hangman are both excellent games, and it is with complete confidence that if a consumer wishes to have a pleasant experience with a quality game, there is no better way to go than Group Q’s rendition of these two classics.

Functions and variables for Othello

Variables:

Othelo % the matrix representtation of the othello board
this is true for all instances even within function

Othelo_test % the matrix representation of the othelo board surrounded by empty slots (0`s) used for testing purposes if move legal etc
this is true for all instances even within function

player % the player currently playing switches to winner at end of program

legal % true or false if the move is legal

x % the x coordinate
this is true for all instances even within function
y % the y coordinate
this is true for all instances even within function

i % i is a for loop iterator
j % j is a for loop iterator

small_Othelo % the othello board in this function

BEEG_Othelo % larger board used for testing etc

playerNum & the player currently playing

proper % true or false if the move is legal

Big_othelo % larger testing board same as othello test
this is true for all instances of Big_othello

Othelo_works % returns the larger testing board to othelo_test

Prow % is the row on the larger board that is passed through the check functions
this is true for all instances of Prow

Pcol % is the col on the larger board that in passed through the check functions
this is true for all instances of Pcol

row % row is the row that the function is checking in various check function
this is true for all instances of row

col % col is the collumn that the function is checking in various check functions
this is true for all instances of row

flip % determines whether or not to flip pieces in a check function

Othelo % Othelo is the returned larer othello board for tedsting
this is true for all instances of Othelo

newOthelo % updates the smaller board based on the larger testing board

GameOver % true or false if the game is over

count1 % the number of pices player one has
count2 % the number of pieces player two has

Board % is the matrix representing othelo game board that is passed through

player % is the player playing

______________________________________________________________________________
Functions:
function [x,y] = location(play)
% gets the location the player wants to play
play is the player within the funciton
function [proper,x,y] = is_legal(small_Othelo,BEEG_Othelo,x,y,playerNum)
%% is_legal determines if a legal move is made
function [Othelo,Othelo_test] = resetBoard()
%% sets the board ti the standard pre-game position
function [Othelo_works] = checkMoves(Big_othelo,y,x)
%% Check moves calls the the check: up down left etc function to
initiate changes to the board from capturing pices
function [Othelo] = checkUp(Big_othelo ,Prow , Pcol)
%% check the up switches
function [Othelo] = checkDown(Big_othelo ,Prow , Pcol)
%% check the down switches
function [Othelo] = checkLeft(Big_othelo ,Prow , Pcol)
%% check the left switches
function [Othelo] = checkRight(Big_othelo ,Prow , Pcol)
%% check the right switches
function [Othelo] = checkUpRight(Big_othelo ,Prow , Pcol)
%% check the up right switches
function [Othelo] = checkUpLeft(Big_othelo ,Prow , Pcol)
%% check the up left switches
function [Othelo] = checkDownLeft(Big_othelo ,Prow , Pcol)
%% check the down left switches
function [Othelo] = checkDownRight(Big_othelo ,Prow , Pcol)
%% check the down Right switches
function [newOthelo] = update(Othelo
%% update updates the othelo board based on the othelo test
function [GameOver, player] = endGame(Board, playerNum)
%% endGame determines if the game is over and if so who the winner is

Othello Discussion

When the idea of creating an Othello game on Matlab was first introduced, some of the group was not too sure about it because we had never heard of or played the game, but two members had heard about and played it and they were fully confident in their abilities to create the game and teach us what the game is and how to play along the way. In order for the game to exist, there must be a board, so an array was created that was eight by eight with two one’s in the center and two two’s also in the center that were in a square, with the matching numbers diagonal to each other. Two players are necessary to play this game, or just one person controlling the inputs of both player 1 and player 2. To begin building the code, the first thing to do was create the array for the board. The next thing that had to be done was to have the program automatically fill in the middle four spaces of the board with two spaces for each player. The next step of the code is to ask a player for their input, requesting an x coordinate and then the y coordinate. The first time the game was tested, it became apparent that the program was not successfully having the team with more of the board filled win, so that portion of the code had to be tweaked. After that the testing went relatively smooth, there were multiple people that tested the game, and all tests succeeded once that tweak was complete.

User Manual Othello

To begin playing Othello, the code must be ran in Matlab. The game will create a board for the game that is 8×8 with the center four spaces already filled with two spaces for each player, with spaces of the same number being diagonal to each other. The game will then prompt player two for their first input, which will be an x coordinate, then it will ask for a y coordinate. Once the player has given the program an input, the program will test if the input given is on the board, if it is on the board it will test if it is adjacent to another space that is already filled, as all moves must be made on adjacent spaces to a filled one, then it will test if it is a space that has already been taken, if the input from the player is either on a filled space, in a non adjacent space, or off the board the program will request another input until the player gives a valid input. The program will then take the valid input and place it on the board and test if there are any opposing player spaces between that new space and any other friendly space in the same row or column, and if there is, they will be switched to the same number as the player who just made the move. After the first player makes their move, the program will prompt the other player for their move, and run through the same tests. Once the game has gone back and forth until the entire board is filled, the program adds up how many of each number appears on the board, and the player with the most of the board with their number wins, and the program prints out the winner.

Final Program with comments

Othello

%%

clear
clc

fprintf(‘Welcome to Othello! \n’)
fprintf(‘\nPlayer 1 will be the Black Team \n’)
fprintf(‘\nPlayer 2 will be the White Team \n’)
fprintf(‘\nThe black team will go first \n’)
fprintf(‘\nThe board will start with a set of crossed black and white pieces in the center.’)
fprintf(‘\nEach piece played must be laid adjacent to an another piece, surrounding an oppenents pieces on two adjacent sides will reasult \nin the capturing of the opponents pieces within your pieces.’)
fprintf(‘\ncaptured pieces will flip and change to your color.’)
fprintf(‘\nIt can happen that a piece is played so that pieces or rows of pieces in more than one direction \nare trapped between the new piece played and other pieces of the same color. In \nthis case, all the pieces in all viable directions change color \n’)
fprintf(‘\nThe game is over when neither player has a legal move ie: when the board is full. \n’)

[Othelo,Othelo_test] = resetBoard();
Othelo
player = 1;
while(true)
legal = false;
while(~legal)
[x,y] = location(player);
[legal,x,y] = is_legal(Othelo,Othelo_test,x,y,player);
end

Othelo(y,x) = player;
Othelo_test(y+1,x+1) = player;
Othelo_test = checkMoves(Othelo_test, y+1, x+1);
Othelo = update(Othelo_test) % this is the board after all proper adjustments are made, and what the sprites should represent
[gameOver,player] = endGame(Othelo, player);
if(gameOver)
break;
end
player = mod(player*2,3);
end
fprintf(“Player %i Wins!”, player)
%%
function [x,y] = location(play)
fprintf(“Player %i your move\n”,play)
x = input(‘Enter the x coordinet ‘);
y = input(‘Enter the y coordinet ‘);
while(x>8||y>8||x<1||y<1)
fprintf(“You must input coordinetes within the board\n”)
x = input(‘Enter the x coordinet ‘);
y = input(‘Enter the y coordinet ‘);
end
end
%% is_legal determines if a legal move is made
function [proper,x,y] = is_legal(small_Othelo,BEEG_Othelo,x,y,playerNum)
proper = false;
while (BEEG_Othelo(y+1,x+1)~=0)
fprintf(“you must place a piece in an empty slot\n”)
[x,y] = location(playerNum);
end

if(BEEG_Othelo(y+1 +1,x+1)~=0) % checks up
proper = true;
end
if(BEEG_Othelo(y+1 -1,x+1)~=0) % checks down
proper = true;
end
if(BEEG_Othelo(y+1,x+1 – 1)~=0) % checks left
proper = true;
end
if(BEEG_Othelo(y+1,x+1 + 1)~=0) % checks right
proper = true;
end
if(BEEG_Othelo(y+1 +1,x+1 +1)~=0) % checks up right
proper = true;
end
if(BEEG_Othelo(y+1 -1,x+1 +1)~=0) % checks down right
proper = true;
end
if(BEEG_Othelo(y+1 +1,x+1 -1)~=0) % checks up left
proper = true;
end
if(BEEG_Othelo(y+1 -1,x+1 -1)~=0) % checks down left
proper = true;
end
if(proper == false)
fprintf(“you must place your piece next to an exsisting piece\n”)
end
end
%% Resets the board to start with a b&w cross in the center needs an edit
% edit needed: should let the players pick the first four spots
function [Othelo,Othelo_test] = resetBoard()
boardSize = 8;
Othelo = [0,0];
for i = 1:boardSize
for j = 1:boardSize
Othelo(i,j) = 0;
end
end
Othelo(4,4) = 1;
Othelo(5,5) = 1;
Othelo(5,4) = 2;
Othelo(4,5) = 2;
Othelo_test = [0,0];

for i = 1:9
for j = 1:9
Othelo_test(i+1,j+1) = 0;
if(i<9&&j<9)
Othelo_test(i+1,j+1) = Othelo(i,j);
end
end
end
end
%% Check moves calls the the check: up down left etc function to initiate changes to the board
function [Othelo_works] = checkMoves(Big_othelo,y,x)

Big_othelo = checkUp(Big_othelo ,y , x);
Big_othelo = checkDown(Big_othelo ,y , x);
Big_othelo = checkLeft(Big_othelo ,y , x);
Big_othelo = checkRight(Big_othelo ,y , x);
Big_othelo = checkUpRight(Big_othelo ,y , x);
Big_othelo = checkUpLeft(Big_othelo ,y , x);
Big_othelo = checkDownRight(Big_othelo ,y , x);
Big_othelo = checkDownLeft(Big_othelo ,y , x);
Othelo_works = Big_othelo;

end
%% check the up moves
function [Othelo] = checkUp(Big_othelo ,Prow , Pcol)
row = Prow-1;
col = Pcol;
flip = false;
while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
row = row-1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow-1;
col = Pcol;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
row = row – 1;
end
Othelo = Big_othelo;
end
%% Check the down moves
function [Othelo] = checkDown(Big_othelo ,Prow , Pcol)
row = Prow+1;
col = Pcol;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
row = row+1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow+1;
col = Pcol;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
row = row + 1;
end
Othelo = Big_othelo;
end

%% check the left moves
function [Othelo] = checkLeft(Big_othelo ,Prow , Pcol)
row = Prow;
col = Pcol – 1;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
col = col-1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow;
col = Pcol – 1;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
col = col – 1;
end
Othelo = Big_othelo;
end
%% check the right moves
function [Othelo] = checkRight(Big_othelo ,Prow , Pcol)
row = Prow;
col = Pcol + 1;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
col = col+1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow;
col = Pcol + 1;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
col = col + 1;
end
Othelo = Big_othelo;
end
%% check the up right moves
% after this function the code may contain errors, will check later
function [Othelo] = checkUpRight(Big_othelo ,Prow , Pcol)
row = Prow – 1;
col = Pcol + 1;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
row = row – 1;
col = col+1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow – 1;
col = Pcol + 1;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
col = col + 1;
row = row – 1;
end
Othelo = Big_othelo;
end
%% check the up right moves
function [Othelo] = checkUpLeft(Big_othelo ,Prow , Pcol)
row = Prow – 1;
col = Pcol – 1;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
row = row – 1;
col = col-1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow – 1;
col = Pcol – 1;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
col = col – 1;
row = row – 1;
end
Othelo = Big_othelo;
end
%% check the down Left moves
function [Othelo] = checkDownLeft(Big_othelo ,Prow , Pcol)
row = Prow + 1;
col = Pcol – 1;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
row = row + 1;
col = col – 1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow + 1;
col = Pcol – 1;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col) = Big_othelo(Prow,Pcol);
col = col – 1;
row = row + 1;
end
Othelo = Big_othelo;
end
%% check the down Right moves
function [Othelo] = checkDownRight(Big_othelo ,Prow , Pcol)
row = Prow + 1;
col = Pcol + 1;
flip = false;

while(Big_othelo(row,col)~=0 && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
row = row + 1;
col = col + 1;
if(Big_othelo(row,col) == Big_othelo(Prow,Pcol))
flip = true;
end
end
row = Prow + 1;
col = Pcol + 1;
while(flip == true && Big_othelo(row,col) ~= Big_othelo(Prow,Pcol))
Big_othelo(row,col);
Big_othelo(Prow,Pcol);

Big_othelo(row,col) = Big_othelo(Prow,Pcol);
col = col + 1;
row = row + 1;
end
Othelo = Big_othelo;
end
%% update updates the othelo board to the othelo test
function [newOthelo] = update(Othelo)
newOthelo = [0;0];
for i = 2:9
for j = 2: 9
newOthelo(i-1,j-1) = Othelo(i,j);
end
end
end
%% function end the game and decides a winner
function [GameOver, player] = endGame(Board, playerNum)
GameOver = true;
count1 = 0;
count2 = 0;
for i = 1:8
for j = 1:8
if(Board(i,j)==0)
GameOver = false;
elseif(Board(i,j)==1)
count1 = count1+1;
elseif(Board(i,j)==2)
count2 = count2+1;
end
end

end
if(GameOver)
if(count1 > count2)
player = 1;
elseif(count1 < count2)
player = 2;
end
else
player = playerNum;
end
end

Hangman

Hangman script file and gameboard:

https://docs.google.com/document/d/1W8WmhtpXC0JADzPyjNwE4qq69DdnLK1B6k2d0zj-O0w/edit

B. USER MANUAL

Othello

 

Hangman

To begin playing Hangman, run the Matlab code. The game will randomly generate one of the 36 words chosen from a word bank created on the following topics: Animals, countries, sports, sandwich toppings, colours and states. The game will then display a number of stars representing how many letters the player is required to guess, and prompt the player to guess a letter. The player will then input a letter. Depending on whether the player is correct or not, the figure gets filled up. If the player is correct, then the letter will replace the star and the player will be prompted to input another letter. If the player is incorrect, the figure slowly starts to fill, starting the head, body, etc. The player will be prompted to guess another letter. This process is repeated until the player has fully guessed the word or the player has one too many incorrect guesses and the hangman figure is complete.

Team Meeting Notes

Meeting 1 (Nov. 1)

  • location- 18th street library
  • Purpose- decide what games our group is choosing to do, and finish assigned groupwork
    • The group decides that we will do a 4 point game and a two point game to attempt to get the maximum extra credit points, but we are still undecided about whether or not we are planning on doing the paperwork for both of the games.

Meeting 2 (Nov. 8)

  • location- 18th street library
  • Purpose- Divy out the work/plan of attack, and finish assigned groupwork
    •  The group decided to play to the strengths of the members. The best coders (Shad and Phillip) would be doing the majority of the coding of the two games with the other two members (Tommy and Garrett) helping with whatever is necessary. In addition the primary coders wouldn’t be asked to do the lion’s share of the notebook in an attempt to balance the workload.

Meeting 3 (Nov. 15)

  • location- The C Store
  • purpose- One last meeting to make sure that everyone was on the same page and knew the plan of attack
    • The group decided to switch the two point game from Memory to Hangman.
    • The coding was on track to be done by the assigned due date.

User Interview #2

  1. What are some games you have played recently?
    1. Red Dead Redemption 2
    2. Call of Duty World War 2
    3. Fortnite
  2. What are some games you might enjoy playing on MATLAB?
    1. Blackjack
    2. Connect 4
    3. Mastermind
    4. Memory
  3. In your opinion what is the optimal length a game should take to play?
    1.  3 minutes or so
  4. What aspects of a game make it enjoyable to you to play?
    1. Mentally engaging/challenging
    2. Competition, either with another person or with self

Algorithms

Algorithm for Othello

  1. Each player chooses either black or white.
  2. Each player places two black and two white pieces in an alternating pattern in the middle of the board in the form of a square.
  3. Black plays first and draws a single disc and places it on a valid spot on the grid.
  4. You must place a disc on a spot that allows you to “flank” or “capture” at least one of your opponent’s discs by bordering them in a row.
  5. You must flip all captured discs to your color.
  6. To capture your opponent’s discs you must have 1 of your own pieces at the end of a row and then on your turn place a new piece at the beginning of the row. Everything in between on that row is now flipped to your color. You can only capture rows of a single color adjacent to each other; there cannot be any open space or your own discs between them or the combo is interrupted.
  7. You can flank any number of discs. You may capture discs vertically, horizontally, diagonally. You may capture in multiple directions at the same time. All discs that can be flipped must be flipped. You cannot pick and choose which ones are captured.
  8. If you cannot make a valid move then your turn is forfeited and your opponent may go again. If you have a valid move available to you then you must make that move and are not allowed to forfeit your turn.
  9. If you have run out of discs, but can still make valid moves, then your opponent must give you one of their own discs to play with. This exchange can continue for as long as needed.
  10. When neither player can make any further play then the game is over.
  11. Each player counts the number of spaces occupied by their color. Highest count is the winner. Games can end before all spaces are filled.

Hangman algorithm

  1. A random is chosen from a word bank and is represented by stars.
  2. The Player is prompted to guess a letter: if the guess is incorrect the player gets a strike. If the player guesses correctly go to step 4
  3. If the player gets 7 incorrect guesses, or 7 strikes, the player loses, go to step 8
  4. If the player guessed the word correctly, go to step 7. If the player guessed a letter correctly, go to step 5
  5. The AI will tell the player how many of the guessed letter is in the word as well as the location of each of the letters.
  6. If there are any unknown letters left go to step 2. If all letters are known go to step 7
  7. The Player Wins!!! end
  8. The player loses. end