Implement the rules and logic for othello

Assignment Help JAVA Programming
Reference no: EM131123608

Java coding: Othello

This is an individual project, to be completed on your own. It is considered dishonest either to read someone else's solution or to provide a classmate with a copy of your work. Do not make the mistake of thinking that superficial changes in a program (such as altering comments, changing variable names, or interchanging statements) can be used to avoid detection. If you cannot do the work yourself, it is extremely unlikely that you can succeed in disguising someone else's work. We are adamant that cheating in any form is not tolerated. Even the most trivial assignment is better not done than if you cheat to complete it.

Prerequisites

1. Primitive types
2. Conditionals
3. Loops
4. Arrays

Learning Objectives

1. Problem Solving
2. Traversing and manipulating 2-dimensional arrays
3. Using nested loops

Introduction

In this project, you will implement the logic of the game Othello, also known as Reversi.

Game Rules

Othello is a strategy board game for two players on a squared checkered board. It is played with identical disks that are white on one side and black on the other. Players take turns placing disks on the board with their assigned color facing up.

The game starts with four disks placed in a square at the center of the board in a standard diagonal pattern: two facing white side up, two facing black side up and same-colored disk on a diagonal with each other. These four initial disks are not placed by the player.

The black player moves first. He must place a disk with the black side up on the board, in such a position that there exists at least one straight occupied line between the new disk and another dark disk, with one or more contiguous white disks bounded between them. During a move, all bounded disks of the opponent's color are turned over to the current's player color. A straight line involves: horizontal, vertical and diagonal lines in every possible direction. It is possible to bound disks in more than one direction during a single move.

Players take turns to play. When a player doesn't have any valid moves, his turned is skipped. The game must keep going while there are valid moves by either player. The goal of the game is to have the majority of the disks displaying your color when there are no more possible moves.

Your Task

In this project, you will implement the rules and logic for Othello. You are provided with the skeleton code containing the basic methods that you need to complete to launch this game on the java console. You have the freedom to use additional methods and variables to structure your solution, as long as the basic methods behave as expected.

Implementation Details

This project consists of just one class:

1. Othello: it implements the logic of the game. You will implement the missing methods.

You should begin coding after you have read the entire handout, understood the problem and made a plan for solving it.

Variables

The Othello class will contain the following class variables:

private static final int NONE = 0;
private static final int BLACK = 1;
private static final int WHITE = 2;

and the following instance variables:

public int[][] board;

The variables spelled in all capitals represent the possible values for positions in the board. They are constant, which is why they are declared final. Final is a Java modifier to indicate that the value of these fields cannot change. Constants defined this way cannot be reassigned, and trying to do so will produce a compile-time error. By convention, the names of constant values are spelled in uppercase letters. This convention is used in many programming languages. We recommend that you follow this convention when using constant values.

The board variable is a 2-d squared array that represents the actual board where the game is played. Each position is specified by its row and column. Each position will contain NONE when there are no disks in it, BLACK when there is a black disk facing up and WHITE when there is a white disk facing up.

Methods

You need to complete the following basic methods to implement the game's logic. A skeleton code is provided below.

- public Othello(int length) : The constructor initializes the instance variables and creates the starting board configuration of the Othello game. The input length represents the size of the squared board (same length of rows and columns). Refer to the rules above to see what is the initial state of the game. You can assume that the length will always be an even number.

- public boolean isValid(int row, int col, int player) : returns true if the specified position is a valid move for the specified player. For a position to be valid, it should be in bounds, empty and playable by the specified player. Refer to rules above to see what is a playable position.

- public boolean hasValidMoves(int player) : scans the complete board to look for positions that are valid moves for the specified player. If there are no valid moves for the input player, it returns false. If there is at least one valid move, it returns true.

- public void makeMove(int row, int col, int player) : The specified player makes the move on position (row, col). Refer to the rules above.

- public int playGame() : this method implements the logic of the game by making use of the previous methods. Players take turns to play and the position has to be obtained by prompting the users. You have to make sure that players enter valid positions. In case they choose an invalid position, keep asking until they choose a valid one. However, if a player doesn't have any possible valid moves, there is no need to prompt him and his turned is skipped. Print the board at the beginning of the game and after each turn. The game must keep going until none of the players have valid moves. When the game is over, remember to congratulate the winner :)

To print the board, use the method provided to you in the skeleton: public void printBoard(int turn).

