Computer Science 1xx Assignment #N
DUE DATE: mmddyyyy
Learning Objectives:
(This is a list of the major topics that you, as
students, will learn in this
assignment:)
Grading Rubric: This document is available for you use - you should use it to to help guide your work. The rubric is a document which explains how your work will be evaluated, and is located here.
Othello (also known as 'Reversi') is a simple-yet-engaging game for 2 players; the objective is to have the largest number of playing pieces under one's control when the game ends. The game is played on a square board composed of a grid of spaces (visually, the board resembles graph paper - normally the grid is 8x8). The game starts with 2 of each player's pieces on the board. Each of the players alternates playing, with each player placing a piece on the board during their turn. Each piece must be placed according to two rules: (1) the newly placed piece is adjacent to one of the other player's pieces that's already on the board, and (2) the newly placed piece must be able to trace a straight-line path (vertically, horizontally, or diagonally) over the other player's pieces to a piece that belongs to the current player, which 'brackets' the opponent's pieces. Doing so flips (or 'reverses') all the opposing player's pieces between the two pieces. The game is described in more detail at http://en.wikipedia.org/wiki/Reversi
For this program, you'll be responsible for implementing part of an existing game. Most of the game will be provided to you, and you will have to implement two methods, described in detail below in Table 1. Both of these methods are found in the PlayBoard.cs file, and are the only methods that you will be required to implement in order to successfully complete this assignment. Note that in order to successfully complete this assignment, you will need to make sure of some code that has been provided to you - these are several methods on the PlayBoard class, as well as several methods on the GamePiece class. These methods have been described below, in Tables 2 and 3
In a nutshell, your HasValidPositions method will tell the rest of the program if the current player has any legal moves available (and if not, then the code that has been provided to you will end the game shortly thereafter). The rest of the program will then figure out what move the current player wants to make, and then call your PlayToCell method, giving your PlayToCell method a particular cell (as indicated by (col,row) (or equivalently, indicated by (X,Y) coordinate)), and your method will figure out if that is a legal move for the current player to make. If it is a legal move, your PlayToCell will also handle flipping any game pieces over.
At this point, you should read through the below documentation, find the code in the starter project that you have to implement, look for (and read) any and all comments that contain the word 'STUDENTS' (they're there to help you understand how the program works)(you may find it easier to search using the Edit menu, then 'Find And Replace', then the 'Find In Files' menu option).
Make sure that you read the rest of this document, as the homework instructions continue after these three tables!
Table 1: Methods That You Have To Implement |
|||
Data Field Name |
Type |
Description: |
|
You're free to add any data fields |
that you need to, in order to accomplish |
the objectives set forth in this assignment |
|
Note: all data fields should be marked private (if you need to expose them, use Properties, or accessor/mutator methods) |
|||
Method Name |
Returns |
Description/Parameters: |
|
PlayToCell |
bool true if the move is valid. A valid move is described in the homework assignment, above. This method will also flip over any pieces that need to be flipped (remember that every valid move results in pieces being flipped over). If the current player has attempted to place a piece illegally (outside the bounds of the array, not adjacent to a previously placed piece, on a square the won't flip any of the opposing player's pieces, or for any other reason), then this method will return false. |
Parameters:
PlayToCell is given the cell/square that the current player wishes to place one of their pieces into, as specified by (X,Y) (or rather, by (col, row)) location. If the move is valid, this method will flip any pieces that need to be flipped, and then return true. If the move is NOT valid (for any reason), it will return false.
|
|
HasValidPositions |
bool Returns true if there are any legal moves for the current player to make, returns false if there aren't any legal moves for the current player to make. |
Parameters: None
This method will check if there are any more legal moves that the "currentPlayer" can make. Returns true if there are, returns false if not (the code that has been provided to you will will then end the game afterwards)
|
|
Note:
all methods should be marked public Note: All methods should run in a minimum amount of time, and with a minimum amount of space (memory) consumed. |
Table 2: Methods On The PlayBoard Class That You May/Will Use |
|||
Data Field Name |
Description: |
||
public const int BlackPlayer = 0; |
Notice that since there are two players, and since we want to refer to players using a textual name (rather than a number like 0), but since C# would prefer to refer to the players via numbers, we instead use a trick of defining a 'variable' with the number 0, and in our code, we use the variable name instead of 0. (Note that the variable is marked as being 'const', meaning 'constant'- C# will never let this 'variable' change it's value) So, we could use code like the following in our PlayToCell method: if (CurrentPlayer() == BlackPlayer)EchoToBottomStatus("Black's turn to move!"); else EchoToBottomStatus("White's turn to move!"); |
||
public const int WhitePlayer = 1; |
This is the same trick for the player who will place White game pieces (see description above). |
||
Method Name |
Returns |
Description/Parameters: |
|
CurrentPlayer() |
int This method will return an integer, representing the current player. BlackPlayer is defined as 0 (see the comments around the BlackPlayer variable, at the top of this table), and WhitePlayer is defined at 1, but you should use the BlackPlayer/WhitePlayer variables to refer to players, if you need to refer to specific players at all. More likely, you'll use feed this method's return value to the GamePiece.IsPlayer method, in order to check if a particular game piece belongs to the current player or not. |
Parameters: None Description: The return value column says it all |
|
NextPlayer() |
int NextPlayer returns the integer identifying the next player to play. Since there are only two players, the next player is also the only other player. Otherwise, it works just like CurrentPlayer, so read the comments about that method, too :) |
Parameters: None Description: The return value column says it all
|
Table 3: Methods On The GamePiece Class That You May/Will Use |
|||
Method Name |
Returns |
Description/Parameters: |
|
FlipPiece | void |
Parameters: None Description: This method will flip a given game piece. If
the piece is currently owned by the BlackPlayer, then calling this method
will cause the ownership to flip to the WhitePlayer. Similar, if the piece
is currently white, then calling FlipPiece will make it black |
|
FlipToPlayer | void |
Parameters:
Description: This method will flip a given game piece, so that the piece is now owned by the specified player (and the color will be adjusted so that the BlackPlayer's pieces are colored black, the WhitePlayer's pieces are colored white, etc) |
|
IsPlayer |
bool true if this GamePiece object is owned by the specified player, false otherwise |
Parameters:
Description: This method will allow you (in PlayToCell,
or HasValidPositions) to determine if a given piece is owned by a specific
player. Note that this is different from figuring out if a given space is
blank - see the sample code in PlayToCell to see how to tell if a
cell/square is empty. |
How To Play The Game: |
Game/Program
Controls: XBox When running the game/program, you can control it using the following Gamepad controls:
|
Game/Program
Controls: PC Here is the keyboard to controller mapping. |
You are not allowed to work in groups for this assignment. You should start, finish, and do all the work on your own. If you have questions, please contact the instructor.
Additionally, you should aggressively comment your code, paying particular attention to areas that are difficult to understand. If you found something to be tricky when you wrote it, make sure to comment it so that the next person (the instructor, who's grading you) understands what your code is doing. It is not necessary to comment every single line.
The purpose of new requirement is to both help you understand, and have you demonstrate, a thorough understanding of exactly how your program works.
Every file that you turn in should have:
·
At the top of each file that
you normally edit, you should put your name (first and last), the name of this
class (BIT 142), and the year and quarter, and the assignment number,
including the revision number, which starts at 0 (A2.0). If youre handing
this in again for a regrade, make sure to increase the minor version number by
one (from A2.0, to A2.1").
You normally edit the C# source code files (.CS files), and any Word documents
that you're handing in (if any).
You do not normally edit the .SLN or .CSPROJ files, and so you should not try to
put this identifying information in those files.
In general, you should make sure to do the following before handing in your project:
· All variables used should have meaningful names.
· The code should be formatted consistently, and in an easy to read format.
What to turn in:
· A single electronic folder (a directory). This folder should contain:
o
The source code for the
program all the .CS files in your project.
I would prefer that you include the project files stuff ending in .SLN and
.VCPROJ, so I can build your project more easily. If you can save these files
(the .SLN / . VCPROJ) into a file format that can be opened by VS.Net 2003, that
would be great.
o
You have to name the folder
with your last name, then first name, then the assignment number (both the major
version 2, and the minor (revision) number 0). Example: "Panitz, Mike,
A2.0"
· You should not include the Debug directory, or anything from it. I will dock you a couple points if you do. Also, you don't need to include your .NCB file, if it's present.
How to electronically submit your homework:
There's a link on the homework page to the document that guides you through handing in your work, using the SourceGear Vault program.
This document and the related materials are developed with support
from Microsoft Research Computer Gaming Initiative under the Computer Gaming
Curriculum in Computer Science RFP, Award Number 15871.