COMP 2160 Programming Practices
Assignment 2
Page 1 of 2
Due Date: February 24th at 11:59pm
NOTES
Please read and follow instructions carefully; not doing so will result in a loss of marks.
You must complete Honesty Declaration form digitally in UMLearn.
Your code must follow the programming standards (available in UMLearn).
You can write your code on any machines; remember to verify your code on one of the lab machines.
You must include a README file which describes how to compile and run your solution. You can
also explain your concerns or personal opinions regarding this assignment.
Use submission tool (handin) in CS Unix system as described in Assignment Submission
Guidelines (available in UMLearn).
REVERSI (OTHELLO) [20]
Download reversi_skeleton.c and rename it to reversi.c. Then, implement the incomplete
functions: checkstate(), canPlayAt(), and numReverseDirection(). Your implementation
must follow the design by contract principle. In addition, make your solution fail gracefully in production
(i.e., when assertion is disabled).
The code is to read a Reversi game board from standard input, compute the best move for a player, and print
the result to standard output. In our case, the best move refers to a move which allows the player to capture
the most opponent’s pieces. If you want to learn more about the game, you can read the Wikipedia entry
(https://en.wikipedia.org/wiki/Reversi); I have listed the game rules that you need for this assignment.
there are two players, black and white
each player can only play at the place where they capture the opponent’s piece(s)
when a piece placed, we check if there are opponent’s pieces wrapped by the player’s
o we check 8-direction (4 straights, up, down, left, right; and 4 diagonals, left-up, left-down,
right-up, right-down) by moving along on this direction
o if we found the player’s piece along the way, the opponent’s pieces in between are captured
and becomes the player’s
we get the number of captures for a specific position by adding every direction’s captures
Implementation Requirements
All following conditions must be met by your solution
boolean checkstate( const GameBoard * board )
This function should check if the given board is valid. Our valid state means
nColumns is (0, MAX_BOARD_COLUMNS), i.e., 0 < nColumns < MAX
nRows is (0, MAX_BOARD_ROWS), i.e., 0 < nRows < MAX
player is either BLACK or WHITE
boolean canPlayAt( const GameBoard * board, int row, int col )
This function should check if the opponent’s piece is around given position (i.e., check 8-direction). For
example, if current player is BLACK, you need to find out if WHITE’s piece appears as a neighbour.
COMP 2160 Programming Practices
Assignment 2
Page 2 of 2
*EDITED You also need to check if the cell (row, col) is empty; otherwise, it is unplayable cell.
int numReverseDirection( const GameBoard * board, int row, int col, int dirRow, i.
1. COMP 2160 Programming Practices
Assignment 2
Page 1 of 2
Due Date: February 24th at 11:59pm
NOTES
will result in a loss of marks.
UMLearn.
in UMLearn).
verify your code on one of the lab machines.
nclude a README file which describes how to
compile and run your solution. You can
also explain your concerns or personal opinions regarding this
assignment.
in Assignment Submission
Guidelines (available in UMLearn).
REVERSI (OTHELLO) [20]
Download reversi_skeleton.c and rename it to reversi.c. Then,
implement the incomplete
functions: checkstate(), canPlayAt(), and
numReverseDirection(). Your implementation
2. must follow the design by contract principle. In addition, make
your solution fail gracefully in production
(i.e., when assertion is disabled).
The code is to read a Reversi game board from standard input,
compute the best move for a player, and print
the result to standard output. In our case, the best move refers
to a move which allows the player to capture
the most opponent’s pieces. If you want to learn more about the
game, you can read the Wikipedia entry
(https://en.wikipedia.org/wiki/Reversi); I have listed the game
rules that you need for this assignment.
opponent’s piece(s)
wrapped by the player’s
o we check 8-direction (4 straights, up, down, left, right; and 4
diagonals, left-up, left-down,
right-up, right-down) by moving along on this direction
o if we found the player’s piece along the way, the opponent’s
pieces in between are captured
and becomes the player’s
adding every direction’s captures
Implementation Requirements
All following conditions must be met by your solution
boolean checkstate( const GameBoard * board )
This function should check if the given board is valid. Our valid
state means
3. nColumns < MAX
boolean canPlayAt( const GameBoard * board, int row, int col )
This function should check if the opponent’s piece is around
given position (i.e., check 8-direction). For
example, if current player is BLACK, you need to find out if
WHITE’s piece appears as a neighbour.
COMP 2160 Programming Practices
Assignment 2
Page 2 of 2
*EDITED You also need to check if the cell (row, col) is empty;
otherwise, it is unplayable cell.
int numReverseDirection( const GameBoard * board, int row,
int col, int dirRow, int dirCol )
This function should count and return the number of opponent’s
pieces which are wrapped in between
player’s. At the given column and row, the player’s piece is
played. You must move toward the given
direction to count the opponent pieces. Both directions must be
in range of [-1, 1]; both should not be zero at
the same time. If you could not find the player’s piece along the
given direction, the count should be zero.
BONUS [1]
If you completed this bonus question, write a note for a marker
4. in the readme file. For this bonus, update
the readGameBoard() routine to handle any error in input. The
correct input format is
o first item is the number of columns
o second item is the number of rows
o third item is either B or W which indicates who’s the player is
o each line represents each row of the board
o each character on a line represents each column of the board
o each cell is B, W, or space character
Your updated function must be able to detect incorrect input
format and return false. Use assertions to follow
the design by contract principle and help you to debug. In
addition, use safeguard to gracefully fail the process
in production. You can write any helper functions.
Paper #2
The balanced scorecard
The Balanced Scorecard
The Balanced Scorecard is a tool that offers business people a
way to translate a company’s Strategic Plan into a series of
Performance measures (Kaplan & Norton, 1992)
5. According to Kaplan and Norton (1992), the Scorecard consists
of 4 perspectives from which to choose these measures:
Customers
Shareholder/Financial processes
Innovation/Learning
Internal/Improvement activities
The Balanced Scorecard
As with Porter’s 5 Forces and SWOT Analysis, the Scorecard is
a tool that when used in combination with other financial
indicators, can inform an organization as to how well it is
performing within its market and with how well it is doing to
meet its own strategic goals.
The Scorecard can direct an organization around where it might
need to initiate change in mission critical areas - product,
processes, customer service and/or market development. Its
measures are forward looking and are based on the
organization’s strategic objectives and competitive demands
(Kaplan & Norton, 1992)
It “converts senior managements priorities(as described in the
Strategic Plan) into visible, actionable objectives by identifying
ways to measure progress against agreed upon targets” (Turban,
Volontino & Wood, 2015)
The Balanced Scorecard
It uses both financial and non financial indicators to assist with
informing an organization with identifying how it is doing with
reaching its strategic goals and objectives.
If helps with identifying what it is doing well along with where
it needs to institute improvements.
Balanced Scorecard (Kaplan & Norton, 1996)
6. The Balanced Scorecard
According to Kaplan and Norton (1996) the Balanced Scorecard
can also be used to help organizations link long term strategy to
short term goals by, among other things, assisting with:
Translating the Vision
Communicating and Linking
Business Planning
Feedback and Learning
The Balanced Scorecard – Managing Strategy (Kaplan &
Norton, 1996, 2007)
The Assignment
Summarize the videos identified below discussing the Balanced
Scorecard. APA format – double spaced, 12 point Arial or
Times New Roman typeface, cite in text FREQUENTLY to the
content of the videos. Minimum of 3 pages, Maximum of 4
pages in length.
The Assignment
Section 1 – write a brief introduction. Use an online dictionary
or online magazine/newspaper to define the Balanced Scorecard.
A very short definition is fine.
Section 2 – discuss the content of the first video -
https://www.youtube.com/watch?v=G8Hgm08ofqQ Cite in text
as (Balanced Scorecard Institute, 2017)
Section 3 – discuss the content of the second video
https://www.youtube.com/watch?v=VAgWjEgv25g Cite in text
as (Balanced Scorecard Institute, 2016)
7. Section 4 – write a brief conclusion that summarizes your
thoughts on what you have viewed in the videos about the
Balanced Scorecard.
Section 5 – Reference page – see the next slide for some tips on
formatting
The Assignment – How to cite to a YouTube video
Reference page citation format for YouTube videos- Author
screen name (such as Balanced Scorecard Institute). (Year,
Month, Day{that the video was posted}). Title of video [Video
file]. Retrieved from URL of specific video
Example - The Cat Shop. (2006, November 4). How to train a
cat to operate a light switch [Video file]. Retrieved from
http://www.youtube.com/watch?v=Vja83KLQXZs
The Assignment
Submit your own work.
So long as you stay focused on the topic, there is no right or
wrong answer.
Watch the videos carefully and critically.
What counts is providing a clear and concise summary of the
Balanced Scorecard as discussed in the videos thus
demonstrating an understanding of the concepts.
Follow the formatting for the paper that is illustrated above
Cite, cite, cite, cite, cite, cite!!!!!!!
Conclusion
Questions? Send me an email
8. Comments? Send me an email
Happy watching!!!
References
Kaplan, R.S. and Norton, D.P. (1992). The balanced scorecard –
Measures that drive performance. Harvard Business Review,
71-79
Kaplan, R.S. and Norton, D.P. (1996, reprinted 2007). Using the
balanced scorecard as a strategic management system. Harvard
Business Review, 75-85
Turban, E., Volonino, L., and Wood, G. (2015). Information
technology for management: digital strategies for insight, action
and sustainable performance, (10th ed.) Hoboken, N.J.:
John Wiley and Sons, Inc.
//------------------------------------------------
// NAME : YOUR NAME
// STUDENT# : #######
//
// COURSE : COMP 2160, SECTION: A01
// INSTRUCTOR: Stela H. Seo
// ASSIGNMENT: 02, QUESTION: 01
//
// REMARKS : Implement a module which finds the best move
in the game Reversi
// The best move refers to placing next stone for the
most number of gains
// https://en.wikipedia.org/wiki/Reversi
//------------------------------------------------
//-------------------------------------------------------------------------
-----
10. GameBoardCell player; // who can move next
GameBoardCell
state[MAX_BOARD_ROWS][MAX_BOARD_COLUMNS];
char title[MAX_BOARD_TITLE];
}GameBoard;
//-------------------------------------------------------------------------
-----
// PROTOTYPES
//-------------------------------------------------------------------------
-----
//--------------------------------------------------
// checkstate
// PURPOSE: Check if the given board is valid
// INPUT PARAMETERS:
// [board]<IN> Game board to check
// OUTPUT PARAMETERS:
// [boolean]<OUT> True if valid; otherwise, false
//--------------------------------------------------
boolean checkstate( const GameBoard * board );
//--------------------------------------------------
// computeBestMove
// PURPOSE: Read one board from standard input and compute
a player's best move
// INPUT PARAMETERS:
// OUTPUT PARAMETERS:
// [boolean]<OUT> True if succeeded; otherwise, false
//--------------------------------------------------
boolean computeBestMove( );
//--------------------------------------------------
// canPlayAt
// PURPOSE: Check if current player perhaps be able to play at
the given row and column
11. // INPUT PARAMETERS:
// [board]<IN> Game board to check
// [row]<IN> Cell row position to check playability
// [col]<IN> Cell column position to check playability
// OUTPUT PARAMETERS:
// [boolean]<OUT> True if possibly playable; otherwise, false
// REMARKS: The function may return true if the cell is
possibly playable.
// To check if cell is indeed playable, after this, the caller must
make sure that
// there will be at least one piece which will be reversed by
playing at this cell.
//--------------------------------------------------
boolean canPlayAt( const GameBoard * board, int row, int col );
//--------------------------------------------------
// numAllReverse
// PURPOSE: Find out all number of reverses by playing at the
given position
// INPUT PARAMETERS:
// [board]<IN> Game board to check
// [row]<IN> Cell row position
// [col]<IN> Cell column position
// OUTPUT PARAMETERS:
// [int]<OUT> Total number of reverses caused by playing at
the given position
//--------------------------------------------------
int numAllReverse( const GameBoard * board, int row, int col );
//--------------------------------------------------
// numReverseDirection
// PURPOSE: Find out all number of reverses from the given
position toward the given direction
// INPUT PARAMETERS:
// [board]<IN> Game board to check
// [row]<IN> Cell row position
12. // [col]<IN> Cell column position
// [dirRow]<IN> Row direction to check reverses [-1, 1]
// -1 for moving above, 0 for no move, 1 for moving
below
// [dirCol]<IN> Column direction to check reverses [-1, 1]
// -1 for moving left, 0 for no move, 1 for moving
right
// OUTPUT PARAMETERS:
// [int]<OUT> Total number of reverses caused by playing at
the given location toward the direction
//--------------------------------------------------
int numReverseDirection( const GameBoard * board, int row,
int col, int dirRow, int dirCol );
//--------------------------------------------------
// readGameBoard
// PURPOSE: Read a game board from standard input
// INPUT PARAMETERS:
// [board]<OUT> Board to store the information
// OUTPUT PARAMETERS:
// [boolean]<OUT> True if no error occurred; otherwise, false
// REMARKS: Input must have the board's title on the first line,
// number of columns, number of rows, and current player ('B'
or 'W') on the second (space as a delimiter),
// the board's row on each line (' ' for NONE, 'B' for BLACK,
and 'W' for WHITE)
// and an empty line at the end.
//--------------------------------------------------
boolean readGameBoard( GameBoard * board );
//--------------------------------------------------
// printBoard
// PURPOSE: Print board in pretty format
// INPUT PARAMETERS:
// [board]<IN> Game board to print
//--------------------------------------------------
13. void printBoard( const GameBoard * board );
//--------------------------------------------------
// printBoardColumnName
// PURPOSE: Print board's column head. Support function for
printBoard()
// INPUT PARAMETERS:
// [nColumns]<IN> The number of columns for the currently
printing board
//--------------------------------------------------
void printBoardColumnName( int nColumns );
//--------------------------------------------------
// printBoardRowSeparator
// PURPOSE: Print board's row separator. Support function for
printBoard()
// INPUT PARAMETERS:
// [nColumns]<IN> The number of columns for the currently
printing board
//--------------------------------------------------
void printBoardRowSeparator( int nColumns );
//-------------------------------------------------------------------------
-----
// VARIABLES
//-------------------------------------------------------------------------
-----
//-------------------------------------------------------------------------
-----
// FUNCTIONS
//-------------------------------------------------------------------------
-----
//------------------------------------------------------
14. // main
// PURPOSE: Application entry point.
// INPUT PARAMETERS:
// OUTPUT PARAMETERS:
// [int]<OUT> Application exit code.
//------------------------------------------------------
int main( void )
{
while( computeBestMove( ) )
{
printf(
"==============================================
==================================n" );
printf( "n" );
}
printf( "n*** END OF PROCESSING ***nn" );
return EXIT_SUCCESS;
}
boolean checkstate( const GameBoard * board )
{
// TODO: COMPLETE THIS ROUTINE
return true;
}
boolean computeBestMove( )
{
GameBoard board;
int col, row;
int bestCol = -1;
int bestRow = -1;
int bestReverse = 0;
int currReverse = 0;
boolean success = false;
15. if( readGameBoard( &board ) )
{
printBoard( &board );
for( row = 0; row < board.nRows; row++ )
{
for( col = 0; col < board.nColumns; col++ )
{
if( canPlayAt( &board, row, col ) )
{
board.state[row][col] = board.player; // play the
piece
currReverse = numAllReverse( &board, row, col );
board.state[row][col] = NONE; // revert our last
change
if( currReverse > bestReverse )
{
bestCol = col;
bestRow = row;
bestReverse = currReverse;
}
}
}
}
printf( "n" );
printf( "The best move for %s is (%c, %d), which will
reverse %d opponent piece(s)n",
WHITE == board.player ? "WHITE" : "BLACK",
bestCol + 'a',
bestRow + 1,
bestReverse );
printf( "n" );
success = true;
}
return success;
}
16. boolean canPlayAt( const GameBoard * board, int row, int col )
{
// TODO: COMPLETE THIS ROUTINE
return false;
}
int numAllReverse( const GameBoard * board, int row, int col )
{
int count = 0;
if( checkstate( board ) )
{
assert( 0 <= row && row < board->nRows );
assert( 0 <= col && col < board->nColumns );
assert( board->state[row][col] == board->player );
if( 0 <= row && row < board->nRows && 0 <= col &&
col < board->nColumns && board->state[row][col] == board-
>player )
{ // we could make following statements to one; however,
this is easier to step-in in debugger
count += numReverseDirection( board, row, col, -1, -1
);
count += numReverseDirection( board, row, col, -1, 0 );
count += numReverseDirection( board, row, col, -1, 1 );
count += numReverseDirection( board, row, col, 0, -1 );
count += numReverseDirection( board, row, col, 0, 1 );
count += numReverseDirection( board, row, col, 1, -1 );
count += numReverseDirection( board, row, col, 1, 0 );
count += numReverseDirection( board, row, col, 1, 1 );
}
}
return count;
17. }
int numReverseDirection( const GameBoard * board, int row,
int col, int dirRow, int dirCol )
{
// TODO: COMPLETE THIS ROUTINE
return 0;
}
boolean readGameBoard( GameBoard * board )
{
char line[LINE_MAX];
char player = 0;
int length = 0;
int col, row;
boolean success = false;
assert( NULL != board );
if( NULL != board )
{
memset( board, 0, sizeof( GameBoard ) ); // initialization
fgets( board->title, MAX_BOARD_TITLE, stdin );
length = strlen( board->title );
if( length > 0 && board->title[length - 1] == 'n' )
{ // remove n
board->title[length - 1] = '0';
}
fgets( line, MAX_BOARD_TITLE, stdin );
sscanf( line, "%d %d %c", &board->nColumns, &board-
>nRows, &player );
board->player = 'W' == player ? WHITE : BLACK; // who
will play next?
18. for( row = 0; NULL != fgets( line, LINE_MAX, stdin )
&& row < board->nRows; row++ )
{ // by putting read line first, we discard the last empty
line
for( col = 0; '0' != line[col] && col < board-
>nColumns; col++ )
{
switch( line[col] )
{
case 'B':
board->state[row][col] = BLACK;
break;
case 'W':
board->state[row][col] = WHITE;
break;
case ' ':
default:
board->state[row][col] = NONE;
break;
}
}
}
success = row > 0 && row >= board->nRows &&
checkstate( board );
}
return success;
}
void printBoard( const GameBoard * board )
{
int col, row;
if( checkstate( board ) )
{
23. +-+-+-+-+
1|B|B|B|B|1
+-+-+-+-+
2|W|B| | |2
+-+-+-+-+
3|W|B|B| |3
+-+-+-+-+
4| |W|B|B|4
+-+-+-+-+
a b c d
The best move for WHITE is (d, 3), which will reverse 2
opponent piece(s)
===============================================
=================================
TEST BOARD 2
a b c d e f g h
+-+-+-+-+-+-+-+-+
1| | | | | | | | |1
+-+-+-+-+-+-+-+-+
2| | | | | | | | |2
+-+-+-+-+-+-+-+-+
3| | | | | | | | |3
+-+-+-+-+-+-+-+-+
4| | | |B|W| | | |4
+-+-+-+-+-+-+-+-+
5| | | |W|B| | | |5
+-+-+-+-+-+-+-+-+
6| | | | | | | | |6
+-+-+-+-+-+-+-+-+
7| | | | | | | | |7
+-+-+-+-+-+-+-+-+
24. 8| | | | | | | | |8
+-+-+-+-+-+-+-+-+
a b c d e f g h
The best move for BLACK is (e, 3), which will reverse 1
opponent piece(s)
===============================================
=================================
TEST BOARD 3
a b c d e f g h
+-+-+-+-+-+-+-+-+
1| | | | | | | | |1
+-+-+-+-+-+-+-+-+
2| | | | | | | | |2
+-+-+-+-+-+-+-+-+
3| | | | | | | | |3
+-+-+-+-+-+-+-+-+
4| | | |B|W| | | |4
+-+-+-+-+-+-+-+-+
5| | | |W|B| | | |5
+-+-+-+-+-+-+-+-+
6| | | | | | | | |6
+-+-+-+-+-+-+-+-+
7| | | | | | | | |7
+-+-+-+-+-+-+-+-+
8| | | | | | | | |8
+-+-+-+-+-+-+-+-+
a b c d e f g h
The best move for WHITE is (d, 3), which will reverse 1
opponent piece(s)
25. ===============================================
=================================
TEST BOARD 4
a b c d e f g h
+-+-+-+-+-+-+-+-+
1| | | | |W| | | |1
+-+-+-+-+-+-+-+-+
2| | | | |W|W| | |2
+-+-+-+-+-+-+-+-+
3| | |W|W|W|W|W|B|3
+-+-+-+-+-+-+-+-+
4| | |W|W|W|W| |B|4
+-+-+-+-+-+-+-+-+
5| | |W|W|W| | |B|5
+-+-+-+-+-+-+-+-+
6| | | | | | | | |6
+-+-+-+-+-+-+-+-+
7| | | | | | | | |7
+-+-+-+-+-+-+-+-+
8| | | | | | | | |8
+-+-+-+-+-+-+-+-+
a b c d e f g h
The best move for BLACK is (b, 3), which will reverse 5
opponent piece(s)
===============================================
=================================
*** END OF PROCESSING ***