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

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

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger. Project #3: Checkers

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

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

Game Playing in Prolog

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

CPSC 217 Assignment 3


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

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

Taffy Tangle. cpsc 231 assignment #5. Due Dates

Project 1: A Game of Greed

CONTENTS. 1. Number of Players. 2. General. 3. Ending the Game. FF-TCG Comprehensive Rules ver.1.0 Last Update: 22/11/2017

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

Spring 06 Assignment 2: Constraint Satisfaction Problems

Lab 7: 3D Tic-Tac-Toe

For slightly more detailed instructions on how to play, visit:

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

a b c d e f g h i j k l m n

Final Project: Reversi

Computer Science 25: Introduction to C Programming

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

YourTurnMyTurn.com: chess rules. Jan Willem Schoonhoven Copyright 2018 YourTurnMyTurn.com

CS 312 Problem Set 6: λ-shark (CTF)

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

Comprehensive Rules Document v1.1

Lines of Action - Wikipedia, the free encyclopedia

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

OCTAGON 5 IN 1 GAME SET

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

Would You Like To Earn $1000 s With The Click Of A Button?

CMSC 201 Fall 2018 Project 3 Sudoku

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.

The game consists of 3 rounds where you will build a castle in 30 seconds then place catapults and steal wall pieces from your neighbors.

Mind Ninja The Game of Boundless Forms

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

BAPC The Problem Set

Sudoku goes Classic. Gaming equipment and the common DOMINARI - rule. for 2 players from the age of 8 up

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #7. Project #1: Checkers, Due: Feb. 19th, 11:59p.m.

EXPLORING TIC-TAC-TOE VARIANTS

Jarl 3 Freeman 3 Spearman Chieftain Vala Berserker

Analyzing Games: Solutions

BINGO MANIAC. Developed by AYGENT543. Copyright Vishnu M Aiea

CSCE 2004 S19 Assignment 5. Halfway checkin: April 6, 2019, 11:59pm. Final version: Apr. 12, 2019, 11:59pm

Selected Game Examples

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

The 2013 British Informatics Olympiad

a b c d e f g h 1 a b c d e f g h C A B B A C C X X C C X X C C A B B A C Diagram 1-2 Square names

e-bos TM Version 2.1.x PowerPlay User s Manual June BOS TM 2.1.x Page 1 of 59

Intro to Java Programming Project

Introduction to Spring 2009 Artificial Intelligence Final Exam

Tac Due: Sep. 26, 2012

Would You Like To Earn $1000 s With The Click Of A Button?

Assignment II: Set. Objective. Materials

Would You Like To Earn $1000 s With The Click Of A Button?

Programming Project 2

CS Project 1 Fall 2017

03/05/14 20:47:19 readme

G51PGP: Software Paradigms. Object Oriented Coursework 4

Game components. Common components: 1 dice tower. 24 progress tokens. 40 commodity tokens 8 of each type

Cato s Hike Quick Start

Documentation and Discussion

The Mathematics of Playing Tic Tac Toe

Spring 06 Assignment 2: Constraint Satisfaction Problems

1, 2,, 10. Example game. Pieces and Board: This game is played on a 1 by 10 board. The initial position is an empty board.

Problem F. Chessboard Coloring

CMPUT 657: Heuristic Search

Chess Handbook: Course One

Problem 4.R1: Best Range

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1

CS106X Handout 13 Winter 2018 January 24 th, 2018 Assignment 3: Boggle

BMT 2018 Combinatorics Test Solutions March 18, 2018

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

1 Running the Program

Find the items on your list...but first find your list! Overview: Definitions: Setup:

Board Game AIs. With a Focus on Othello. Julian Panetta March 3, 2010

GLOSSARY USING THIS REFERENCE THE GOLDEN RULES ACTION CARDS ACTIVATING SYSTEMS

Problem A To and Fro (Problem appeared in the 2004/2005 Regional Competition in North America East Central.)

Computing Science (CMPUT) 496

