Subroutine anaylsis Flashcards
(35 cards)
What data type does the GetIndexOfSquare subroutine return?
Int
What parameters does the GetIndexOfSquare subroutine take in?
int SquareReference
What is the squareReference variable?
- A two digit number where the 1st integer is the row of the grid and the second is the column
- It references a square on the grid
How is squareReference calculated?
Row*10 + column
Is Squarerefernce Internal or user facing and why?
It is user facing because SR is how the user interacts with the program by entering the square row and then the column.
What is the returned by GetIndexOfSquare?
An int value that is the index of the square in the list of squares.
How are the squares mapped to the List board?
The squares are mapped sequentially and go from left to right.
What is the purpose of the GetIndexOfSquare subroutine?
To convert a square location to its index the the List board.
How does the GetIndexOfSquare sub work?
It works by extracting the row and the column by using using Mod and div.
It then calculates the index by : (row -1) * 10 + column-1
What are the limitations of the board size?
The board cannot have more than 9 columns
What is the parameter for the CheckSquareInbounds sub?
int squareReference
What is the return value for CheckSquareInbounds?
A bool value that realates to whether the SR passed is is a valid square or not
What is the purpose of the CheckSquareInbounds sub?
It is to verify if the SR inputed by the user is a square that exists on the board
How does the CheckSquareInbounds sub work?
It first calculates the row and column values of the SR.
IF the row value is less than 1 or greater than the number of rows then false is returned
if the column value is less than 1 or greater than the number of columns then false is returned
else true is returned
What is the return value for CheckifGameOver?
- Bool value
- relates to whether the game has finished or not
How does the CheckifGameOver sub work?
It checks each sqaure for the following:
* If the current square is a kotla and if it is occupied by the opposing players mirza; if true then return true;
* If the current square contains a mirza and who it belongs two
if true it sets the playerhasmirza value to true
* The subroutine returns the Nand value of p1mirza and p2mirza
What are the parameters for CheckSquareIsValid?
int squareReference, Bool startSquare
What is Bool startSquare?
A bool value that represents whether the square that is being checked is the first square or the destination square
What is the return value of CheckSquareIsValid?
A Boo value that represnts whether the square that is passed is a validsquare for its given purpose. e.g if the selected square can be a start square
How does CheckSquareIsValid work?
- It first checks if the square is in bounds.
- If not then false is returned
- then it checks if there is a piece occupying the square. If the square is empty then it can not be a start square and vice versa
- if the square is occupied by a piece that belongs to the current player it can only be a start square
- if the square is occupied by a piece that belongs to the other player then it can not be a start square
What is the purpose of createBoard?
To create the board for the game
How does CreateBoard work?
- It works by using a nested for loop with limits to the number of rows || columns depending on the loop to check which squares are to whose kotlas.
- When these squares are found they are assigned to each player
- every other square is just a normal square
- The squares are then added to the list
What is the parameter for CreateRyottMoveOption?
int direction
What is the direction variable
Direction is an int value that specifies what way up the board a peice should move. Positive is going from top to bottom so the direction for p1 is 1