Remember that you have the freedom to add the auxiliary methods or variables that you deem helpful, as well as to reuse methods that you have coded, as long as specified methods behave as expected. An example execution is illustrated below.

Test Cases

These test cases are to help you during your development. There are no test cases for the method playGame and you will have to test it manually.

Reference no: EM131123608

Questions Cloud

A willingness to listen during an interaction allows : To be an effective communicator we must master the core competence of listening. A willingness to listen during an interaction allows you to understand others, respond appropriately to what they say, or provide helpful feedback.
Analyze role of culture and disability in work with families : Analyze research-based information regarding how culture influences an educational setting and how to support families and students from non-mainstream cultures.
Compare capabilities of the microsoft access and sql server : Compare the capabilities of the Microsoft Access, Microsoft SQL Server, Oracle's MySQL, and Oracle relational database management systems (RDBMSs).
Create an activity that will address all three levels : Create an activity/lesson that will address all three levels. The activity/lesson should draw on what the students may already know from home, community or school, will be meaningful, will show knowledge of local norms (please choose one culture/l..
Implement the rules and logic for othello : In this project, you will implement the rules and logic for Othello. You are provided with the skeleton code containing the basic methods that you need to complete to launch this game on the java console.
What is the maximum amount of bank borrowing that would : Use the income statement data and the balance sheet information from Problem 9 to prepare monthly income statements, balance sheets, and statements of cash flows for October through December 2011. What is the maximum amount of bank borrowing that wou..
Determine the mean birth weight of a certain breed of kitten : A study was conducted to determine the mean birth weight of a certain breed of kittens. Consider the birth weights of kittens to be normally distributed
King leopold ii and the belgian congo genocide : King Leopold II was born April 9, 1835 in Brussels, Belgium. He was Queen Victoria of Britain's first cousin and became the Duke of Bradant in 1846. Leopold also served in the Belgium army. In 1853 Leopold married Marie-Henriette. He became King ..
Prepare pdcs sales schedule purchases schedule : A. Prepare PDC’s sales schedule, purchases schedule, and wages schedule for each of the last four months of 2011. B. Prepare cash budgets for each of the last four months of 2011 for the PDC Company and describe how the forecast affects the end-of-mo..

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  What challenges in planning solution for programming problem

what are the three biggest challenges in planning and designing a solution for a programming problem? What can you do to overcome these challenges? How would you apply these techniques to the programs in this class?

  Create a 2-by-3 two-dimensional array of integers

Create a 2-by-3 two-dimensional array of integers and fill it with data. Loop through the array and locate the smallest value stored.

  A method with the signature public static void

A method with the signature public static void printDetails(City[] cities) that will iterate through the cities and printthe details of the city using the displayDetails(...) method.

  Explain where the following method invocations

Explain where the following method invocations are most likely to be found in a program for dealing with census data organized using the Model, View, Controller (MVC) design pattern. Choices are zero or more of Model, View, and Controller. Be sure to..

  Create a bar chart that illustrates sales.

Hal's Used Cars has four salespeople named Pam, Leo, Kim, and Bob. Accept values for the number of cars sold by each salesperson in a month, and create a bar chart that illustrates sales. Save the file as BarGraph.java.

  Assignment related to java programming

Question 1: Write a java program to compute the squares of the numbers in the array list like 1, 2, 3, 4... up to 50. Question 2: Write a java program to compute the sum of numbers and average in the array list up to 50.

  How should ijvm be modified to make best use of instructions

On the full JVM machine, there are special 1-byte opcodes for loading locals 0 through 3 onto the stack instead of using the general ILOAD instruction. How should IJVM be modified to make the best use of these instructions?

  Develop a java program given the width, length and depth

Write the source code for each class in a separate file which must have the same name as the class name together with the extension .java. Remember also that by convention, class names commence with a capital letter.

  Calculates the total annual compensation of a salesperson

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of $85,000.00

  Define the determinant of a matrix

Define the determinant of a matrix a (written det(a)) recursively as follows: if a is a 1 x 1 matrix, then det(a) = x

  Threads and synchronization

Threads and Synchronization- Whenever we have multiple entities working together to get something done, we have the problem of synchronization between the entities

  Explain security and permissions for the android platform

Briefly explain security and permissions for the Android Platform. Briefly describe some of the Android Platform Services. Describe the Android Platform Differences (complete, open, and free).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd