Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M91880170
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in Java

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As