159.272 Programming Paradigms (Scala代写,Massey University代写,159.272代写,澳洲程序代写,新西兰程序代写)

Playing board games interactively is a common computational activity. We can use abstraction to aide in the design of board games by separating the game logic from the actual user interaction required to play the game.

联系我们
微信: biyeprodaixie 欢迎联系咨询

本次CS代写的主要涉及如下领域: Scala代写,Massey University代写,159.272代写,澳洲程序代写,新西兰程序代写

159.272 Programming Paradigms

 

Assignment 2

Playing a board game: Reversi

Playing board games interactively is a common computational activity. We can use  abstraction to aide in the design of board games by separating the game logic from the actual user interaction required to play the game. No matter the type of user interface provided to play the game (text-based, desktop environment, web browser), the underlying logic remains the same.

 

In this assignment, you will complete a Scala implementation of Reversi (also called Othello),         a game for two players, played on a board divided into 64 squares, arranged in 8 rows and 8 columns, with a set of 64 chips. Each chip has  a  dark  and  a  light-colored  side,  with  each  colour belonging to one of the two  players.  The  players  place  their  chips  on  the  board  and flip the chips of their opponent, with the goal of having the most chips of their colour on the  board at the end of the game.

 

A chip can only be placed into a square that is adjacent to a chip of the opponent and that forms at least one straight line of attack (horizontal, vertical, diagonal). A line of attack is formed between two squares containing the players chips for which there are one or more of the opponent's chips between the two. The opponent's chips within the line of attack are then flipped.

 

Play alternates between the players until all the squares are filled or neither player can move.        If one player cannot move but the opponent can,  play  continues  with  the  opponent.  The  winner is the player with the most chips at the end of the game.

 

See Maths is Fun to have a practice, or read the  wikiHow  entry.

                                                                                                                                                                                                                                                                                                                                                          

 

The    Scala     code    for    this    assignment     is    contained    in    three    files    in    the    zip    file assignment2_2019.zip

 

Reversi.scala

GameTree.scala

Main.scala

 

The game logic is contained in the file Reversi.scala.

 Your main task is to define the  functions  in  Reversi.scala using the  provided  data  types.

 

 

Instructions:

 

  1. 1. Create a new Scala project in Eclipse.
  2. Add the files Reversi.scala, GameTree.scala, Main.scala to the src folder of the project.
  3.  Complete the functions in Reversi.scala. Replace the ??? with your definitions.
  4. Main.scala defines the main class of the application with the  main method. Run and test your changes  in  the  the  main method  defined  in  Main.scala. The final function call in the main method starts the game. Right click and run the main class as a Scala application as you did at the tutorials.

 

In lectures, we will explain the concepts behind the GameTree.scala code. You should work through the code and make an effort to understand how these concepts have been implemented. The most important concern is to ensure that your functions defined in Reversi.scala return sensible values of the correct types, so that the other modules can sensibly use your completed code.

Your second task considers the estimate function in GameTree.scala which takes a Player value and a Game value and returns an integer value, which "rates" the result of placing the given piece on the current board, for that player.

Your second task is to "make this function smarter". The vanilla version returns a score for the given player and the given board, defined as the number of pieces currently belonging to the player. Can you make this function smarter? This function can be modified to account for strategic concerns, e.g. corners are worth more than edges, which are worth more than other positions. The important point is that you can modify this function without changing any of the other code, and end up with a smarter program. Think about what you would need to do to alter this program behavior using other programming paradigms.

 

When you have a finished version, submit your files Reversi.scala and GameTree.scala for marking. You will get (up to) 12 marks for a correct working version of Reversi.scala, modulated by the use of good  functional  programming style, and (up to) 3  marks  for  an  updated  version  of  GameTree.scala,  modulated by the sophistication of your improvements .

 

Submit your work on Stream by 8pm (Beijing time) Tuesday 4th June. The deadline encroaches on the Study break but this is so that we don’t clash with other  courses having deadlines early in Week 12.