My Little Pony CCG Comprehensive Rules

After learning the Rules, What should beginners learn next?

OBJECTIVE OF THE GAME YOUR TEAM COMPONENTS. speeds and Blocker pushing.

Stat 155: solutions to midterm exam

Copies of the Color by Pixel template sheets (included in the Resources section). Colored pencils, crayons, markers, or other supplies for coloring.

For our EC331 project we successfully designed and implemented a PIC based Tic-Tac-Toe game using the PIC16874.

ENGR170 Assignment Problem Solving with Recursion Dr Michael M. Marefat

--- ISF Game Rules ---

Introduction to Counting and Probability

Essential Chess Basics (Updated Version) provided by Chessolutions.com

Welcome to the Brain Games Chess Help File.

Microchess 2.0 gives you a unique and exciting way to use your Apple II to enjoy the intellectually stimulating game of chess. The complete program lo

G52CPP Lab Exercise: Hangman Requirements (v1.0)

Programming Assignment 4

DELUXE 3 IN 1 GAME SET

ARMY COMMANDER - GREAT WAR INDEX

Red Dragon Inn Tournament Rules

Game Rules. 01 Definition and Purpose. 03 Overlooking ISF Game Rules: ISF Court of Appeal. 02 Changes in ISF Game Rules.

Movement of the pieces

Problem C The Stern-Brocot Number System Input: standard input Output: standard output

CSC Curriculum Term One Lesson Plans

Transcription:

CSB, Fall 0 Project #: Jumping Cubes(version ) P. N. Hilfinger Due: Tuesday, 8 November 0 Background The KJumpingCube game is a simple two-person board game. It is a pure strategy game, involving no element of chance. For this second project, you are to implement our version of this game, which we ll call jump, allowing a user to play against a computer or against another person, or to allow the computer to play itself. The basic interface is textual, as before, but for extra credit, you can produce a GUI interface for the game. Rules of Jump The game board consists of an N N array of squares, where N >. At any time, each square may have one of three colors: red, blue, or white (neutral), and some number of spots (as on dice). Initially, all squares are white and have one spot. For purposes of naming squares, we ll use the following notation: r : c refers to the square at row r and column c, where r,c N. Rows are numbered from top to bottom (top row is row ) and columns are numbered from the left. The neighbors of a square are the horizontally and vertically adjacent squares (diagonally adjacent squares are not neighbors). We say that a square is overfull if it contains more spots than it has neighbors. Thus, the four corner squares are overfull when they have more than two spots; other squares on the edge are overfull with more than three spots; and all others are overfull with more than four spots. There are two players, whom we ll call Red and Blue. The players each move in turn, with Red going first. A move consists of adding one spot on any square that does not have the opponent s color (so Red may add a spot to either a red or white square). A spot placed on any square colors that square with the player s color. After the player has moved, we repeat the following steps until no square is overfull or either all squares are red or all blue:. Pick an overfull square.. For each neighbor of the overfull square, move one spot out of the square and into the neighbor (even if occupied by the opposing side).. Give each of these neighboring squares the player s color (if they don t have it already). The order in which this happens, as it turns out, does not usually matter that is, the end result will be the same regardless of which overfull square s spots are removed first, with the exception that the winning position might differ. A player wins when all squares are the player s color. For example, given the board on the left (N = ) in Figure, if Red adds a spot to square :, we get the board on the right after all the spots stop jumping. Distributed under the GNU Public License as part of the KDE project. Copyright 999, 000 by Matthias Kiefer. It was inspired by an old game on the Commodore.

