G51PGP: Software Paradigms. Object Oriented Coursework 4

Similar documents
CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

Taffy Tangle. cpsc 231 assignment #5. Due Dates

Intro to Java Programming Project

CPSC 217 Assignment 3

Activity 6: Playing Elevens

Assignment III: Graphical Set

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

Shaftesbury Park Primary School. Wandsworth test examples

Programming Problems 14 th Annual Computer Science Programming Contest

G54GAM Lab Session 1

The game of Paco Ŝako

Girls Programming Network. Scissors Paper Rock!

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

CMPT 310 Assignment 1

Game Playing in Prolog

Learning to Play like an Othello Master CS 229 Project Report. Shir Aharon, Amanda Chang, Kent Koyanagi

CS Programming Project 1

1st Grade Math. Please complete the activity below for the day indicated. Day 1: Double Trouble. Day 2: Greatest Sum. Day 3: Make a Number

Tic-tac-toe. Lars-Henrik Eriksson. Functional Programming 1. Original presentation by Tjark Weber. Lars-Henrik Eriksson (UU) Tic-tac-toe 1 / 23

CSC 110 Lab 4 Algorithms using Functions. Names:

Final Project: Reversi

Slitherlink. Supervisor: David Rydeheard. Date: 06/05/10. The University of Manchester. School of Computer Science. B.Sc.(Hons) Computer Science

Programming an Othello AI Michael An (man4), Evan Liang (liange)

Memory. Introduction. Scratch. In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Assignment 1. Due: 2:00pm, Monday 14th November 2016 This assignment counts for 25% of your final grade.

Structured Programming Using Procedural Languages INSS Spring 2018

In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Create Your Own World

January 11, 2017 Administrative notes

Part 1. Using LabVIEW to Measure Current

Sudoku Online Qualifiers2017

Cryptic Crosswords for Bright Sparks

Mind Ninja The Game of Boundless Forms

2D Platform. Table of Contents

Unit 5: What s in a List

CMPT 310 Assignment 1

3 0 S E C O N D Q U I C K S T A R T To start playing right away, read this page.

Assignment 2 (Part 1 of 2), University of Toronto, CSC384 - Intro to AI, Winter

Due: Sunday 13 November by 10:59pm Worth: 8%

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

This game can be played in a 3x3 grid (shown in the figure 2.1).The game can be played by two players. There are two options for players:

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

BAPC The Problem Set

2: Turning the Tables

1 Modified Othello. Assignment 2. Total marks: 100. Out: February 10 Due: March 5 at 14:30

CSC Curriculum Term One Lesson Plans

A fun way to challenge your math thinking! Grade Levels: 4th - 8th Time: 1 class period. Check out 36 BINGO Snapshot

A Level Computer Science H446/02 Algorithms and programming. Practice paper - Set 1. Time allowed: 2 hours 30 minutes

CS221 Project Final Report Automatic Flappy Bird Player

Homework Assignment #2

One Zero One. The binary card game. Players: 2 Ages: 8+ Play Time: 10 minutes

Checkpoint Questions Due Monday, October 7 at 2:15 PM Remaining Questions Due Friday, October 11 at 2:15 PM

Pay attention to how flipping of pieces is determined with each move.

Bachelor Project Major League Wizardry: Game Engine. Phillip Morten Barth s113404

2 Textual Input Language. 1.1 Notation. Project #2 2

Scrabble. Assignment 2 CSSE1001/7030 Semester 2, Version 1.0.0rc1. 20 marks : 10% Due Friday 22 September, 2017, 21:30

HW4: The Game of Pig Due date: Tuesday, Mar 15 th at 9pm. Late turn-in deadline is Thursday, Mar 17th at 9pm.

MATHEMATICAL RELATIONAL SKILLS AND COUNTING 0 20

Project Connect Four (Version 1.1)

Sudoku Mock Test 5. Instruction Booklet. 28 th December, IST (GMT ) 975 points + Time Bonus. Organized by. Logic Masters: India

Surreal Numbers and Games. February 2010

Kenken For Teachers. Tom Davis January 8, Abstract

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Sep 25. Homework #1. ( Due: Oct 10 ) Figure 1: The laser game.

The Beauty and Joy of Computing Lab Exercise 10: Shall we play a game? Objectives. Background (Pre-Lab Reading)

Inventor: 2009 manuela&wiesl

Games of Skill Lesson 1 of 9, work in pairs

CS 354R: Computer Game Technology

Documentation and Discussion

The 2015 British Informatics Olympiad

Reinforcing Note Reading in G Position with. by Andrea and Trevor Dow Teach Music Today Learning Solutions

Tic-Tac-Toe and machine learning. David Holmstedt Davho G43

2048: An Autonomous Solver

Let s Make. Math Fun. Volume 19 January/February Dice Challenges. Telling the Time. Printable Games. Mastering Multiplication.

