代写C++代码 代做C++程序 C++辅导 C++教学

C++网络家教 远程写代码 在线Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

CS1002 Object-Oriented Programming  Practical W11: Fox & Geese 

Aims and Objectives 

Your aim in this practical is to gain the following skill: 

•  to use 2-D arrays as a data structure in Java programs 

By the end of this practical you should be able to: 

•  design and implement data structures based upon 2-D arrays 

•  design and implement methods that manipulate 2-D arrays 

Introduction 

This practical involves modelling and implementing a solution to a specified problem. 

You will need to identify which classes to create, what fields they will have and which 

methods they will need. You will also need to implement a solution and test it. 

The main, compulsory, part of  the practical  is described  in Parts 1-6. Part 7 describes 

some additional extension activities, which you can choose to do or not. Without do-

ing any extension activities the highest mark that you can achieve is 17. 

Practical Instructions 

Part 1:  Setting Up 

Create a new LibreOffice Writer document and an Eclipse project to hold your work. 

Part 2:  Overview 

In this practical you will design and implement a program to simulate the board game 

Fox and Geese. There are several variations on this game, so it is important to read the 

following description carefully – this is the variant you will be implementing. 

The Fox and Geese board is in the shape of a cross, as follows: 

 

 CS1002 Object-Oriented Programming  Practical W11: Fox & Geese 

Board and Pieces 

The board consists of thirty-three squares, nine  in the centre, and six more  in each of 

the arms of the cross. 

There  is a single piece representing  the  fox, and a number of pieces representing  the 

geese. In the variant of the game that we are modelling, we will assume 17 geese, as in 

the figure above. The starting positions of these pieces are also as shown in the figure. 

Players, Movement, and Capture 

One player controls the fox, the other the geese. The geese move first. The players take 

turns to move the fox or one of the geese to an adjacent unoccupied square, horizon-

tally, vertically, or diagonally. 

The fox may alternatively capture a goose by  jumping over  it (in a straight  line) onto 

an unoccupied square: 

 

A captured goose is removed from play for the remainder of the game. 

Victory Conditions 

The geese win the game if the fox is unable to move. This happens when the fox is sur-

rounded by geese so that there are no adjacent squares to which  it can move, and no 

geese that it can capture. The fox wins the game when there are too few geese to hem 

in the fox. 

Part 3:  Specification 

The task in this practical is to write a program to support the playing of a game of Fox 

and Geese. It should: 

•  Maintain  the  current  state  of  the  board,  and  allow  it  to  be  displayed.  Your 

board representation should be based upon a two-dimensional array. 

•  Allow only legal moves. 

•  Detect victory. 

•  Allow users to input moves via a simple textual interface.   


Part 4:  Design and Implementation 

It would be sensible to review your lecture notes and Week 9, Exercise 1 on Noughts & 

Crosses before continuing. Fox and Geese shares many of the same design considera-

tions. 

You will need to think about the following: 

•  Board representation. The practical specifies a two-dimensional array. You will 

need  to decide how  to  represent  each  of  the possible  states  of  a point  on  the 

board (empty, contains goose, contains fox). Since the board is not rectangular, 

your  array will have  to be big  enough  contain  the whole board  and you will  

also have to decide how to represent a position outside the board. 

•  Displaying the Board. How will you print out a representation of the board? 

•  Next to Play. How will you keep track of whose turn it is? 

•  Making moves. How will you specify a move (hint: one pair of coordinates, or 

two?). How will you ensure  that a specified move  is  legal? How will you up-

date the state of the board to reflect that a move has been made? 

•  Victory. How will you detect victory from the perspective of the fox? From the 

perspective of the geese? 

Part 5:  Testing 

You are not required to provide JUnit tests for this practical; however, you should provide 

evidence that you have thoroughly tested your program. One possible way of testing 

would be to play the game, print out the state of the board after each step, and observe 

the output to see if everything worked correctly. 

At each step, you could try one/some of the following: 

•  A legal move. This would change the state of the game, and result in the fox or 

one of  the geese changing  its position, or being removed  from  the board. This 

should be indicated. 

•  A move  outside  one’s  turn. A  fox  should  not  be  allowed  to move  if  it’s  the 

geese’ turn to move, and vice versa. 

•  An illegal move. A move should not be possible if a cell is already occupied or 

outside the board, and should be indicated. 

•  A move  that  leads  to victory. Victory should be  indicated  immediately after a 

move that results in it. 

•  An incorrect input. The user entered input may have errors such as missing co-

ordinates or non-numeral input etc., and these should be indicated.  

Part 6:  Report 

Your report must be structured as follows: 

•  Overview: Give a short overview of the practical: what were you asked to do? 

•  Design:  Describe  the  design  of  your  solution,  justifying  the  decisions  you 

made. In particular, include a copy of a UML class diagram, a brief explanation 

of why you designed your model in the that you did, how you translated your 

model into Java and any interesting features of your Java implementation. CS1002 Object-Oriented Programming  Practical W11: Fox & Geese 

•  Testing: Describe how you tested your program and in particular, how you de-

signed different tests. Your report should include the output from a number of 

test runs to demonstrate that your program satisfies the specification. 

•  Evaluation: Evaluate the success of your program against what you were asked 

to do. 

•  Conclusion:  Conclude  by  summarising what  you  achieved, what  you  found 

difficult, and what you would like to do given more time. 

Don’t forget to add a header including your matriculation number, tutor, and the date. 

Part 7:  Extension Activities 

The activities in this section are not compulsory, though you need to do at least one of 

them to achieve a grade above 17. Try them if you’re interested and have spare time. 

•  Can  you  replace  one  or  both  of  the  human  players with  an  artificial  intelli-

gence? The very  simplest  such AI would  collect  all  of  the possible moves  to-

gether and select one at random, but you can do much better than that… 

•  Can you support some of the variants of the game, such as an increased number 

of foxes, or a different number of geese? How will you allow the user to select 

which game to play? 

Part 8:  Finishing Up 

Save your report and create a PDF version as for previous practicals. Package up your 

Eclipse project and PDF report into a zip file and upload the zip file to MMS. 


相关推荐