Project #: Jumping Cubes Red square: Blue square: Legend: Figure : Example of a move. The board on the right results from Red adding a spot at :. The rules hold that the game is over as soon as one player s color covers the board. This is a slightly subtle point: it is easy to set up situations where the procedure given above for dealing with overfull squares loops infinitely, swapping spots around in an endless cycle, unless one is careful to stop as soon as a winning position appears. It is acceptable, in fact, for you to report winning positions in which the redistribution procedure described above is prematurely terminated, so that some squares remain overfull. For example, if, on Red s move, the board is as on the left of Figure and Red moves to :, then the board will turn entirely red. You are allowed to stop the process of redistributing spots when all squares are red, even though, depending on the order in which you do things, you could end up with the board on the right in the figure. Textual Input Language Your program should respond to the following textual commands (you may add others). There is one command per line, but otherwise, whitespace may precede and follow command names and operands freely. Empty lines have no effect, and a command line whose first non-blank character is # is ignored as a comment. Extra arguments to a command (beyond those specified below) are ignored. An end-of-file indication on the command input should have the same effect as the quit command. clear Abandons the current game (if one is in progress), and clears the board to its initial

Project #: Jumping Cubes Figure : The board on the left shows a position just before Red s last move (to :). The board on the right is one possible stopping point for spot redistribution (all squares now being one color), even though the square at : is still overloaded. configuration (all squares neutral with one spot). Playing stops until the next start command. start Start playing from the current position, if not doing so already (has no effect if currently playing). Takes moves alternately from Red and Blue according to their color and the current total number of spots on the board: if the spot count plus the board size is even, it is Red s move, and if odd, Blue s move. quit Exits the program. auto P Stops the current game until the next start command and causes player P to be played by an automated player (an AI) on subsequent moves. The value P must be red or blue (ignore case Red or RED also work). Initially, Blue is an automated player. manual P Stops the current game until the next start command and causes player P to take moves from the terminal on subsequent moves. The value of P is as for the auto command. Initially, Red is a manual player. size N Stops any current game, clears the board to its initial configuration, and sets the size of the board to N squares, where N 0. Initially, N =. set R C N P Stop any current game. Put N spots at row R and column C (see.). P is either b or r (for blue or red,) indicating the color of the square. When N is 0, P is ignored and the square is cleared. N must be non-negative and less than or equal to the number of neighboring squares.

Project #: Jumping Cubes dump This command is especially for testing and debugging. It prints the board out in exactly the following format: === r - r r - b - - r - r - r r r r - b r r r r r b b r r r r b b b b r b b === with the === markers at the left margin and other lines indented four spaces. Here, - indicates a neutral square (necessarily with one spot), Nr indicates a red square with N spots, and Nb indicates a blue square with N spots. Don t use the two === markers anywhere else in your output. This gives the autograder a way to determine the state of your game board at any point. It does not change any of the state of the program. seed N If your program s automated players use pseudo-random numbers to choose moves, this command sets the random seed to N (a long integer). This command has no effect if there is no random component to your automated players (or if you don t use them in a particular game). It doesn t matter exactly how you use N as long as your automated player behaves identically each time it is seeded with N. In the absence of a seed command, do what you want to seed your generator. help Print a brief summary of the commands.. Entering Moves To enter moves from the terminal (for a manual player), use a command of the form R C Adds a spot to the square at row R, column C, where R and C are integers in the range to the current board size. Rows are numbered from the top, columns from the left. After the spot is added, spots are redistributed as indicated in the rules above. Like other commands, R and C may be surrounded by any amount of whitespace. Illegal moves must be rejected (they have no effect on the board; the program should tell the user that there is an error and request another move). The first and then every other move is for the red player, the second and then every other is for blue, and the normal legality rules apply to all moves. Output When either player enters a winning move, the program should print a line saying either "Red wins." or "Blue wins." as appropriate. Use exactly those phrases, and do not use them in any other context. When an AI plays, print out the moves that it makes using the format "P moves R C.", where P is "Red" or "Blue" and R and C are the row and column numbers at which a spot is added. Use exactly that format. Do not print this message for manual moves.