Inductive Reasoning Practice Test. Solution Booklet. 1

HW4: The Game of Pig Due date: Thursday, Oct. 29 th at 9pm. Late turn-in deadline is Tuesday, Nov. 3 rd at 9pm.

1 The Pieces. 1.1 The Body + Bounding Box. CS 314H Data Structures Fall 2018 Programming Assignment #4 Tetris Due October 8/October 12, 2018

The first player to construct his or her obelisk is the winner, and if a player has no legal moves, he or she immediately loses the game.

Asura. An Environment for Assessment of Programming Challenges using Gamification

Assignment II: Set. Objective. Materials

DARK EGYPT Hints, Tips & Tricks

Student Outcomes. Classwork. Opening Exercises (5 minutes)

Lab 7: 3D Tic-Tac-Toe

The purpose of this document is to help users create their own TimeSplitters Future Perfect maps. It is designed as a brief overview for beginners.

Assignment 2, University of Toronto, CSC384 - Intro to AI, Winter

03/05/14 20:47:19 readme

Real-Time Connect 4 Game Using Artificial Intelligence

The game of Reversi was invented around 1880 by two. Englishmen, Lewis Waterman and John W. Mollett. It later became

COUNT ON US SECONDARY CHALLENGE STUDENT WORKBOOK

Module 1 Introducing Kodu Basics

Before displaying an image, the game should wait for a random amount of time.

Unit 12: Artificial Intelligence CS 101, Fall 2018

Embedded Systems Lab

JUNIOR CERTIFICATE 2009 MARKING SCHEME TECHNICAL GRAPHICS HIGHER LEVEL

COMPUTING CURRICULUM TOOLKIT

Part II: Number Guessing Game Part 2. Lab Guessing Game version 2.0

2010 HSC Software Design and Development Marking Guidelines

Worksheets :::1::: Copyright Zach Browman - All Rights Reserved Worldwide

Codebreaker Lesson Plan

Virtual Reality in Unreal Engine 4. Nathan Adara Program of Computer Graphics

Solving the Rubik s Cube

Transcription:

G51PGP: Software Paradigms Object Oriented Coursework 4 You must complete this coursework on your own, rather than working with anybody else. To complete the coursework you must create a working two-player version of a Reversi game (https://en.wikipedia.org/wiki/reversi), along with class and object diagrams to explain your chosen design. This coursework is harder than the others that you have had so far, and I will not spell out the steps to achieve what you need to do in the same detail. You have a lot longer to do it, and will use a lot of the knowledge that you have gained from the other courseworks. You must complete this coursework on your own rather than working with anybody else. This coursework is worth 7.5% of the module mark. The first three OO courseworks were together worth 5% of the module mark, making 12.5% total. The FP courseworks also added up to 12.5%. You should try to complete this coursework in your own time and use the labs as an opportunity to get questions answered. The lab helpers can help you to understand concepts but will not help you to actually complete the coursework itself. Be aware that this coursework deliberately gives you less of a walk-through than the previous courseworks, and involves applying what you have done so far in a new situation.

Coursework requirements: Consider the program requirements in this document: Produce a Java program for a Reversi game which meets the program requirements specified in this document. Identify and use appropriate classes in your program. Use interfaces and sub-classing appropriately in your program. Use anonymous inner classes if/where appropriate to do so. Use standard Swing classes, any other standard class library classes, any classes that I have given you already, and your own classes (which may be subclasses of Swing classes), where appropriate. Draw a class diagram to represent your solution, including your own classes, any immediate superclasses for your classes. Include aggregation and inheritance relationships where they exist. Include all attributes and operations. You can draw this by hand or using any software package that you wish to use. It must be clear and unambiguous. Draw an object diagram, showing all of the objects that you create and the relationships between them. You do not need to show attributes and operations. You can draw this by hand or using any software package that you wish to use. It must be clear and unambiguous. In summary: your finished program should look like the display below, should allow players to place pieces when it is their turn, should automatically change the colour of pieces which are taken, and should detect when a player wins: Please also see the start of lecture OO-11 for a demo of a running version of this program.

Program requirements: 1. You must have two frames which display the board, with a label at the top and a button at the bottom, as shown above. You need to display the board on each, where one shows the board upside down from the other (actually a 180 degree rotation, see example below). Think of each as representing a player and the players sitting at opposite ends of the table, so that they see the board upside down compared with the other player. 2. Create a class to draw and handle a square on the board. Consider what I did previously in ColorLabel and ColorButton and do something appropriate for the board square. 3. You need to maintain a board state, which should represent an 8x8 grid of squares, as shown above. Each square can contain a white piece, a black piece or be empty. You should put four initial pieces in the centre as show above. 4. When a piece is played, any pieces between it and another piece of colour in a straight line up to the first piece of your colour in that direction are captured. One way to do this for every time a piece is played, search vertically, horizontally and diagonally (8 directions in total): If you find an empty square or the edge of the board then stop no pieces can be captured in that direction. If you find a piece of the opposing colour then continue in that direction. If you find a piece of your own colour then stop and capture all of the pieces of the opposing colour between it and the piece you just played. 5. Players take it in turns to play. The active player should be obvious to the player(s) and should be indicated in the label along the top of the screen, as shown in the earlier pictures (where it was white s turn) and below (where it is black s turn). A potential position after the first move by white

6. A player can only play a piece if it is their turn and playing the piece will capture at least one piece owned by the other player. There are only four initial places for white to play, which will be horizontally or vertically next to a black piece, as illustrated above. The black player can then play in a choice of three places. After that things get more complex. 7. White should play first. A potential position after the first move by black (after the move by white) A game in progress

8. Include a simple greedy AI, so that when a player presses the AI button and it is their turn the computer takes their turn for them. When the player presses the button, the program should check each space, calculate how many pieces will be taken if a piece is placed in that space and choose one of the space which take the most pieces. Note: If there are multiple places which take the same pieces then I don t mind which you choose I chose randomly but you can choose the first or last such position if you wish. This is called a greedy algorithm because it always makes the best move it can think of at the time without thinking about later consequences. The end of the game 9. When neither player can play a piece then the game ends (this will usually be when the board is full). At this point the player(s) should be presented with a message telling them then who won (who had the most pieces) and how many pieces of each colour there were at the time the game ended. Final message

Submission: It is intended that this coursework will be marked in the labs and that nothing will be submitted. When you have completed your coursework, please ask one of the markers to mark it. They will ask you to demo it and ask you various questions to understand how you did things and to test your understanding of what you did. They will then give you a mark. You will receive immediate verbal feedback so will know what mark you got and why. Marking criteria (total 30 marks): The mark breakdown is shown below, since I am aware that sometimes students use this to strategically decide what to do if time becomes short: 10 marks: Class diagram and object diagram are correct and model/design used for this program is appropriate. Appropriate classes were used. Diagrams are correct. Relationships between objects are appropriate and shown correctly in the diagrams. 8 marks: Board appears correctly: in two frames, showing pieces correctly, initial pieces are placed, labels show current player, board state is displayed, one board is upside down from the other, everything updates correctly. The class for the board square is appropriate and works correctly. At the end the number of pieces is correctly calculated and the winner is announced appropriately. 4 marks: Board state is maintained and updated correctly, counts of pieces taken are accurate, pieces are actually captured correctly. 4 marks: Game logic works correctly, passing control between players appropriately, allowing correct player to play, players can only play in valid locations, play alternates between players, play moves to other player when player cannot play a piece, etc. 4 marks: AI works correctly, correctly working out how many pieces will be taken if playing in each location, and choosing one of the best greedy moves when button is pressed.

Hints: Counting the pieces taken: If you create a function which counts how many pieces will be taken if you play in a location, you will find that you can use this function in multiple places. If the value is 0 for all directions then you can t play there. If you call the function mentioned above for every square you can work out whether a player can play at all. You can also work out what the best greedy move is (i.e. the one which takes the most pieces). Checking in multiple directions: If you want to check multiple directions, you could use a loop of offsets and recursion. E.g. continuously adding -1x,-1y to a position moves diagonally, whereas adding 0x,1y to a position moves vertically. I used two loops: e.g. for (xoffset=-1; xoffset<=1;xoffset++) and similarly for y, and skipped the case for 0,0. Using this offset I checked all 8 directions without me having to hardcode multiple directions. (If this doesn t make sense to you then just hardcode the directions, but it is not as quick to code it that way, so you ll need to write more code.) You can use iteration to keep moving to the edge, but I found that recursion gave me an easier function to create in this case. You may find iteration easier until you fully understand recursion though the comments from the FP lectures about different cases also apply to recursive functions in Java. How do I display a message? The JOptionPane class has a static function (the equivalent of a global function in C) which will display a message box for you if you wish. Just create the string to display and pass it to the function. E.g.: String st = "My message"; JOptionPane.showMessageDialog(null,st); Where to start? You can choose your own starting point, either starting from the diagrams and working to the code, or doing both in combination. If you are really stuck for a starting point then I suggest starting with the user interface, since the concepts are very similar to those that you have already used in the earlier courseworks. This will allow you to make some progress. I also suggest considering an MVC approach (see Lecture 11) if it seems appropriate. Next decide how to store your data, how you will work out which pieces are taken (or could be taken) and how you will ensure that changes made to one frame are seen in the other. I tend to think about what data I need to maintain as well (i.e. what member variables do you need in each object), and what each object needs to do. Thinking about the collaborations and responsibilities of objects may help you. Think also about how you will record whose turn it is as well, and how you will ensure that a player can only play a piece on their own turn.