Project #: Jumping Cubes Finally, as indicated in, the dump command must print out in exactly the format shown. Otherwise, you are free to prompt for input however you want, and to print out whatever user-friendly output you wish (other than debugging output or Java exception tracebacks, that is). For example, you will probably want to print the game board out after each move is complete (this is distinct from printing the board in the special format required by dump ). When users enter erroneous input, you should print an error message, and the input should have no effect (and in particular, the user should be able to continue entering commands after an error). Make sure that any of this extra output you generate is distinct from the outputs that are required (otherwise, the testing software will flag your program as erroneous.) Regardless of whether users have made errors during a session, your program should always exit with code 0. Other Requirements On the instructional machines, the Unix command make must compile your program and make check must run all your tests (both unit and integration tests). The command java jump.main must run your program. In order to be submitted, your program will have to pass the style check. When testing your program, we will use the command java -ea jump.main to run it (the -ea insures that all assertions in your program are checked.) As before, we will evaluate your project in part on the thoroughness of your testing. Put JUnit test classes with names ending in Test (e.g., BoardTest.java) in your jump package, including one particular class named UnitTest, which should run all your individual JUnit tests as a suite (see the skeleton). Our autograder script will rununittest in the JUnit framework, expecting it to pass. For integration testing, we ve provided a program test-jump, which you can find on the instructional servers in the file ~csb/bin/test-jump. On Unix home systems (including Macs), you can simply copy this to a directory in your path and use it as you can on the instructional machines. This program allows you to run your program, supply it with input, and check the result, or to run two programs, and play them against each other (taking output like "Red moves " from one program and feeding its move to the other.) See the comments at the beginning of test-jump and the sample files in the skeleton tests directory for information on how to write your own tests. If you d prefer to substitute your own test driver instead, go ahead; just make sure you submit all necessary files and that you update your makefile appropriately. Your AI must reliably find a win from any position in which a forced win is four or fewer moves away, for any board no larger than six squares on a side. Likewise, it should be able to put off defeat for at least four moves (again on boards up to six squares on a side) if there is not a forced win for the other side in that many moves. Simply moving at random won t satisfy these requirements. Your program will have limited time to move. Don t expect to get more than an average of roughly seconds per move on the instructional servers. As always, your program must always be in control of its own termination. Terminating by means of an unhandled exception is never acceptable in a finished program.

Project #: Jumping Cubes You may add commands and other features to your program, as long as it otherwise meets this specification. If you do, be sure to update the output of the help command or of usage messages accordingly. Buffering. In order to make it possible for the autograder to interact properly with your program, you must make sure that required outputs that you produce get output immediately. Modern systems tend to buffer input or output collecting it until economies of scale make it efficient to deliver it to its destination. Furthermore, buffering is not consistent across file types: input from or output to a file may behave differently from input from and output to a terminal or Unix pipe. Buffering is problematic for an interactive program (there s no point in saving up all the prompts for input and only print them a thousand at a time.) To make sure this doesn t happen, make sure to use the flush() method on output files after writing a prompt or one of the outputs specified for this assignment. In fact, with the Java library there is no guarantee that the last outputs written to a file object actually get to their intended destination unless you explicitly close the file object, using the.close() method. So it s a good habit to close all output files before exiting, whether normally or as a result of an error. Extra Credit. For extra credit (and please attempt this only after you have met the required conditions,) you can provide a graphical interface. We ve set up the skeleton in such a way that you can use the simple strategy of having your GUI communicate with the rest of the program by writing the same commands you can enter by hand and interpreting the output from the program to get its moves. Your GUI must operate only when the program is executed with java jump.main --display (or java -ea ) so that the GUI is not initialized when the --display option is missing. Advice As usual, start immediately. Read the skeleton and try to understand its intent, even if you don t use it. We have deliberately included uses of various Java features in the skeleton in part to get you to explore them to read the on-line documentation and think about how they might be useful. We have provided a program staff-jump with a solution we ve developed. You can use it for ideas and sanity checks but it is NOT part of the specification! There might be errors in it for all we know (why, we might even have added a few just to mislead you.) Feel free to use it with test-jump to write tests of your program running against another.